@@ -42,6 +42,7 @@ beforeEach(() => {
42
42
process . env . INPUT_SELECT_LABEL = ''
43
43
process . env . GITHUB_REPOSITORY = 'test-owner/test-repo'
44
44
process . env . INPUT_MIN_COMBINE_NUMBER = '2'
45
+ process . env . INPUT_LABELS = ''
45
46
46
47
jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
47
48
return {
@@ -660,6 +661,143 @@ test('ignore_label and select_label can both be empty', async () => {
660
661
expect ( await run ( ) ) . toBe ( 'success' )
661
662
} )
662
663
664
+ test ( 'successfully runs the action and sets labels' , async ( ) => {
665
+ jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
666
+ return {
667
+ paginate : jest . fn ( ) . mockImplementation ( ( ) => {
668
+ return [
669
+ buildPR ( 1 , 'dependabot-1' , [ 'question' ] ) ,
670
+ buildPR ( 2 , 'dependabot-2' ) ,
671
+ buildPR ( 3 , 'dependabot-3' , [ 'nocombine' ] ) ,
672
+ buildPR ( 4 , 'dependabot-4' ) ,
673
+ buildPR ( 5 , 'dependabot-5' ) ,
674
+ buildPR ( 6 , 'dependabot-6' ) ,
675
+ buildPR ( 7 , 'fix-package' )
676
+ ]
677
+ } ) ,
678
+ graphql : jest . fn ( ) . mockImplementation ( ( _query , params ) => {
679
+ switch ( params . pull_number ) {
680
+ case 1 :
681
+ case 2 :
682
+ case 3 :
683
+ return buildStatusResponse ( 'APPROVED' , 'SUCCESS' )
684
+ case 4 :
685
+ return buildStatusResponse ( 'APPROVED' , 'FAILURE' )
686
+ case 5 :
687
+ return buildStatusResponse ( null , 'SUCCESS' )
688
+ case 6 :
689
+ return buildStatusResponse ( 'REVIEW_REQUIRED' , 'SUCCESS' )
690
+ default :
691
+ throw new Error (
692
+ `params.pull_number of ${ params . pull_number } is not configured.`
693
+ )
694
+ }
695
+ } ) ,
696
+ rest : {
697
+ issues : {
698
+ addLabels : jest . fn ( ) . mockReturnValueOnce ( {
699
+ data : { }
700
+ } )
701
+ } ,
702
+ git : {
703
+ createRef : jest . fn ( ) . mockReturnValueOnce ( {
704
+ data : { }
705
+ } )
706
+ } ,
707
+ repos : {
708
+ // mock the first value of merge to be a success and the second to be an exception
709
+ merge : jest
710
+ . fn ( )
711
+ . mockReturnValueOnce ( {
712
+ data : {
713
+ merged : true
714
+ }
715
+ } )
716
+ . mockImplementationOnce ( ( ) => {
717
+ throw new Error ( 'merge error' )
718
+ } )
719
+ } ,
720
+ pulls : {
721
+ create : jest . fn ( ) . mockReturnValueOnce ( {
722
+ data : {
723
+ number : 100 ,
724
+ html_url : 'https://github.com/test-owner/test-repo/pull/100'
725
+ }
726
+ } )
727
+ }
728
+ }
729
+ }
730
+ } )
731
+
732
+ process . env . INPUT_REVIEW_REQUIRED = 'true'
733
+ process . env . INPUT_LABELS = 'label1,label2, label3'
734
+ expect ( await run ( ) ) . toBe ( 'success' )
735
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Pull for branch: dependabot-1' )
736
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch matched prefix: dependabot-1' )
737
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking green status: dependabot-1' )
738
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating status: SUCCESS' )
739
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating review decision: APPROVED' )
740
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch dependabot-1 is approved' )
741
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Pull for branch: dependabot-2' )
742
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch matched prefix: dependabot-2' )
743
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking green status: dependabot-2' )
744
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating status: SUCCESS' )
745
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating review decision: APPROVED' )
746
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch dependabot-2 is approved' )
747
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Pull for branch: dependabot-3' )
748
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch matched prefix: dependabot-3' )
749
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Pull for branch: dependabot-4' )
750
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch matched prefix: dependabot-4' )
751
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking green status: dependabot-4' )
752
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating status: FAILURE' )
753
+ expect ( infoMock ) . toHaveBeenCalledWith (
754
+ 'Discarding dependabot-4 with status FAILURE'
755
+ )
756
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Branch matched prefix: dependabot-5' )
757
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking green status: dependabot-5' )
758
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating status: SUCCESS' )
759
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Validating review decision: null' )
760
+ expect ( infoMock ) . toHaveBeenCalledWith (
761
+ 'Branch dependabot-5 has no required reviewers - OK'
762
+ )
763
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-1' )
764
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking ignore_label for: question' )
765
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Adding branch to array: dependabot-1' )
766
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-2' )
767
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Adding branch to array: dependabot-2' )
768
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-3' )
769
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking ignore_label for: nocombine' )
770
+ expect ( infoMock ) . toHaveBeenCalledWith (
771
+ 'Discarding dependabot-3 with label nocombine because it matches ignore_label'
772
+ )
773
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-4' )
774
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-5' )
775
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Checking labels: dependabot-6' )
776
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Merged branch dependabot-1' )
777
+ expect ( warningMock ) . toHaveBeenCalledWith (
778
+ 'Failed to merge branch dependabot-2'
779
+ )
780
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Merged branch dependabot-5' )
781
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Creating combined PR' )
782
+ expect ( debugMock ) . toHaveBeenCalledWith (
783
+ 'PR body: # Combined PRs ➡️📦⬅️\n\n✅ The following pull requests have been successfully combined on this PR:\n- #1 Update dependency 1\n- #5 Update dependency 5\n\n⚠️ The following PRs were left out due to merge conflicts:\n- #2 Update dependency 2\n\n> This PR was created by the [`github/combine-prs`](https://github.com/github/combine-prs) action'
784
+ )
785
+
786
+ expect ( infoMock ) . toHaveBeenCalledWith (
787
+ `Adding labels to combined PR: label1,label2,label3`
788
+ )
789
+
790
+ expect ( infoMock ) . toHaveBeenCalledWith (
791
+ 'Combined PR url: https://github.com/test-owner/test-repo/pull/100'
792
+ )
793
+ expect ( infoMock ) . toHaveBeenCalledWith ( 'Combined PR number: 100' )
794
+ expect ( setOutputMock ) . toHaveBeenCalledWith ( 'pr_number' , 100 )
795
+ expect ( setOutputMock ) . toHaveBeenCalledWith (
796
+ 'pr_url' ,
797
+ 'https://github.com/test-owner/test-repo/pull/100'
798
+ )
799
+ } )
800
+
663
801
function buildStatusResponse ( reviewDecision , ciStatus ) {
664
802
return {
665
803
repository : {
0 commit comments