@@ -54,7 +54,7 @@ describe("GitHub Actions Params", () => {
5454 headLabel = "" ,
5555 } : {
5656 data ?: object ;
57- eventName ?: "" | "pull_request" | "pull_request_target" ;
57+ eventName ?: "" | "pull_request" | "pull_request_target" | "merge_group" ;
5858 baseLabel ?: string ;
5959 headLabel ?: string ;
6060 } = { data : { } , eventName : "" } ,
@@ -63,22 +63,35 @@ describe("GitHub Actions Params", () => {
6363 mocks . baseLabel . mockReturnValue ( baseLabel ) ;
6464 mocks . headLabel . mockReturnValue ( headLabel ) ;
6565
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+ if ( [ "pull_request" , "pull_request_target" ] . includes ( eventName ) ) {
67+ vi . mocked ( GitHub ) . context = {
68+ eventName,
69+ payload : {
70+ // @ts -expect-error - forcing the payload to be a PullRequestEvent
71+ pull_request : {
72+ head : {
73+ sha : "test-head-sha" ,
74+ label : headLabel ,
75+ } ,
76+ base : {
77+ sha : "test-base-sha" ,
78+ label : baseLabel ,
79+ } ,
7480 } ,
75- base : {
76- sha : "test-base-sha" ,
77- label : baseLabel ,
81+ } ,
82+ } ;
83+ } else if ( eventName === "merge_group" ) {
84+ // @ts -expect-error - forcing the payload to be a MergeGroupEvent
85+ vi . mocked ( GitHub ) . context = {
86+ eventName,
87+ payload : {
88+ merge_group : {
89+ base_sha : "test-base-sha" ,
90+ head_sha : "test-head-sha" ,
7891 } ,
7992 } ,
80- } ,
81- } ;
93+ } ;
94+ }
8295
8396 server . use (
8497 http . get (
@@ -264,7 +277,7 @@ describe("GitHub Actions Params", () => {
264277 build : "2" ,
265278 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
266279 commit : "test-head-sha" ,
267- compareSha : null ,
280+ compareSha : "test-base-sha" ,
268281 job : "testWorkflow" ,
269282 pr : "1" ,
270283 service : "github-actions" ,
@@ -324,7 +337,66 @@ describe("GitHub Actions Params", () => {
324337 build : "2" ,
325338 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
326339 commit : "test-head-sha" ,
327- compareSha : null ,
340+ compareSha : "test-base-sha" ,
341+ job : "testWorkflow" ,
342+ pr : "1" ,
343+ service : "github-actions" ,
344+ slug : "testOrg/testRepo" ,
345+ } ;
346+ expect ( params ) . toMatchObject ( expected ) ;
347+ } ) ;
348+
349+ it ( "gets the correct branch from a merge group CI run" , async ( ) => {
350+ setup ( {
351+ data : {
352+ jobs : [
353+ {
354+ id : 1 ,
355+ name : "fakeJob" ,
356+ html_url : "https://fake.com" ,
357+ } ,
358+ ] ,
359+ } ,
360+ eventName : "merge_group" ,
361+ baseLabel : "codecov:baseBranch" ,
362+ headLabel : "testOrg:headBranch" ,
363+ } ) ;
364+
365+ const inputs : ProviderUtilInputs = {
366+ args : { ...createEmptyArgs ( ) } ,
367+ envs : {
368+ GITHUB_ACTIONS : "true" ,
369+ GITHUB_HEAD_REF : "branch" ,
370+ GITHUB_JOB : "testJob" ,
371+ GITHUB_REF : "refs/pull/1/merge" ,
372+ GITHUB_REPOSITORY : "testOrg/testRepo" ,
373+ GITHUB_RUN_ID : "2" ,
374+ GITHUB_SERVER_URL : "https://github.com" ,
375+ GITHUB_SHA : "test-head-sha" ,
376+ GITHUB_WORKFLOW : "testWorkflow" ,
377+ } ,
378+ } ;
379+
380+ const output = new Output (
381+ {
382+ apiUrl : "http://localhost" ,
383+ bundleName : "GHA-test" ,
384+ debug : false ,
385+ dryRun : true ,
386+ enableBundleAnalysis : true ,
387+ retryCount : 0 ,
388+ telemetry : false ,
389+ } ,
390+ { metaFramework : "vite" } ,
391+ ) ;
392+ const params = await GitHubActions . getServiceParams ( inputs , output ) ;
393+
394+ const expected : ProviderServiceParams = {
395+ branch : "branch" ,
396+ build : "2" ,
397+ buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
398+ commit : "test-head-sha" ,
399+ compareSha : "test-base-sha" ,
328400 job : "testWorkflow" ,
329401 pr : "1" ,
330402 service : "github-actions" ,
@@ -383,7 +455,7 @@ describe("GitHub Actions Params", () => {
383455 build : "2" ,
384456 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
385457 commit : "test-head-sha" ,
386- compareSha : null ,
458+ compareSha : "test-base-sha" ,
387459 job : "testWorkflow" ,
388460 pr : "1" ,
389461 service : "github-actions" ,
@@ -451,7 +523,7 @@ describe("GitHub Actions Params", () => {
451523 build : "2" ,
452524 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2/jobs/2" ,
453525 commit : "test-head-sha" ,
454- compareSha : null ,
526+ compareSha : "test-base-sha" ,
455527 job : "testWorkflow" ,
456528 pr : "1" ,
457529 service : "github-actions" ,
0 commit comments