|
1 | | -import {PullRequestSchema, ConfigurationOptions} from './schemas' |
| 1 | +import { |
| 2 | + PullRequestSchema, |
| 3 | + ConfigurationOptions, |
| 4 | + MergeGroupSchema |
| 5 | +} from './schemas' |
2 | 6 |
|
3 | 7 | export function getRefs( |
4 | 8 | config: ConfigurationOptions, |
5 | | - context: {payload: {pull_request?: unknown}; eventName: string} |
| 9 | + context: { |
| 10 | + payload: {pull_request?: unknown; merge_group?: unknown} |
| 11 | + eventName: string |
| 12 | + } |
6 | 13 | ): {base: string; head: string} { |
7 | 14 | let base_ref = config.base_ref |
8 | 15 | let head_ref = config.head_ref |
9 | 16 |
|
10 | 17 | // If possible, source default base & head refs from the GitHub event. |
11 | 18 | // 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 | + } |
20 | 32 | } |
21 | 33 |
|
22 | 34 | if (!base_ref && !head_ref) { |
|
0 commit comments