Skip to content

Commit d257d49

Browse files
committed
chore: apply AI code review suggestions
- Move PullRequestPayload and ReleasePayload interfaces to top of file - Use PullRequestPayload type instead of inline type assertion - Simplify parseArgs regex match logic (remove redundant fallback)
1 parent bf85c1a commit d257d49

2 files changed

Lines changed: 32 additions & 33 deletions

File tree

src/index.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,35 @@ import {
1717

1818
type OctokitClient = ReturnType<typeof github.getOctokit>
1919

20+
interface PullRequestPayload {
21+
pull_request?: {
22+
head: {
23+
ref: string
24+
sha: string
25+
repo?: {
26+
owner: { login: string }
27+
name: string
28+
}
29+
}
30+
}
31+
pull_request_target?: {
32+
head: {
33+
ref: string
34+
sha: string
35+
repo?: {
36+
owner: { login: string }
37+
name: string
38+
}
39+
}
40+
}
41+
}
42+
43+
interface ReleasePayload {
44+
release?: {
45+
tag_name: string
46+
}
47+
}
48+
2049
const { context } = github
2150

2251
const githubToken = core.getInput('github-token')
@@ -46,9 +75,8 @@ const aliasDomains = core
4675
let url = s
4776
let branch = slugify(context.ref.replace('refs/heads/', ''))
4877
if (isPullRequestType(context.eventName)) {
49-
const pr = (context.payload.pull_request || context.payload.pull_request_target) as {
50-
head: { ref: string }
51-
} | undefined
78+
const payload = context.payload as PullRequestPayload
79+
const pr = payload.pull_request || payload.pull_request_target
5280
if (pr) {
5381
branch = slugify(pr.head.ref.replace('refs/heads/', ''))
5482
url = url.replace(prNumberRegExp, context.issue.number.toString())
@@ -322,35 +350,6 @@ async function aliasDomainsToDeployment(deploymentUrl: string): Promise<void> {
322350
await Promise.all(promises)
323351
}
324352

325-
interface PullRequestPayload {
326-
pull_request?: {
327-
head: {
328-
ref: string
329-
sha: string
330-
repo?: {
331-
owner: { login: string }
332-
name: string
333-
}
334-
}
335-
}
336-
pull_request_target?: {
337-
head: {
338-
ref: string
339-
sha: string
340-
repo?: {
341-
owner: { login: string }
342-
name: string
343-
}
344-
}
345-
}
346-
}
347-
348-
interface ReleasePayload {
349-
release?: {
350-
tag_name: string
351-
}
352-
}
353-
354353
async function run(): Promise<void> {
355354
core.debug(`action : ${context.action}`)
356355
core.debug(`ref : ${context.ref}`)

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function parseArgs(s: string): string[] {
3535
const args: string[] = []
3636

3737
for (const match of s.matchAll(/'([^']*)'|"([^"]*)"|(\S+)/g)) {
38-
args.push(match[1] ?? match[2] ?? match[3] ?? match[0])
38+
args.push((match[1] ?? match[2] ?? match[3])!)
3939
}
4040
return args
4141
}

0 commit comments

Comments
 (0)