@@ -54,7 +54,7 @@ describe("GitHub Actions Params", () => {
54
54
headLabel = "" ,
55
55
} : {
56
56
data ?: object ;
57
- eventName ?: "" | "pull_request" | "pull_request_target" ;
57
+ eventName ?: "" | "pull_request" | "pull_request_target" | "merge_group" ;
58
58
baseLabel ?: string ;
59
59
headLabel ?: string ;
60
60
} = { data : { } , eventName : "" } ,
@@ -63,22 +63,38 @@ describe("GitHub Actions Params", () => {
63
63
mocks . baseLabel . mockReturnValue ( baseLabel ) ;
64
64
mocks . headLabel . mockReturnValue ( headLabel ) ;
65
65
66
- vi . mocked ( GitHub ) . context = {
67
- eventName,
68
- payload : {
69
- // @ts -expect-error - forcing the payload to be a PullRequestEvent
70
- pull_request : {
71
- head : {
72
- sha : "test-head-sha" ,
73
- label : headLabel ,
66
+ // not sure if empty string is correct here but for parity with previous tests
67
+ // TODO: verify that empty string belongs here, from a glance it seems PushEvent does not
68
+ // include a pull_request key
69
+ if ( [ "pull_request" , "pull_request_target" , "" ] . includes ( eventName ) ) {
70
+ vi . mocked ( GitHub ) . context = {
71
+ eventName,
72
+ payload : {
73
+ // @ts -expect-error - forcing the payload to be a PullRequestEvent
74
+ pull_request : {
75
+ head : {
76
+ sha : "test-head-sha" ,
77
+ label : headLabel ,
78
+ } ,
79
+ base : {
80
+ sha : "test-base-sha" ,
81
+ label : baseLabel ,
82
+ } ,
74
83
} ,
75
- base : {
76
- sha : "test-base-sha" ,
77
- label : baseLabel ,
84
+ } ,
85
+ } ;
86
+ } else if ( eventName === "merge_group" ) {
87
+ // @ts -expect-error - forcing the payload to be a MergeGroupEvent
88
+ vi . mocked ( GitHub ) . context = {
89
+ eventName,
90
+ payload : {
91
+ merge_group : {
92
+ base_sha : "test-base-sha" ,
93
+ head_sha : "test-head-sha" ,
78
94
} ,
79
95
} ,
80
- } ,
81
- } ;
96
+ } ;
97
+ }
82
98
83
99
server . use (
84
100
http . get (
@@ -324,7 +340,66 @@ describe("GitHub Actions Params", () => {
324
340
build : "2" ,
325
341
buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
326
342
commit : "test-head-sha" ,
327
- compareSha : null ,
343
+ compareSha : "test-base-sha" ,
344
+ job : "testWorkflow" ,
345
+ pr : "1" ,
346
+ service : "github-actions" ,
347
+ slug : "testOrg/testRepo" ,
348
+ } ;
349
+ expect ( params ) . toMatchObject ( expected ) ;
350
+ } ) ;
351
+
352
+ it ( "gets the correct branch from a merge group CI run" , async ( ) => {
353
+ setup ( {
354
+ data : {
355
+ jobs : [
356
+ {
357
+ id : 1 ,
358
+ name : "fakeJob" ,
359
+ html_url : "https://fake.com" ,
360
+ } ,
361
+ ] ,
362
+ } ,
363
+ eventName : "merge_group" ,
364
+ baseLabel : "codecov:baseBranch" ,
365
+ headLabel : "testOrg:headBranch" ,
366
+ } ) ;
367
+
368
+ const inputs : ProviderUtilInputs = {
369
+ args : { ...createEmptyArgs ( ) } ,
370
+ envs : {
371
+ GITHUB_ACTIONS : "true" ,
372
+ GITHUB_HEAD_REF : "branch" ,
373
+ GITHUB_JOB : "testJob" ,
374
+ GITHUB_REF : "refs/pull/1/merge" ,
375
+ GITHUB_REPOSITORY : "testOrg/testRepo" ,
376
+ GITHUB_RUN_ID : "2" ,
377
+ GITHUB_SERVER_URL : "https://github.com" ,
378
+ GITHUB_SHA : "test-head-sha" ,
379
+ GITHUB_WORKFLOW : "testWorkflow" ,
380
+ } ,
381
+ } ;
382
+
383
+ const output = new Output (
384
+ {
385
+ apiUrl : "http://localhost" ,
386
+ bundleName : "GHA-test" ,
387
+ debug : false ,
388
+ dryRun : true ,
389
+ enableBundleAnalysis : true ,
390
+ retryCount : 0 ,
391
+ telemetry : false ,
392
+ } ,
393
+ { metaFramework : "vite" } ,
394
+ ) ;
395
+ const params = await GitHubActions . getServiceParams ( inputs , output ) ;
396
+
397
+ const expected : ProviderServiceParams = {
398
+ branch : "branch" ,
399
+ build : "2" ,
400
+ buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
401
+ commit : "test-head-sha" ,
402
+ compareSha : "test-base-sha" ,
328
403
job : "testWorkflow" ,
329
404
pr : "1" ,
330
405
service : "github-actions" ,
@@ -383,7 +458,7 @@ describe("GitHub Actions Params", () => {
383
458
build : "2" ,
384
459
buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
385
460
commit : "test-head-sha" ,
386
- compareSha : null ,
461
+ compareSha : "test-base-sha" ,
387
462
job : "testWorkflow" ,
388
463
pr : "1" ,
389
464
service : "github-actions" ,
0 commit comments