@@ -51,9 +51,9 @@ test.serial('Add comment to PRs associated with release commits and issues close
51
51
const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } , body : 'Fixes #3' } ] ;
52
52
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
53
53
const commits = [
54
- { hash : '123' , message : 'Commit 1 message\n\n Fix #1' } ,
55
- { hash : '456' , message : 'Commit 2 message' } ,
56
- { hash : '789' , message : 'Commit 3 message Closes #4' } ,
54
+ { hash : '123' , message : 'Commit 1 message\n\n Fix #1' , tree : { long : 'aaa' } } ,
55
+ { hash : '456' , message : 'Commit 2 message' , tree : { long : 'ccc' } } ,
56
+ { hash : '789' , message : 'Commit 3 message Closes #4' , tree : { long : 'ccc' } } ,
57
57
] ;
58
58
const nextRelease = { version : '1.0.0' } ;
59
59
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -116,13 +116,13 @@ test.serial('Make multiple search queries if necessary', async t => {
116
116
] ;
117
117
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
118
118
const commits = [
119
- { hash : repeat ( 'a' , 40 ) , message : 'Commit 1 message' } ,
120
- { hash : repeat ( 'b' , 40 ) , message : 'Commit 2 message' } ,
121
- { hash : repeat ( 'c' , 40 ) , message : 'Commit 3 message' } ,
122
- { hash : repeat ( 'd' , 40 ) , message : 'Commit 4 message' } ,
123
- { hash : repeat ( 'e' , 40 ) , message : 'Commit 5 message' } ,
124
- { hash : repeat ( 'f' , 40 ) , message : 'Commit 6 message' } ,
125
- { hash : repeat ( 'g' , 40 ) , message : 'Commit 7 message' } ,
119
+ { hash : repeat ( 'a' , 40 ) , message : 'Commit 1 message' , tree : { long : 'aaa' } } ,
120
+ { hash : repeat ( 'b' , 40 ) , message : 'Commit 2 message' , tree : { long : 'bbb' } } ,
121
+ { hash : repeat ( 'c' , 40 ) , message : 'Commit 3 message' , tree : { long : 'ccc' } } ,
122
+ { hash : repeat ( 'd' , 40 ) , message : 'Commit 4 message' , tree : { long : 'ddd' } } ,
123
+ { hash : repeat ( 'e' , 40 ) , message : 'Commit 5 message' , tree : { long : 'eee' } } ,
124
+ { hash : repeat ( 'f' , 40 ) , message : 'Commit 6 message' , tree : { long : 'fff' } } ,
125
+ { hash : repeat ( 'g' , 40 ) , message : 'Commit 7 message' , tree : { long : 'ggg' } } ,
126
126
] ;
127
127
const nextRelease = { version : '1.0.0' } ;
128
128
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -193,15 +193,18 @@ test.serial('Make multiple search queries if necessary', async t => {
193
193
t . true ( github . isDone ( ) ) ;
194
194
} ) ;
195
195
196
- test . serial ( 'Do not add comment for unrelated PR returned by search' , async t => {
196
+ test . serial ( 'Do not add comment for unrelated PR returned by search (compare sha) ' , async t => {
197
197
const owner = 'test_user' ;
198
198
const repo = 'test_repo' ;
199
199
process . env . GITHUB_TOKEN = 'github_token' ;
200
200
const failTitle = 'The automated release is failing 🚨' ;
201
201
const pluginConfig = { failTitle} ;
202
202
const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } } ] ;
203
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' } ] ;
204
+ const commits = [
205
+ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ,
206
+ { hash : '456' , message : 'Commit 2 message' , tree : { long : 'bbb' } } ,
207
+ ] ;
205
208
const nextRelease = { version : '1.0.0' } ;
206
209
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
207
210
const github = authenticate ( )
@@ -214,7 +217,49 @@ test.serial('Do not add comment for unrelated PR returned by search', async t =>
214
217
. get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
215
218
. reply ( 200 , [ { sha : commits [ 0 ] . hash } ] )
216
219
. get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
217
- . reply ( 200 , [ { sha : 'unrelated_commit' } ] )
220
+ . reply ( 200 , [ { sha : 'unrelated_commit' , commit : { tree : { sha : 'unrelated_commit' } } } ] )
221
+ . get ( `/repos/${ owner } /${ repo } /issues/1` )
222
+ . reply ( 200 , { state : 'closed' } )
223
+ . post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
224
+ . reply ( 200 , { html_url : 'https://github.com/successcomment-1' } )
225
+ . get (
226
+ `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
227
+ 'state:open'
228
+ ) } +${ escape ( failTitle ) } `
229
+ )
230
+ . reply ( 200 , { items : [ ] } ) ;
231
+
232
+ await success ( pluginConfig , { options, commits, nextRelease, releases, logger : t . context . logger } ) ;
233
+
234
+ t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s' , 1 , 'https://github.com/successcomment-1' ) ) ;
235
+ t . true ( github . isDone ( ) ) ;
236
+ } ) ;
237
+
238
+ test . serial ( 'Do not add comment for unrelated PR returned by search (compare tree sha)' , async t => {
239
+ const owner = 'test_user' ;
240
+ const repo = 'test_repo' ;
241
+ process . env . GITHUB_TOKEN = 'github_token' ;
242
+ const failTitle = 'The automated release is failing 🚨' ;
243
+ const pluginConfig = { failTitle} ;
244
+ const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } } ] ;
245
+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
246
+ const commits = [
247
+ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ,
248
+ { hash : '456' , message : 'Commit 2 message' , tree : { long : 'bbb' } } ,
249
+ ] ;
250
+ const nextRelease = { version : '1.0.0' } ;
251
+ const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
252
+ const github = authenticate ( )
253
+ . get (
254
+ `/search/issues?q=${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:pr' ) } +${ escape ( 'is:merged' ) } +${ commits
255
+ . map ( commit => commit . hash )
256
+ . join ( '+' ) } `
257
+ )
258
+ . reply ( 200 , { items : prs } )
259
+ . get ( `/repos/${ owner } /${ repo } /pulls/1/commits` )
260
+ . reply ( 200 , [ { sha : 'rebased_sha' , commit : { tree : { sha : commits [ 0 ] . tree . long } } } ] )
261
+ . get ( `/repos/${ owner } /${ repo } /pulls/2/commits` )
262
+ . reply ( 200 , [ { sha : 'unrelated_commit' , commit : { tree : { sha : 'unrelated_commit' } } } ] )
218
263
. get ( `/repos/${ owner } /${ repo } /issues/1` )
219
264
. reply ( 200 , { state : 'closed' } )
220
265
. post ( `/repos/${ owner } /${ repo } /issues/1/comments` , { body : / T h i s P R i s i n c l u d e d / } )
@@ -240,7 +285,7 @@ test.serial('Do not add comment to open issues/PRs', async t => {
240
285
const pluginConfig = { failTitle} ;
241
286
const prs = [ { number : 1 , pull_request : { } , body : 'Fixes #2' } ] ;
242
287
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
243
- const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
288
+ const commits = [ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ] ;
244
289
const nextRelease = { version : '1.0.0' } ;
245
290
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
246
291
const github = authenticate ( )
@@ -279,7 +324,7 @@ test.serial('Do not add comment if no PR is associated with release commits', as
279
324
const failTitle = 'The automated release is failing 🚨' ;
280
325
const pluginConfig = { failTitle} ;
281
326
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
282
- const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
327
+ const commits = [ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ] ;
283
328
const nextRelease = { version : '1.0.0' } ;
284
329
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
285
330
const github = authenticate ( )
@@ -309,9 +354,9 @@ test.serial('Do not add comment to PR/issues from other repo', async t => {
309
354
const pluginConfig = { failTitle} ;
310
355
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
311
356
const commits = [
312
- { hash : '123' , message : 'Commit 1 message\n\n Fix other/other#1' } ,
313
- { hash : '456' , message : `Commit 2 message Fix ${ owner } /${ repo } #2` } ,
314
- { hash : '789' , message : 'Commit 3 message Closes other/other#3' } ,
357
+ { hash : '123' , message : 'Commit 1 message\n\n Fix other/other#1' , tree : { long : 'aaa' } } ,
358
+ { hash : '456' , message : `Commit 2 message Fix ${ owner } /${ repo } #2` , tree : { long : 'bbb' } } ,
359
+ { hash : '789' , message : 'Commit 3 message Closes other/other#3' , tree : { long : 'ccc' } } ,
315
360
] ;
316
361
const nextRelease = { version : '1.0.0' } ;
317
362
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
@@ -346,7 +391,10 @@ test.serial('Ignore missing issues/PRs', async t => {
346
391
const pluginConfig = { failTitle} ;
347
392
const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } , body : 'Fixes #3' } ] ;
348
393
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
349
- const commits = [ { hash : '123' , message : 'Commit 1 message\n\n Fix #1' } , { hash : '456' , message : 'Commit 2 message' } ] ;
394
+ const commits = [
395
+ { hash : '123' , message : 'Commit 1 message\n\n Fix #1' , tree : { long : 'aaa' } } ,
396
+ { hash : '456' , message : 'Commit 2 message' , tree : { long : 'bbb' } } ,
397
+ ] ;
350
398
const nextRelease = { version : '1.0.0' } ;
351
399
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
352
400
const github = authenticate ( )
@@ -400,7 +448,7 @@ test.serial('Add custom comment', async t => {
400
448
const prs = [ { number : 1 , prop : 'PR prop' , pull_request : { } } ] ;
401
449
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
402
450
const lastRelease = { version : '1.0.0' } ;
403
- const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
451
+ const commits = [ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ] ;
404
452
const nextRelease = { version : '2.0.0' } ;
405
453
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
406
454
const github = authenticate ( )
@@ -443,7 +491,10 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
443
491
] ;
444
492
const prs = [ { number : 1 , pull_request : { } } , { number : 2 , pull_request : { } } ] ;
445
493
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
446
- const commits = [ { hash : '123' , message : 'Commit 1 message' } , { hash : '456' , message : 'Commit 2 message' } ] ;
494
+ const commits = [
495
+ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ,
496
+ { hash : '456' , message : 'Commit 2 message' , tree : { long : 'bbb' } } ,
497
+ ] ;
447
498
const nextRelease = { version : '1.0.0' } ;
448
499
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
449
500
const github = authenticate ( )
@@ -502,7 +553,7 @@ test.serial('Close open issues when a release is successful', async t => {
502
553
{ number : 3 , body : `Issue 3 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
503
554
] ;
504
555
const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
505
- const commits = [ { hash : '123' , message : 'Commit 1 message' } ] ;
556
+ const commits = [ { hash : '123' , message : 'Commit 1 message' , tree : { long : 'aaa' } } ] ;
506
557
const nextRelease = { version : '1.0.0' } ;
507
558
const releases = [ { name : 'GitHub release' , url : 'https://github.com/release' } ] ;
508
559
const github = authenticate ( )
0 commit comments