@@ -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,160 @@ 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' , 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 : true } ;
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 } ` , { body : getReleaseLinks ( releases ) . concat ( nextRelease . body ) } )
666
+ . reply ( 200 , { html_url : releaseUrl } ) ;
667
+
668
+ await success ( pluginConfig , {
669
+ env,
670
+ options,
671
+ branch : { name : 'master' } ,
672
+ lastRelease,
673
+ commits,
674
+ nextRelease,
675
+ releases,
676
+ logger : t . context . logger ,
677
+ } ) ;
678
+
679
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
680
+ t . true ( github . isDone ( ) ) ;
681
+ } ) ;
682
+
683
+ test . serial ( 'Editing the release to include all release links with no additional releases' , async ( t ) => {
684
+ const owner = 'test_user' ;
685
+ const repo = 'test_repo' ;
686
+ const env = { GITHUB_TOKEN : 'github_token' } ;
687
+ const failTitle = 'The automated release is failing 🚨' ;
688
+ const pluginConfig = { releasedLabels : false , addReleases : true } ;
689
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
690
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
691
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
692
+ const lastRelease = { version : '1.0.0' } ;
693
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
694
+ const releaseId = 1 ;
695
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' , id : releaseId } ] ;
696
+ const github = authenticate ( env )
697
+ . get ( `/repos/${ owner } /${ repo } ` )
698
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
699
+ . get (
700
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
701
+ . map ( ( commit ) => commit . hash )
702
+ . join ( '+' ) } `
703
+ )
704
+ . reply ( 200 , { items : prs } )
705
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
706
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
707
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
708
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
709
+ . get (
710
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
711
+ 'state:open'
712
+ ) } +${ escape ( failTitle ) } `
713
+ )
714
+ . reply ( 200 , { items : [ ] } ) ;
715
+
716
+ await success ( pluginConfig , {
717
+ env,
718
+ options,
719
+ branch : { name : 'master' } ,
720
+ lastRelease,
721
+ commits,
722
+ nextRelease,
723
+ releases,
724
+ logger : t . context . logger ,
725
+ } ) ;
726
+
727
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
728
+ t . true ( github . isDone ( ) ) ;
729
+ } ) ;
730
+
731
+ test . serial ( 'Editing the release with no ID in the release' , async ( t ) => {
732
+ const owner = 'test_user' ;
733
+ const repo = 'test_repo' ;
734
+ const env = { GITHUB_TOKEN : 'github_token' } ;
735
+ const failTitle = 'The automated release is failing 🚨' ;
736
+ const pluginConfig = { releasedLabels : false , addReleases : true } ;
737
+ const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
738
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
739
+ const nextRelease = { version : '2.0.0' , gitTag : 'v1.0.0' , name : 'v1.0.0' , notes : 'Test release note body' } ;
740
+ const lastRelease = { version : '1.0.0' } ;
741
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
742
+ const releases = [
743
+ { name : 'GitHub release' , url : 'https://github.com/release' } ,
744
+ { name : 'S3' , url : 's3://my-bucket/release-asset' } ,
745
+ { name : 'Docker: docker.io/python:slim' } ,
746
+ ] ;
747
+ const github = authenticate ( env )
748
+ . get ( `/repos/${ owner } /${ repo } ` )
749
+ . reply ( 200 , { full_name : `${ owner } /${ repo } ` } )
750
+ . get (
751
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
752
+ . map ( ( commit ) => commit . hash )
753
+ . join ( '+' ) } `
754
+ )
755
+ . reply ( 200 , { items : prs } )
756
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
757
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
758
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
759
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
760
+ . get (
761
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
762
+ 'state:open'
763
+ ) } +${ escape ( failTitle ) } `
764
+ )
765
+ . reply ( 200 , { items : [ ] } ) ;
766
+
767
+ await success ( pluginConfig , {
768
+ env,
769
+ options,
770
+ branch : { name : 'master' } ,
771
+ lastRelease,
772
+ commits,
773
+ nextRelease,
774
+ releases,
775
+ logger : t . context . logger ,
776
+ } ) ;
777
+
778
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
779
+ t . true ( github . isDone ( ) ) ;
780
+ } ) ;
781
+
627
782
test . serial ( 'Ignore errors when adding comments and closing issues' , async ( t ) => {
628
783
const owner = 'test_user' ;
629
784
const repo = 'test_repo' ;
0 commit comments