@@ -4,7 +4,7 @@ import {repeat} from 'lodash';
4
4
import nock from 'nock' ;
5
5
import { stub } from 'sinon' ;
6
6
import proxyquire from 'proxyquire' ;
7
- import ISSUE_ID from '../lib/definitions/sr-issue-id ' ;
7
+ import { ISSUE_ID } from '../lib/definitions/constants ' ;
8
8
import { authenticate } from './helpers/mock-github' ;
9
9
import rateLimit from './helpers/rate-limit' ;
10
10
@@ -124,7 +124,7 @@ test.serial(
124
124
{ hash : '456' , message : 'Commit 2 message' } ,
125
125
{ hash : '789' , message : `Commit 3 message Closes https://custom-url.com/${ owner } /${ repo } /issues/4` } ,
126
126
] ;
127
- const nextRelease = { version : '1.0.0' } ;
127
+ const nextRelease = { version : '1.0.0' , channel : 'next' } ;
128
128
const releases = [ { name : 'GitHub release' , url : 'https://custom-url.com/release' } ] ;
129
129
const github = authenticate ( env )
130
130
. get ( `/repos/${ owner } /${ repo } ` )
@@ -141,23 +141,23 @@ test.serial(
141
141
. reply ( 200 , [ { sha : commits [ 1 ] . hash } ] )
142
142
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
143
143
. reply ( 200 , { html_url : 'https://custom-url.com/successcomment-1' } )
144
- . post ( `/repos/${ owner } /${ repo } /issues/1/labels` , '{"labels":["released"]}' )
144
+ . post ( `/repos/${ owner } /${ repo } /issues/1/labels` , '{"labels":["released on @next "]}' )
145
145
. reply ( 200 , { } )
146
146
. post ( `/repos/${ owner } /${ repo } /issues/2/comments` , { body : / T h i s P R i s i n c l u d e d / } )
147
147
. reply ( 200 , { html_url : 'https://custom-url.com/successcomment-2' } )
148
- . post ( `/repos/${ owner } /${ repo } /issues/2/labels` , '{"labels":["released"]}' )
148
+ . post ( `/repos/${ owner } /${ repo } /issues/2/labels` , '{"labels":["released on @next "]}' )
149
149
. reply ( 200 , { } )
150
150
. get ( `/repos/${ owner } /${ repo } /issues/3` )
151
151
. reply ( 200 , { state : 'closed' } )
152
152
. post ( `/repos/${ owner } /${ repo } /issues/3/comments` , { body : / T h i s i s s u e h a s b e e n r e s o l v e d / } )
153
153
. reply ( 200 , { html_url : 'https://custom-url.com/successcomment-3' } )
154
- . post ( `/repos/${ owner } /${ repo } /issues/3/labels` , '{"labels":["released"]}' )
154
+ . post ( `/repos/${ owner } /${ repo } /issues/3/labels` , '{"labels":["released on @next "]}' )
155
155
. reply ( 200 , { } )
156
156
. get ( `/repos/${ owner } /${ repo } /issues/4` )
157
157
. reply ( 200 , { state : 'closed' } )
158
158
. post ( `/repos/${ owner } /${ repo } /issues/4/comments` , { body : / T h i s i s s u e h a s b e e n r e s o l v e d / } )
159
159
. reply ( 200 , { html_url : 'https://custom-url.com/successcomment-4' } )
160
- . post ( `/repos/${ owner } /${ repo } /issues/4/labels` , '{"labels":["released"]}' )
160
+ . post ( `/repos/${ owner } /${ repo } /issues/4/labels` , '{"labels":["released on @next "]}' )
161
161
. reply ( 200 , { } )
162
162
. get (
163
163
`/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
@@ -169,13 +169,13 @@ test.serial(
169
169
await success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } ) ;
170
170
171
171
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://custom-url.com/successcomment-1' ) ) ;
172
- t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released' ] , 1 ) ) ;
172
+ t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released on @next ' ] , 1 ) ) ;
173
173
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 2 , 'https://custom-url.com/successcomment-2' ) ) ;
174
- t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released' ] , 2 ) ) ;
174
+ t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released on @next ' ] , 2 ) ) ;
175
175
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 3 , 'https://custom-url.com/successcomment-3' ) ) ;
176
- t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released' ] , 3 ) ) ;
176
+ t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released on @next ' ] , 3 ) ) ;
177
177
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 4 , 'https://custom-url.com/successcomment-4' ) ) ;
178
- t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released' ] , 4 ) ) ;
178
+ t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released on @next ' ] , 4 ) ) ;
179
179
t . true ( github . isDone ( ) ) ;
180
180
}
181
181
) ;
@@ -504,20 +504,21 @@ test.serial('Ignore missing issues/PRs', async t => {
504
504
t . true ( github . isDone ( ) ) ;
505
505
} ) ;
506
506
507
- test . serial ( 'Add custom comment' , async t => {
507
+ test . serial ( 'Add custom comment and labels ' , async t => {
508
508
const owner = 'test_user' ;
509
509
const repo = 'test_repo' ;
510
510
const env = { GITHUB_TOKEN : 'github_token' } ;
511
511
const failTitle = 'The automated release is failing 🚨' ;
512
512
const pluginConfig = {
513
- successComment : `last release: \${lastRelease.version} nextRelease: \${nextRelease.version} branch: \${branch} commits: \${commits.length} releases: \${releases.length} PR attribute: \${issue.prop}` ,
513
+ successComment : `last release: \${lastRelease.version} nextRelease: \${nextRelease.version} branch: \${branch.name } commits: \${commits.length} releases: \${releases.length} PR attribute: \${issue.prop}` ,
514
514
failTitle,
515
+ releasedLabels : [ 'released on @<%= nextRelease.channel %>' , 'released from <%= branch.name %>' ] ,
515
516
} ;
516
517
const prs = [ { number : 1 , prop : 'PR prop' , pull_request : { } , state : 'closed' } ] ;
517
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
518
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
518
519
const lastRelease = { version : '1.0.0' } ;
519
520
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
520
- const nextRelease = { version : '2.0.0' } ;
521
+ const nextRelease = { version : '2.0.0' , channel : 'next' } ;
521
522
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
522
523
const github = authenticate ( env )
523
524
. get ( `/repos/${ owner } /${ repo } ` )
@@ -534,7 +535,7 @@ test.serial('Add custom comment', async t => {
534
535
body : / l a s t r e l e a s e : 1 \. 0 \. 0 n e x t R e l e a s e : 2 \. 0 \. 0 b r a n c h : m a s t e r c o m m i t s : 1 r e l e a s e s : 1 P R a t t r i b u t e : P R p r o p / ,
535
536
} )
536
537
. reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
537
- . post ( `/repos/${ owner } /${ repo } /issues/1/labels` , '{"labels":["released"]}' )
538
+ . post ( `/repos/${ owner } /${ repo } /issues/1/labels` , '{"labels":["released on @next","released from master "]}' )
538
539
. reply ( 200 , { } )
539
540
. get (
540
541
`/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
@@ -543,10 +544,19 @@ test.serial('Add custom comment', async t => {
543
544
)
544
545
. reply ( 200 , { items : [ ] } ) ;
545
546
546
- await success ( pluginConfig , { env, options, lastRelease, commits, nextRelease, releases, logger : t . context . logger } ) ;
547
+ await success ( pluginConfig , {
548
+ env,
549
+ branch : { name : 'master' } ,
550
+ options,
551
+ lastRelease,
552
+ commits,
553
+ nextRelease,
554
+ releases,
555
+ logger : t . context . logger ,
556
+ } ) ;
547
557
548
558
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
549
- t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released' ] , 1 ) ) ;
559
+ t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'released on @next' , 'released from master '] , 1 ) ) ;
550
560
t . true ( github . isDone ( ) ) ;
551
561
} ) ;
552
562
@@ -557,7 +567,7 @@ test.serial('Add custom label', async t => {
557
567
const failTitle = 'The automated release is failing 🚨' ;
558
568
const pluginConfig = { releasedLabels : [ 'custom label' ] , failTitle} ;
559
569
const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
560
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
570
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
561
571
const lastRelease = { version : '1.0.0' } ;
562
572
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
563
573
const nextRelease = { version : '2.0.0' } ;
@@ -584,7 +594,16 @@ test.serial('Add custom label', async t => {
584
594
)
585
595
. reply ( 200 , { items : [ ] } ) ;
586
596
587
- await success ( pluginConfig , { env, options, lastRelease, commits, nextRelease, releases, logger : t . context . logger } ) ;
597
+ await success ( pluginConfig , {
598
+ env,
599
+ options,
600
+ branch : { name : 'master' } ,
601
+ lastRelease,
602
+ commits,
603
+ nextRelease,
604
+ releases,
605
+ logger : t . context . logger ,
606
+ } ) ;
588
607
589
608
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
590
609
t . true ( t . context . log . calledWith ( 'Added labels %O to issue #%d' , [ 'custom label' ] , 1 ) ) ;
@@ -598,7 +617,7 @@ test.serial('Comment on issue/PR without ading a label', async t => {
598
617
const failTitle = 'The automated release is failing 🚨' ;
599
618
const pluginConfig = { releasedLabels : false , failTitle} ;
600
619
const prs = [ { number : 1 , pull_request : { } , state : 'closed' } ] ;
601
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
620
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
602
621
const lastRelease = { version : '1.0.0' } ;
603
622
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
604
623
const nextRelease = { version : '2.0.0' } ;
@@ -623,7 +642,16 @@ test.serial('Comment on issue/PR without ading a label', async t => {
623
642
)
624
643
. reply ( 200 , { items : [ ] } ) ;
625
644
626
- await success ( pluginConfig , { env, options, lastRelease, commits, nextRelease, releases, logger : t . context . logger } ) ;
645
+ await success ( pluginConfig , {
646
+ env,
647
+ options,
648
+ branch : { name : 'master' } ,
649
+ lastRelease,
650
+ commits,
651
+ nextRelease,
652
+ releases,
653
+ logger : t . context . logger ,
654
+ } ) ;
627
655
628
656
t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
629
657
t . true ( github . isDone ( ) ) ;
@@ -641,7 +669,7 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
641
669
{ number : 3 , body : `Issue 3 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
642
670
] ;
643
671
const prs = [ { number : 1 , pull_request : { } , state : 'closed' } , { number : 2 , pull_request : { } , state : 'closed' } ] ;
644
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
672
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
645
673
const commits = [ { hash : '123' , message : 'Commit 1 message' } , { hash : '456' , message : 'Commit 2 message' } ] ;
646
674
const nextRelease = { version : '1.0.0' } ;
647
675
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -675,7 +703,15 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
675
703
. reply ( 200 , { html_url : 'https://github.com/issues/3' } ) ;
676
704
677
705
const [ error1 , error2 ] = await t . throws (
678
- success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } )
706
+ success ( pluginConfig , {
707
+ env,
708
+ options,
709
+ branch : { name : 'master' } ,
710
+ commits,
711
+ nextRelease,
712
+ releases,
713
+ logger : t . context . logger ,
714
+ } )
679
715
) ;
680
716
681
717
t . is ( error1 . status , 400 ) ;
@@ -698,7 +734,7 @@ test.serial('Close open issues when a release is successful', async t => {
698
734
{ number : 2 , body : `Issue 2 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
699
735
{ number : 3 , body : `Issue 3 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
700
736
] ;
701
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
737
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
702
738
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
703
739
const nextRelease = { version : '1.0.0' } ;
704
740
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -722,7 +758,15 @@ test.serial('Close open issues when a release is successful', async t => {
722
758
. patch ( `/repos/${ owner } /${ repo } /issues/3` , { state : 'closed' } )
723
759
. reply ( 200 , { html_url : 'https://github.com/issues/3' } ) ;
724
760
725
- await success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } ) ;
761
+ await success ( pluginConfig , {
762
+ env,
763
+ options,
764
+ branch : { name : 'master' } ,
765
+ commits,
766
+ nextRelease,
767
+ releases,
768
+ logger : t . context . logger ,
769
+ } ) ;
726
770
727
771
t . true ( t . context . log . calledWith ( 'Closed issue #%d: %s.' , 2 , 'https://github.com/issues/2' ) ) ;
728
772
t . true ( t . context . log . calledWith ( 'Closed issue #%d: %s.' , 3 , 'https://github.com/issues/3' ) ) ;
@@ -735,7 +779,7 @@ test.serial('Skip commention on issues/PR if "successComment" is "false"', async
735
779
const env = { GITHUB_TOKEN : 'github_token' } ;
736
780
const failTitle = 'The automated release is failing 🚨' ;
737
781
const pluginConfig = { failTitle, successComment : false } ;
738
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
782
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
739
783
const commits = [ { hash : '123' , message : 'Commit 1 message\n\n Fix #1' , tree : { long : 'aaa' } } ] ;
740
784
const nextRelease = { version : '1.0.0' } ;
741
785
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -749,7 +793,15 @@ test.serial('Skip commention on issues/PR if "successComment" is "false"', async
749
793
)
750
794
. reply ( 200 , { items : [ ] } ) ;
751
795
752
- await success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } ) ;
796
+ await success ( pluginConfig , {
797
+ env,
798
+ options,
799
+ branch : { name : 'master' } ,
800
+ commits,
801
+ nextRelease,
802
+ releases,
803
+ logger : t . context . logger ,
804
+ } ) ;
753
805
754
806
t . true ( t . context . log . calledWith ( 'Skip commenting on issues and pull requests.' ) ) ;
755
807
t . true ( github . isDone ( ) ) ;
@@ -760,7 +812,7 @@ test.serial('Skip closing issues if "failComment" is "false"', async t => {
760
812
const repo = 'test_repo' ;
761
813
const env = { GITHUB_TOKEN : 'github_token' } ;
762
814
const pluginConfig = { failComment : false } ;
763
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
815
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
764
816
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
765
817
const nextRelease = { version : '1.0.0' } ;
766
818
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -774,7 +826,15 @@ test.serial('Skip closing issues if "failComment" is "false"', async t => {
774
826
)
775
827
. reply ( 200 , { items : [ ] } ) ;
776
828
777
- await success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } ) ;
829
+ await success ( pluginConfig , {
830
+ env,
831
+ options,
832
+ branch : { name : 'master' } ,
833
+ commits,
834
+ nextRelease,
835
+ releases,
836
+ logger : t . context . logger ,
837
+ } ) ;
778
838
t . true ( t . context . log . calledWith ( 'Skip closing issue.' ) ) ;
779
839
t . true ( github . isDone ( ) ) ;
780
840
} ) ;
@@ -784,7 +844,7 @@ test.serial('Skip closing issues if "failTitle" is "false"', async t => {
784
844
const repo = 'test_repo' ;
785
845
const env = { GITHUB_TOKEN : 'github_token' } ;
786
846
const pluginConfig = { failTitle : false } ;
787
- const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
847
+ const options = { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
788
848
const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
789
849
const nextRelease = { version : '1.0.0' } ;
790
850
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -798,7 +858,15 @@ test.serial('Skip closing issues if "failTitle" is "false"', async t => {
798
858
)
799
859
. reply ( 200 , { items : [ ] } ) ;
800
860
801
- await success ( pluginConfig , { env, options, commits, nextRelease, releases, logger : t . context . logger } ) ;
861
+ await success ( pluginConfig , {
862
+ env,
863
+ options,
864
+ branch : { name : 'master' } ,
865
+ commits,
866
+ nextRelease,
867
+ releases,
868
+ logger : t . context . logger ,
869
+ } ) ;
802
870
t . true ( t . context . log . calledWith ( 'Skip closing issue.' ) ) ;
803
871
t . true ( github . isDone ( ) ) ;
804
872
} ) ;
0 commit comments