@@ -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,38 @@ 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+ // 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+ } ,
7483 } ,
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" ,
7894 } ,
7995 } ,
80- } ,
81- } ;
96+ } ;
97+ }
8298
8399 server . use (
84100 http . get (
@@ -324,7 +340,66 @@ describe("GitHub Actions Params", () => {
324340 build : "2" ,
325341 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
326342 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" ,
328403 job : "testWorkflow" ,
329404 pr : "1" ,
330405 service : "github-actions" ,
@@ -383,7 +458,7 @@ describe("GitHub Actions Params", () => {
383458 build : "2" ,
384459 buildURL : "https://github.com/testOrg/testRepo/actions/runs/2" ,
385460 commit : "test-head-sha" ,
386- compareSha : null ,
461+ compareSha : "test-base-sha" ,
387462 job : "testWorkflow" ,
388463 pr : "1" ,
389464 service : "github-actions" ,
0 commit comments