1
1
import { escape } from 'querystring' ;
2
2
import test from 'ava' ;
3
+ import { repeat } from 'lodash' ;
3
4
import nock from 'nock' ;
4
5
import { stub } from 'sinon' ;
5
6
import ISSUE_ID from '../lib/definitions/sr-issue-id' ;
@@ -49,9 +50,9 @@ test.serial('Add comment to PRs associated with release commits and issues close
49
50
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
50
51
const github = authenticate ( )
51
52
. get (
52
- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
53
- 'type:pr'
54
- ) } `
53
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
54
+ . map ( commit => commit . hash )
55
+ . join ( '+' ) } `
55
56
)
56
57
. reply ( 200 , { items : prs } )
57
58
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -78,6 +79,70 @@ test.serial('Add comment to PRs associated with release commits and issues close
78
79
t . true ( github . isDone ( ) ) ;
79
80
} ) ;
80
81
82
+ test . serial ( 'Make multiple search queries if necessary' , async t => {
83
+ const owner = 'test_user' ;
84
+ const repo = 'test_repo' ;
85
+ process . env . GITHUB_TOKEN = 'github_token' ;
86
+ const failTitle = 'The automated release is failing :rotating_light:' ;
87
+ const pluginConfig = { failTitle} ;
88
+ const prs = [
89
+ { number : 1 , pull_request : { } } ,
90
+ { number : 2 , pull_request : { } } ,
91
+ { number : 3 , pull_request : { } } ,
92
+ { number : 4 , pull_request : { } } ,
93
+ { number : 5 , pull_request : { } } ,
94
+ { number : 6 , pull_request : { } } ,
95
+ ] ;
96
+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
97
+ const commits = [
98
+ { hash : repeat ( 'a' , 40 ) , message : 'Commit 1 message' } ,
99
+ { hash : repeat ( 'b' , 40 ) , message : 'Commit 2 message' } ,
100
+ { hash : repeat ( 'c' , 40 ) , message : 'Commit 3 message' } ,
101
+ { hash : repeat ( 'd' , 40 ) , message : 'Commit 4 message' } ,
102
+ { hash : repeat ( 'e' , 40 ) , message : 'Commit 5 message' } ,
103
+ { hash : repeat ( 'f' , 40 ) , message : 'Commit 6 message' } ,
104
+ ] ;
105
+ const nextRelease = { version : '1.0.0' } ;
106
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
107
+ const github = authenticate ( )
108
+ . get (
109
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ commits [ 0 ] . hash } +${ commits [ 1 ] . hash } +${
110
+ commits [ 2 ] . hash
111
+ } +${ commits [ 3 ] . hash } +${ commits [ 4 ] . hash } `
112
+ )
113
+ . reply ( 200 , { items : [ prs [ 0 ] , prs [ 1 ] , prs [ 2 ] , prs [ 3 ] , prs [ 4 ] ] } )
114
+ . get ( `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ commits [ 5 ] . hash } ` )
115
+ . reply ( 200 , { items : [ prs [ 5 ] ] } )
116
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
117
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
118
+ . post ( `/repos/${ owner } /${ repo } /issues/2/comments` , { body : / T h i s P R i s i n c l u d e d / } )
119
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-2' } )
120
+ . post ( `/repos/${ owner } /${ repo } /issues/3/comments` , { body : / T h i s P R i s i n c l u d e d / } )
121
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-3' } )
122
+ . post ( `/repos/${ owner } /${ repo } /issues/4/comments` , { body : / T h i s P R i s i n c l u d e d / } )
123
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-4' } )
124
+ . post ( `/repos/${ owner } /${ repo } /issues/5/comments` , { body : / T h i s P R i s i n c l u d e d / } )
125
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-5' } )
126
+ . post ( `/repos/${ owner } /${ repo } /issues/6/comments` , { body : / T h i s P R i s i n c l u d e d / } )
127
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-6' } )
128
+ . get (
129
+ `/search/issues?q=${ escape ( `title:${ failTitle } ` ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
130
+ 'type:issue'
131
+ ) } +${ escape ( 'state:open' ) } `
132
+ )
133
+ . reply ( 200 , { items : [ ] } ) ;
134
+
135
+ await success ( pluginConfig , { options, commits, nextRelease, releases, logger : t . context . logger } ) ;
136
+
137
+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ] ) ;
138
+ t . deepEqual ( t . context . log . args [ 1 ] , [ 'Added comment to issue #%d: %s' , 2 , 'https://github.com/successcomment-2' ] ) ;
139
+ t . deepEqual ( t . context . log . args [ 2 ] , [ 'Added comment to issue #%d: %s' , 3 , 'https://github.com/successcomment-3' ] ) ;
140
+ t . deepEqual ( t . context . log . args [ 3 ] , [ 'Added comment to issue #%d: %s' , 4 , 'https://github.com/successcomment-4' ] ) ;
141
+ t . deepEqual ( t . context . log . args [ 4 ] , [ 'Added comment to issue #%d: %s' , 5 , 'https://github.com/successcomment-5' ] ) ;
142
+ t . deepEqual ( t . context . log . args [ 5 ] , [ 'Added comment to issue #%d: %s' , 6 , 'https://github.com/successcomment-6' ] ) ;
143
+ t . true ( github . isDone ( ) ) ;
144
+ } ) ;
145
+
81
146
test . serial ( 'Do not add comment if no PR is associated with release commits' , async t => {
82
147
const owner = 'test_user' ;
83
148
const repo = 'test_repo' ;
@@ -90,9 +155,9 @@ test.serial('Do not add comment if no PR is associated with release commits', as
90
155
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
91
156
const github = authenticate ( )
92
157
. get (
93
- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
94
- 'type:pr'
95
- ) } `
158
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
159
+ . map ( commit => commit . hash )
160
+ . join ( '+' ) } `
96
161
)
97
162
. reply ( 200 , { items : [ ] } )
98
163
. get (
@@ -124,9 +189,9 @@ test.serial('Add custom comment', async t => {
124
189
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
125
190
const github = authenticate ( )
126
191
. get (
127
- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
128
- 'type:pr'
129
- ) } `
192
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
193
+ . map ( commit => commit . hash )
194
+ . join ( '+' ) } `
130
195
)
131
196
. reply ( 200 , { items : prs } )
132
197
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , {
@@ -163,9 +228,9 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
163
228
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
164
229
const github = authenticate ( )
165
230
. get (
166
- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
167
- 'type:pr'
168
- ) } `
231
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
232
+ . map ( commit => commit . hash )
233
+ . join ( '+' ) } `
169
234
)
170
235
. reply ( 200 , { items : prs } )
171
236
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -213,9 +278,9 @@ test.serial('Close open issues when a release is successful', async t => {
213
278
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
214
279
const github = authenticate ( )
215
280
. get (
216
- `/search/issues?q=${ commits . map ( commit => commit . hash ) . join ( '+' ) } + ${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape (
217
- 'type:pr'
218
- ) } `
281
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } + ${ commits
282
+ . map ( commit => commit . hash )
283
+ . join ( '+' ) } `
219
284
)
220
285
. reply ( 200 , { items : [ ] } )
221
286
. get (
0 commit comments