-
Notifications
You must be signed in to change notification settings - Fork 317
/
index.test.js
2658 lines (2269 loc) · 81.3 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const nock = require('nock')
const { Probot, ProbotOctokit } = require('probot')
const { getConfigMock } = require('./helpers/config-mock')
const releaseDrafter = require('../index')
const mockedEnv = require('mocked-env')
const pino = require('pino')
const Stream = require('stream')
const pushPayload = require('./fixtures/push.json')
const pushTagPayload = require('./fixtures/push-tag.json')
const releasePayload = require('./fixtures/release.json')
const release2Payload = require('./fixtures/release-2.json')
const release3Payload = require('./fixtures/release-3.json')
const pushNonMasterPayload = require('./fixtures/push-non-master-branch.json')
const graphqlCommitsNoPRsPayload = require('./fixtures/graphql-commits-no-prs.json')
const graphqlCommitsMergeCommit = require('./fixtures/__generated__/graphql-commits-merge-commit.json')
const graphqlCommitsEmpty = require('./fixtures/graphql-commits-empty.json')
const releaseDrafterFixture = require('./fixtures/release-draft.json')
const graphqlCommitsOverlappingLabel = require('./fixtures/__generated__/graphql-commits-overlapping-label.json')
const graphqlCommitsRebaseMerging = require('./fixtures/__generated__/graphql-commits-rebase-merging.json')
const graphqlCommitsSquashMerging = require('./fixtures/__generated__/graphql-commits-squash-merging.json')
const releaseSharedCommitDate = require('./fixtures/release-shared-commit-date.json')
const graphqlCommitsForking = require('./fixtures/__generated__/graphql-commits-forking.json')
const graphqlCommitsPaginated1 = require('./fixtures/graphql-commits-paginated-1.json')
const graphqlCommitsPaginated2 = require('./fixtures/graphql-commits-paginated-2.json')
nock.disableNetConnect()
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQC2RTg7dNjQMwPzFwF0gXFRCcRHha4H24PeK7ey6Ij39ay1hy2o
H9NEZOxrmAb0bEBDuECImTsJdpgI6F3OwkJGsOkIH09xTk5tC4fkfY8N7LklK+uM
ndN4+VUXTPSj/U8lQtCd9JnnUL/wXDc46wRJ0AAKsQtUw5n4e44f+aYggwIDAQAB
AoGAW2/cJs+WWNPO3msjGrw5CYtZwPuJ830m6RSLYiAPXj0LuEEpIVdd18i9Zbht
fL61eoN7NEuSd0vcN1PCg4+mSRAb/LoauSO3HXote+6Lhg+y5mVYTNkE0ZAW1zUb
HOelQp9M6Ia/iQFIMykhrNLqMG9xQIdLH8BDGuqTE+Eh8jkCQQDyR6qfowD64H09
oYJI+QbsE7yDOnG68tG7g9h68Mp089YuQ43lktz0q3fhC7BhBuSnfkBHwMztABuA
Ow1+dP9FAkEAwJeYJYxJN9ron24IePDoZkL0T0faIWIX2htZH7kJODs14OP+YMVO
1CPShdTIgFeVp/HlAY2Qqk/do2fzyueZJwJBAN5GvdUjmRyRpJVMfdkxDxa7rLHA
huL7L0wX1B5Gl5fgtVlQhPhgWvLl9V+0d6csyc6Y16R80AWHmbN1ehXQhPkCQGfF
RsV0gT8HRLAiqY4AwDfZe6n8HRw/rnpmoe7l1IHn5W/3aOjbZ04Gvzg9HouIpaqI
O8xKathZkCKrsEBz6aECQQCLgqOCJz4MGIVHP4vQHgYp8YNZ+RMSfJfZA9AyAsgP
Pc6zWtW2XuNIGHw9pDj7v1yDolm7feBXLg8/u9APwHDy
-----END RSA PRIVATE KEY-----`
describe('release-drafter', () => {
let probot
let logger
let restoreEnvironment
const streamLogsToOutput = new Stream.Writable({ objectMode: true })
streamLogsToOutput._write = (object, encoding, done) => {
logger.push(JSON.parse(object))
done()
}
probot = new Probot({
appId: 179_208,
privateKey,
githubToken: 'test',
Octokit: ProbotOctokit.defaults({
retry: { enabled: false },
throttle: { enabled: false },
}),
log: pino(streamLogsToOutput),
})
probot.load(releaseDrafter)
beforeEach(() => {
logger = []
nock('https://api.github.com')
.post('/app/installations/179208/access_tokens')
.reply(200, { token: 'test' })
let mockEnvironment = {}
// We have to delete all the GITHUB_* envs before every test, because if
// we're running the tests themselves inside a GitHub Actions container
// they'll mess with the tests, and also because we set some of them in
// tests and we don't want them to leak into other tests.
for (const key of Object.keys(process.env).filter((key) =>
key.match(/^GITHUB_/)
)) {
mockEnvironment[key] = undefined
}
restoreEnvironment = mockedEnv(mockEnvironment)
})
afterAll(nock.restore)
afterEach(() => {
nock.cleanAll()
restoreEnvironment()
})
describe('push', () => {
describe('without a config', () => {
it('does nothing', async () => {
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/contents/.github%2Frelease-drafter.yml'
)
.reply(404)
.get(
'/repos/toolmantim/.github/contents/.github%2Frelease-drafter.yml'
)
.reply(404)
await probot.receive({
name: 'push',
payload: pushPayload,
})
})
})
describe('to a non-master branch', () => {
it('does nothing', async () => {
getConfigMock()
nock('https://api.github.com')
.post('/repos/:owner/:repo/releases')
.reply(200, () => {
throw new Error("Shouldn't create a new release")
})
.patch('/repos/:owner/:repo/releases/:release_id')
.reply(200, () => {
throw new Error("Shouldn't update an existing release")
})
await probot.receive({
name: 'push',
payload: pushNonMasterPayload,
})
})
describe('when configured for that branch', () => {
it('creates a release draft', async () => {
getConfigMock('config-non-master-branch.yml')
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsNoPRsPayload)
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* No changes
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushNonMasterPayload,
})
})
})
})
describe('to a tag', () => {
it('does nothing', async () => {
getConfigMock('config-tag-reference.yml')
nock('https://api.github.com')
.post('/repos/:owner/:repo/releases')
.reply(200, () => {
throw new Error("Shouldn't create a new release")
})
.patch('/repos/:owner/:repo/releases/:release_id')
.reply(200, () => {
throw new Error("Shouldn't update an existing release")
})
await probot.receive({
name: 'push',
payload: pushPayload,
})
})
describe('when configured for that tag', () => {
it('creates a release draft', async () => {
getConfigMock('config-tag-reference.yml')
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushTagPayload,
})
})
})
})
describe('with no past releases', () => {
it('sets $CHANGES based on all commits, and $PREVIOUS_TAG to blank', async () => {
getConfigMock('config-previous-tag.yml')
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [])
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Changes:
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
Previous tag: ''
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
const payload = pushPayload
await probot.receive({
name: 'push',
payload,
})
expect.assertions(1)
})
})
describe('with past releases', () => {
it('creates a new draft listing the changes', async () => {
getConfigMock()
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [release2Payload, releasePayload, release3Payload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
it('creates a new draft when run as a GitHub Action', async () => {
getConfigMock()
// GitHub actions should use the GITHUB_REF and not the payload ref
process.env['GITHUB_REF'] = 'refs/heads/master'
process.env['GITHUB_ACTIONS'] = 'true'
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [release2Payload, releasePayload, release3Payload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
// This payload has a different ref to GITHUB_REF, which is how GitHub
// Action merge push payloads behave
payload: pushNonMasterPayload,
})
expect.assertions(1)
})
it('makes next versions available as template placeholders', async () => {
getConfigMock('config-with-next-versioning.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Placeholder with example. Automatically calculated values are next major=3.0.0 (major=3, minor=0, patch=0), minor=2.1.0 (major=2, minor=1, patch=0), patch=2.0.1 (major=2, minor=0, patch=1)",
"draft": true,
"name": "v2.0.1 (Code name: Placeholder)",
"prerelease": false,
"tag_name": "v2.0.1",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
describe('with custom changes-template config', () => {
it('creates a new draft using the template', async () => {
getConfigMock('config-with-changes-templates.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "* Change: #5 'Add documentation' @TimonVS
* Change: #4 'Update dependencies' @TimonVS
* Change: #3 'Bug fixes' @TimonVS
* Change: #2 'Add big feature' @TimonVS
* Change: #1 '👽 Add alien technology' @TimonVS",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
describe('with custom changes-template config that includes a pull request body', () => {
it('creates a new draft using the template', async () => {
getConfigMock('config-with-changes-templates-and-body.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "* Change: #5 'Add documentation' ✍️ writing docs all day
* Change: #4 'Update dependencies' 📦 Package time! 📦
* Change: #3 'Bug fixes' 🐛 squashing
* Change: #2 'Add big feature' ![I'm kind of a big deal](https://media.giphy.com/media/9LFBOD8a1Ip2M/giphy.gif)
* Change: #1 '👽 Add alien technology' Space invasion 👾",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
describe('with custom changes-template config that includes a pull request URL', () => {
it('creates a new draft using the template', async () => {
getConfigMock('config-with-changes-templates-and-url.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "* Change: https://github.com/toolmantim/release-drafter-test-project/pull/5 'Add documentation' @TimonVS
* Change: https://github.com/toolmantim/release-drafter-test-project/pull/4 'Update dependencies' @TimonVS
* Change: https://github.com/toolmantim/release-drafter-test-project/pull/3 'Bug fixes' @TimonVS
* Change: https://github.com/toolmantim/release-drafter-test-project/pull/2 'Add big feature' @TimonVS
* Change: https://github.com/toolmantim/release-drafter-test-project/pull/1 '👽 Add alien technology' @TimonVS",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
describe('with contributors config', () => {
it('adds the contributors', async () => {
getConfigMock('config-with-contributors.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "A big thanks to: @TimonVS and Ada Lovelace",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
it('uses no-contributors-template when there are no contributors', async () => {
getConfigMock('config-with-contributors.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsEmpty)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "A big thanks to: Nobody",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
describe('with exclude-contributors config', () => {
it('excludes matching contributors by username', async () => {
getConfigMock('config-with-exclude-contributors.yml')
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "A big thanks to: Ada Lovelace",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
})
describe('with no changes since the last release', () => {
it('creates a new draft with no changes', async () => {
getConfigMock()
nock('https://api.github.com')
.get(
'/repos/toolmantim/release-drafter-test-project/releases?per_page=100'
)
.reply(200, [release2Payload, releasePayload, release3Payload])
nock('https://api.github.com')
.post('/graphql', (body) => {
expect(body.variables.since).toBe(release3Payload.created_at)
return body.query.includes(
'query findCommitsWithAssociatedPullRequests'
)
})
.reply(200, graphqlCommitsEmpty)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* No changes
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(2)
})
describe('with custom no-changes-template config', () => {
it('creates a new draft with the template', async () => {
getConfigMock('config-with-changes-templates.yml')
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsEmpty)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "* No changes mmkay",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
})
describe('with an existing draft release', () => {
it('updates the existing release’s body', async () => {
getConfigMock()
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releaseDrafterFixture])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.patch(
'/repos/toolmantim/release-drafter-test-project/releases/11691725',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
",
"draft": true,
"name": "v3.0.0-beta",
"prerelease": false,
"tag_name": "v3.0.0-beta",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
})
describe('with categories config', () => {
it('categorizes pull requests with single label', async () => {
getConfigMock('config-with-categories.yml')
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
## 🚀 Features
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
## 🐛 Bug Fixes
* Bug fixes (#3) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
it('categorizes pull requests with multiple labels', async () => {
getConfigMock('config-with-categories-2.yml')
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
## 🚀 Features
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
## 🐛 Bug Fixes
* Bug fixes (#3) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)
await probot.receive({
name: 'push',
payload: pushPayload,
})
expect.assertions(1)
})
it('categorizes pull requests with overlapping labels', async () => {
getConfigMock('config-with-categories-3.yml')
nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])
nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsOverlappingLabel)
nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#22) @jetersen
* Update dependencies (#21) @jetersen
## 🚀 Features
* Add big feature (#19) @jetersen