@@ -64,6 +64,10 @@ test.serial('Add comment to PRs associated with release commits and issues close
64
64
. join ( '+' ) } `
65
65
)
66
66
. reply ( 200 , { items : prs } )
67
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
68
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
69
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
70
+ . reply ( 200 , [ { sha : commits [ 1 ] . hash } ] )
67
71
. get ( `/repos/${ owner } /${ repo } /issues/1` )
68
72
. reply ( 200 , { state : 'closed' } )
69
73
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -135,6 +139,18 @@ test.serial('Make multiple search queries if necessary', async t => {
135
139
} +${ commits [ 6 ] . hash } `
136
140
)
137
141
. reply ( 200 , { items : [ prs [ 5 ] , prs [ 1 ] ] } )
142
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
143
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
144
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
145
+ . reply ( 200 , [ { sha : commits [ 1 ] . hash } ] )
146
+ . get ( `/repos/${ owner } /${ repo } /pulls/3/commits` )
147
+ . reply ( 200 , [ { sha : commits [ 2 ] . hash } ] )
148
+ . get ( `/repos/${ owner } /${ repo } /pulls/4/commits` )
149
+ . reply ( 200 , [ { sha : commits [ 3 ] . hash } ] )
150
+ . get ( `/repos/${ owner } /${ repo } /pulls/5/commits` )
151
+ . reply ( 200 , [ { sha : commits [ 4 ] . hash } ] )
152
+ . get ( `/repos/${ owner } /${ repo } /pulls/6/commits` )
153
+ . reply ( 200 , [ { sha : commits [ 5 ] . hash } ] )
138
154
. get ( `/repos/${ owner } /${ repo } /issues/1` )
139
155
. reply ( 200 , { state : 'closed' } )
140
156
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -177,6 +193,45 @@ test.serial('Make multiple search queries if necessary', async t => {
177
193
t . true ( github . isDone ( ) ) ;
178
194
} ) ;
179
195
196
+ test . serial ( 'Do not add comment for unrelated PR returned by search' , async t => {
197
+ const owner = 'test_user' ;
198
+ const repo = 'test_repo' ;
199
+ process . env . GITHUB_TOKEN = 'github_token' ;
200
+ const failTitle = 'The automated release is failing 🚨' ;
201
+ const pluginConfig = { failTitle} ;
202
+ const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } } ] ;
203
+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
204
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } , { hash : '456' , message : 'Commit 2 message' } ] ;
205
+ const nextRelease = { version : '1.0.0' } ;
206
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
207
+ const github = authenticate ( )
208
+ . get (
209
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
210
+ . map ( commit => commit . hash )
211
+ . join ( '+' ) } `
212
+ )
213
+ . reply ( 200 , { items : prs } )
214
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
215
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
216
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
217
+ . reply ( 200 , [ { sha : 'unrelated_commit' } ] )
218
+ . get ( `/repos/${ owner } /${ repo } /issues/1` )
219
+ . reply ( 200 , { state : 'closed' } )
220
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
221
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
222
+ . get (
223
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
224
+ 'state:open'
225
+ ) } +${ escape ( failTitle ) } `
226
+ )
227
+ . reply ( 200 , { items : [ ] } ) ;
228
+
229
+ await success ( pluginConfig , { options, commits, nextRelease, releases, logger : t . context . logger } ) ;
230
+
231
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
232
+ t . true ( github . isDone ( ) ) ;
233
+ } ) ;
234
+
180
235
test . serial ( 'Do not add comment to open issues/PRs' , async t => {
181
236
const owner = 'test_user' ;
182
237
const repo = 'test_repo' ;
@@ -195,6 +250,8 @@ test.serial('Do not add comment to open issues/PRs', async t => {
195
250
. join ( '+' ) } `
196
251
)
197
252
. reply ( 200 , { items : prs } )
253
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
254
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
198
255
. get ( `/repos/${ owner } /${ repo } /issues/1` )
199
256
. reply ( 200 , { state : 'closed' } )
200
257
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -299,6 +356,10 @@ test.serial('Ignore missing issues/PRs', async t => {
299
356
. join ( '+' ) } `
300
357
)
301
358
. reply ( 200 , { items : prs } )
359
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
360
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
361
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
362
+ . reply ( 200 , [ { sha : commits [ 1 ] . hash } ] )
302
363
. get ( `/repos/${ owner } /${ repo } /issues/1` )
303
364
. reply ( 200 , { state : 'closed' } )
304
365
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -349,6 +410,8 @@ test.serial('Add custom comment', async t => {
349
410
. join ( '+' ) } `
350
411
)
351
412
. reply ( 200 , { items : prs } )
413
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
414
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
352
415
. get ( `/repos/${ owner } /${ repo } /issues/1` )
353
416
. reply ( 200 , { state : 'closed' } )
354
417
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , {
@@ -380,7 +443,7 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
380
443
] ;
381
444
const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } } ] ;
382
445
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
383
- const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
446
+ const commits = [ { hash : '123' , message : 'Commit 1 message' } , { hash : '456' , message : 'Commit 2 message' } ] ;
384
447
const nextRelease = { version : '1.0.0' } ;
385
448
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
386
449
const github = authenticate ( )
@@ -390,6 +453,10 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
390
453
. join ( '+' ) } `
391
454
)
392
455
. reply ( 200 , { items : prs } )
456
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
457
+ . reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
458
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
459
+ . reply ( 200 , [ { sha : commits [ 1 ] . hash } ] )
393
460
. get ( `/repos/${ owner } /${ repo } /issues/1` )
394
461
. reply ( 200 , { state : 'closed' } )
395
462
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
0 commit comments