Skip to content

Commit e99353b

Browse files
committed
fixing merge_group schema bug
1 parent a6993e2 commit e99353b

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/git-refs.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
import {PullRequestSchema, ConfigurationOptions} from './schemas'
1+
import {
2+
PullRequestSchema,
3+
ConfigurationOptions,
4+
MergeGroupSchema
5+
} from './schemas'
26

37
export function getRefs(
48
config: ConfigurationOptions,
5-
context: {payload: {pull_request?: unknown}; eventName: string}
9+
context: {
10+
payload: {pull_request?: unknown; merge_group?: unknown}
11+
eventName: string
12+
}
613
): {base: string; head: string} {
714
let base_ref = config.base_ref
815
let head_ref = config.head_ref
916

1017
// If possible, source default base & head refs from the GitHub event.
1118
// The base/head ref from the config take priority, if provided.
12-
if (
13-
context.eventName === 'pull_request' ||
14-
context.eventName === 'pull_request_target' ||
15-
context.eventName === 'merge_group'
16-
) {
17-
const pull_request = PullRequestSchema.parse(context.payload.pull_request)
18-
base_ref = base_ref || pull_request.base.sha
19-
head_ref = head_ref || pull_request.head.sha
19+
if (!base_ref && !head_ref) {
20+
if (
21+
context.eventName === 'pull_request' ||
22+
context.eventName === 'pull_request_target'
23+
) {
24+
const pull_request = PullRequestSchema.parse(context.payload.pull_request)
25+
base_ref = base_ref || pull_request.base.sha
26+
head_ref = head_ref || pull_request.head.sha
27+
} else if (context.eventName === 'merge_group') {
28+
const merge_group = MergeGroupSchema.parse(context.payload.merge_group)
29+
base_ref = base_ref || merge_group.base_sha
30+
head_ref = head_ref || merge_group.head_sha
31+
}
2032
}
2133

2234
if (!base_ref && !head_ref) {

src/schemas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export const PullRequestSchema = z.object({
9191
head: z.object({sha: z.string()})
9292
})
9393

94+
export const MergeGroupSchema = z.object({
95+
base_sha: z.string(),
96+
head_sha: z.string()
97+
})
98+
9499
export const ConfigurationOptionsSchema = z
95100
.object({
96101
fail_on_severity: SeveritySchema,

0 commit comments

Comments
 (0)