@@ -7,6 +7,7 @@ const proxyquire = require('proxyquire');
7
7
const { ISSUE_ID } = require ( '../lib/definitions/constants' ) ;
8
8
const { authenticate} = require ( './helpers/mock-github' ) ;
9
9
const rateLimit = require ( './helpers/rate-limit' ) ;
10
+ const getReleaseLinks = require ( '../lib/get-release-links' ) ;
10
11
11
12
/* eslint camelcase: ["error", {properties: "never"}] */
12
13
@@ -624,6 +625,316 @@ test.serial('Comment on issue/PR without ading a label', async (t) => {
624
625
t . true ( github . isDone ( ) ) ;
625
626
} ) ;
626
627
628
+ test . serial ( 'Editing the release to include all release links at the bottom' , async ( t ) => {
629
+ const owner = 'test_user' ;
630
+ const repo = 'test_repo' ;
631
+ const env = { GITHUB_TOKEN : 'github_token' } ;
632
+ const failTitle = 'The automated release is failing 🚨' ;
633
+ const pluginConfig = { releasedLabels : false , addReleases : 'bottom' } ;
634
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
635
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
636
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
637
+ const lastRelease = { version : '1.0.0' } ;
638
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
639
+ const releaseUrl = `https://github.com/${ owner } /${ repo } /releases/${ nextRelease . version } ` ;
640
+ const releaseId = 1 ;
641
+ const releases = [
642
+ { name : 'GitHub release' , url : 'https://github.com/release' , id : releaseId } ,
643
+ { name : 'S3' , url : 's3://my-bucket/release-asset' } ,
644
+ { name : 'Docker: docker.io/python:slim' } ,
645
+ ] ;
646
+ const github = authenticate ( env )
647
+ . get ( `/repos/${ owner } /${ repo } ` )
648
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
649
+ . get (
650
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
651
+ . map ( ( commit ) => commit . hash )
652
+ . join ( '+' ) } `
653
+ )
654
+ . reply ( 200 , { items : prs } )
655
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
656
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
657
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
658
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
659
+ . get (
660
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
661
+ 'state:open'
662
+ ) } +${ escape ( failTitle ) } `
663
+ )
664
+ . reply ( 200 , { items : [ ] } )
665
+ . patch ( `/repos/${ owner } /${ repo } /releases/${ releaseId } ` , {
666
+ body : nextRelease . notes . concat ( '\n---\n' , getReleaseLinks ( releases ) ) ,
667
+ } )
668
+ . reply ( 200 , { html_url : releaseUrl } ) ;
669
+
670
+ await success ( pluginConfig , {
671
+ env,
672
+ options,
673
+ branch : { name : 'master' } ,
674
+ lastRelease,
675
+ commits,
676
+ nextRelease,
677
+ releases,
678
+ notes : nextRelease . notes ,
679
+ logger : t . context . logger ,
680
+ } ) ;
681
+
682
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
683
+ t . true ( github . isDone ( ) ) ;
684
+ } ) ;
685
+
686
+ test . serial ( 'Editing the release to include all release links at the top' , async ( t ) => {
687
+ const owner = 'test_user' ;
688
+ const repo = 'test_repo' ;
689
+ const env = { GITHUB_TOKEN : 'github_token' } ;
690
+ const failTitle = 'The automated release is failing 🚨' ;
691
+ const pluginConfig = { releasedLabels : false , addReleases : 'top' } ;
692
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
693
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
694
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
695
+ const lastRelease = { version : '1.0.0' } ;
696
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
697
+ const releaseUrl = `https://github.com/${ owner } /${ repo } /releases/${ nextRelease . version } ` ;
698
+ const releaseId = 1 ;
699
+ const releases = [
700
+ { name : 'GitHub release' , url : 'https://github.com/release' , id : releaseId } ,
701
+ { name : 'S3' , url : 's3://my-bucket/release-asset' } ,
702
+ { name : 'Docker: docker.io/python:slim' } ,
703
+ ] ;
704
+ const github = authenticate ( env )
705
+ . get ( `/repos/${ owner } /${ repo } ` )
706
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
707
+ . get (
708
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
709
+ . map ( ( commit ) => commit . hash )
710
+ . join ( '+' ) } `
711
+ )
712
+ . reply ( 200 , { items : prs } )
713
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
714
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
715
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
716
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
717
+ . get (
718
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
719
+ 'state:open'
720
+ ) } +${ escape ( failTitle ) } `
721
+ )
722
+ . reply ( 200 , { items : [ ] } )
723
+ . patch ( `/repos/${ owner } /${ repo } /releases/${ releaseId } ` , {
724
+ body : getReleaseLinks ( releases ) . concat ( '\n---\n' , nextRelease . notes ) ,
725
+ } )
726
+ . reply ( 200 , { html_url : releaseUrl } ) ;
727
+
728
+ await success ( pluginConfig , {
729
+ env,
730
+ options,
731
+ branch : { name : 'master' } ,
732
+ lastRelease,
733
+ commits,
734
+ nextRelease,
735
+ releases,
736
+ notes : nextRelease . notes ,
737
+ logger : t . context . logger ,
738
+ } ) ;
739
+
740
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
741
+ t . true ( github . isDone ( ) ) ;
742
+ } ) ;
743
+
744
+ test . serial ( 'Editing the release to include all release links with no additional releases (top)' , async ( t ) => {
745
+ const owner = 'test_user' ;
746
+ const repo = 'test_repo' ;
747
+ const env = { GITHUB_TOKEN : 'github_token' } ;
748
+ const failTitle = 'The automated release is failing 🚨' ;
749
+ const pluginConfig = { releasedLabels : false , addReleases : 'top' } ;
750
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
751
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
752
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
753
+ const lastRelease = { version : '1.0.0' } ;
754
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
755
+ const releaseId = 1 ;
756
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' , id : releaseId } ] ;
757
+ const github = authenticate ( env )
758
+ . get ( `/repos/${ owner } /${ repo } ` )
759
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
760
+ . get (
761
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
762
+ . map ( ( commit ) => commit . hash )
763
+ . join ( '+' ) } `
764
+ )
765
+ . reply ( 200 , { items : prs } )
766
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
767
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
768
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
769
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
770
+ . get (
771
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
772
+ 'state:open'
773
+ ) } +${ escape ( failTitle ) } `
774
+ )
775
+ . reply ( 200 , { items : [ ] } ) ;
776
+
777
+ await success ( pluginConfig , {
778
+ env,
779
+ options,
780
+ branch : { name : 'master' } ,
781
+ lastRelease,
782
+ commits,
783
+ nextRelease,
784
+ releases,
785
+ logger : t . context . logger ,
786
+ } ) ;
787
+
788
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
789
+ t . true ( github . isDone ( ) ) ;
790
+ } ) ;
791
+
792
+ test . serial ( 'Editing the release to include all release links with no additional releases (bottom)' , async ( t ) => {
793
+ const owner = 'test_user' ;
794
+ const repo = 'test_repo' ;
795
+ const env = { GITHUB_TOKEN : 'github_token' } ;
796
+ const failTitle = 'The automated release is failing 🚨' ;
797
+ const pluginConfig = { releasedLabels : false , addReleases : 'bottom' } ;
798
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
799
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
800
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
801
+ const lastRelease = { version : '1.0.0' } ;
802
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
803
+ const releaseId = 1 ;
804
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' , id : releaseId } ] ;
805
+ const github = authenticate ( env )
806
+ . get ( `/repos/${ owner } /${ repo } ` )
807
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
808
+ . get (
809
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
810
+ . map ( ( commit ) => commit . hash )
811
+ . join ( '+' ) } `
812
+ )
813
+ . reply ( 200 , { items : prs } )
814
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
815
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
816
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
817
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
818
+ . get (
819
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
820
+ 'state:open'
821
+ ) } +${ escape ( failTitle ) } `
822
+ )
823
+ . reply ( 200 , { items : [ ] } ) ;
824
+
825
+ await success ( pluginConfig , {
826
+ env,
827
+ options,
828
+ branch : { name : 'master' } ,
829
+ lastRelease,
830
+ commits,
831
+ nextRelease,
832
+ releases,
833
+ logger : t . context . logger ,
834
+ } ) ;
835
+
836
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
837
+ t . true ( github . isDone ( ) ) ;
838
+ } ) ;
839
+
840
+ test . serial ( 'Editing the release to include all release links with no releases' , async ( t ) => {
841
+ const owner = 'test_user' ;
842
+ const repo = 'test_repo' ;
843
+ const env = { GITHUB_TOKEN : 'github_token' } ;
844
+ const failTitle = 'The automated release is failing 🚨' ;
845
+ const pluginConfig = { releasedLabels : false , addReleases : 'bottom' } ;
846
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
847
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
848
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
849
+ const lastRelease = { version : '1.0.0' } ;
850
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
851
+ const releases = [ ] ;
852
+ const github = authenticate ( env )
853
+ . get ( `/repos/${ owner } /${ repo } ` )
854
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
855
+ . get (
856
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
857
+ . map ( ( commit ) => commit . hash )
858
+ . join ( '+' ) } `
859
+ )
860
+ . reply ( 200 , { items : prs } )
861
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
862
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
863
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
864
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
865
+ . get (
866
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
867
+ 'state:open'
868
+ ) } +${ escape ( failTitle ) } `
869
+ )
870
+ . reply ( 200 , { items : [ ] } ) ;
871
+
872
+ await success ( pluginConfig , {
873
+ env,
874
+ options,
875
+ branch : { name : 'master' } ,
876
+ lastRelease,
877
+ commits,
878
+ nextRelease,
879
+ releases,
880
+ logger : t . context . logger ,
881
+ } ) ;
882
+
883
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
884
+ t . true ( github . isDone ( ) ) ;
885
+ } ) ;
886
+
887
+ test . serial ( 'Editing the release with no ID in the release' , async ( t ) => {
888
+ const owner = 'test_user' ;
889
+ const repo = 'test_repo' ;
890
+ const env = { GITHUB_TOKEN : 'github_token' } ;
891
+ const failTitle = 'The automated release is failing 🚨' ;
892
+ const pluginConfig = { releasedLabels : false , addReleases : 'bottom' } ;
893
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
894
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
895
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
896
+ const lastRelease = { version : '1.0.0' } ;
897
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
898
+ const releases = [
899
+ { name : 'GitHub release' , url : 'https://github.com/release' } ,
900
+ { name : 'S3' , url : 's3://my-bucket/release-asset' } ,
901
+ { name : 'Docker: docker.io/python:slim' } ,
902
+ ] ;
903
+ const github = authenticate ( env )
904
+ . get ( `/repos/${ owner } /${ repo } ` )
905
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
906
+ . get (
907
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
908
+ . map ( ( commit ) => commit . hash )
909
+ . join ( '+' ) } `
910
+ )
911
+ . reply ( 200 , { items : prs } )
912
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
913
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
914
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
915
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
916
+ . get (
917
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
918
+ 'state:open'
919
+ ) } +${ escape ( failTitle ) } `
920
+ )
921
+ . reply ( 200 , { items : [ ] } ) ;
922
+
923
+ await success ( pluginConfig , {
924
+ env,
925
+ options,
926
+ branch : { name : 'master' } ,
927
+ lastRelease,
928
+ commits,
929
+ nextRelease,
930
+ releases,
931
+ logger : t . context . logger ,
932
+ } ) ;
933
+
934
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
935
+ t . true ( github . isDone ( ) ) ;
936
+ } ) ;
937
+
627
938
test . serial ( 'Ignore errors when adding comments and closing issues' , async ( t ) => {
628
939
const owner = 'test_user' ;
629
940
const repo = 'test_repo' ;
0 commit comments