@@ -203,13 +203,11 @@ test('Retry create comment when it fails', async () => {
203
203
test ( 'create (draft) PR' , async ( ) => {
204
204
const createPR = jest . fn ( )
205
205
let capturedCommitMessage = ''
206
- const createCommit = ( { message } ) => {
207
- capturedCommitMessage = message
208
- return ( { data : { sha : 'abcd1234' } } )
209
- }
210
206
const ctx = helpers . getDefaultContext ( )
211
207
ctx . octokit . pulls . create = createPR
212
- ctx . octokit . git . createCommit = createCommit
208
+ ctx . octokit . graphql = ( _ , { message } ) => {
209
+ capturedCommitMessage = message
210
+ }
213
211
214
212
await github . createPr ( { log : ( ) => { } } , ctx , { silent : false } , 'robvanderleek' , 'issue-1' )
215
213
expect ( createPR ) . toHaveBeenCalledWith ( {
@@ -237,11 +235,10 @@ test('create (draft) PR', async () => {
237
235
238
236
test ( 'copy Issue description into PR' , async ( ) => {
239
237
const createPR = jest . fn ( )
240
- const createCommit = ( ) => ( { data : { sha : 'abcd1234' } } )
241
238
const ctx = helpers . getDefaultContext ( )
242
239
ctx . octokit . pulls . create = createPR
243
- ctx . octokit . git . createCommit = createCommit
244
240
ctx . payload . issue . body = 'This is the description'
241
+ ctx . octokit . graphql = jest . fn ( )
245
242
246
243
await github . createPr ( { log : ( ) => { } } , ctx , { copyIssueDescriptionToPR : true , silent : false } , 'robvanderleek' ,
247
244
'issue-1' )
@@ -259,11 +256,10 @@ test('copy Issue description into PR', async () => {
259
256
260
257
test ( 'Do not copy undefined Issue description into PR' , async ( ) => {
261
258
const createPR = jest . fn ( )
262
- const createCommit = ( ) => ( { data : { sha : 'abcd1234' } } )
263
259
const ctx = helpers . getDefaultContext ( )
264
260
ctx . octokit . pulls . create = createPR
265
- ctx . octokit . git . createCommit = createCommit
266
261
ctx . payload . issue . body = null
262
+ ctx . octokit . graphql = jest . fn ( )
267
263
268
264
await github . createPr ( { log : ( ) => { } } , ctx , { copyIssueDescriptionToPR : true , silent : false } , 'robvanderleek' ,
269
265
'issue-1' )
@@ -282,6 +278,7 @@ test('use correct source branch', async () => {
282
278
const createPR = jest . fn ( )
283
279
const ctx = helpers . getDefaultContext ( )
284
280
ctx . octokit . pulls . create = createPR
281
+ ctx . octokit . graphql = jest . fn ( )
285
282
ctx . payload . issue . labels = [ { name : 'enhancement' } ]
286
283
const config = { branches : [ { label : 'enhancement' , name : 'develop' } ] }
287
284
@@ -301,6 +298,7 @@ test('use configured target branch', async () => {
301
298
const createPR = jest . fn ( )
302
299
const ctx = helpers . getDefaultContext ( )
303
300
ctx . octokit . pulls . create = createPR
301
+ ctx . octokit . graphql = jest . fn ( )
304
302
ctx . payload . issue . labels = [ { name : 'enhancement' } ]
305
303
const config = { branches : [ { label : 'enhancement' , prTarget : 'develop' } ] }
306
304
@@ -320,6 +318,7 @@ test('configured source and target branch', async () => {
320
318
const createPR = jest . fn ( )
321
319
const ctx = helpers . getDefaultContext ( )
322
320
ctx . octokit . pulls . create = createPR
321
+ ctx . octokit . graphql = jest . fn ( )
323
322
ctx . payload . issue . labels = [ { name : 'hotfix' } ]
324
323
const config = { branches : [ { label : 'hotfix' , name : 'develop' , prTarget : 'hotfix' } ] }
325
324
@@ -337,11 +336,10 @@ test('configured source and target branch', async () => {
337
336
338
337
test ( 'copy Issue milestone into PR' , async ( ) => {
339
338
const updateIssue = jest . fn ( )
340
- const createCommit = ( ) => ( { data : { sha : 'abcd1234' } } )
341
339
const ctx = helpers . getDefaultContext ( )
342
340
ctx . octokit . pulls . create = ( ) => ( { data : { number : 123 } } )
343
341
ctx . octokit . issues . update = updateIssue
344
- ctx . octokit . git . createCommit = createCommit
342
+ ctx . octokit . graphql = jest . fn ( )
345
343
ctx . payload . issue . body = 'This is the description'
346
344
ctx . payload . issue . milestone = { number : 456 }
347
345
@@ -353,27 +351,31 @@ test('copy Issue milestone into PR', async () => {
353
351
} )
354
352
355
353
test ( 'empty commit text' , async ( ) => {
356
- const createCommit = jest . fn ( )
357
354
const ctx = helpers . getDefaultContext ( )
358
355
ctx . octokit . pulls . create = ( ) => ( { data : { number : 123 } } )
359
- ctx . octokit . git . createCommit = createCommit
356
+ let capturedCommitMessage = ''
357
+ ctx . octokit . graphql = ( _ , { message } ) => {
358
+ capturedCommitMessage = message
359
+ }
360
360
ctx . payload . issue . body = 'This is the description'
361
361
ctx . payload . issue . milestone = { number : 456 }
362
362
363
363
await github . createPr ( { log : ( ) => { } } , ctx , { } , 'robvanderleek' , 'issue-1' )
364
364
365
- expect ( createCommit . mock . calls [ 0 ] [ 0 ] . message ) . toBe ( 'Create PR for #1' )
365
+ expect ( capturedCommitMessage ) . toBe ( 'Create PR for #1' )
366
366
} )
367
367
368
368
test ( 'empty commit with skip CI text' , async ( ) => {
369
- const createCommit = jest . fn ( )
370
369
const ctx = helpers . getDefaultContext ( )
371
370
ctx . octokit . pulls . create = ( ) => ( { data : { number : 123 } } )
372
- ctx . octokit . git . createCommit = createCommit
371
+ let capturedCommitMessage = ''
372
+ ctx . octokit . graphql = ( _ , { message } ) => {
373
+ capturedCommitMessage = message
374
+ }
373
375
ctx . payload . issue . body = 'This is the description'
374
376
ctx . payload . issue . milestone = { number : 456 }
375
377
376
378
await github . createPr ( { log : ( ) => { } } , ctx , { prSkipCI : true } , 'robvanderleek' , 'issue-1' )
377
379
378
- expect ( createCommit . mock . calls [ 0 ] [ 0 ] . message ) . toBe ( 'Create PR for #1\n[skip ci]' )
380
+ expect ( capturedCommitMessage ) . toBe ( 'Create PR for #1\n[skip ci]' )
379
381
} )
0 commit comments