@@ -364,14 +364,12 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
364
364
when :
365
365
groovyScript. forkRepo()
366
366
then :
367
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
368
367
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
369
368
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
370
369
371
370
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
372
371
1 * getPipelineMock(" sh" )(' git config user.name user' )
373
- 1 * getPipelineMock(" sh" )(' git config hub.protocol https' )
374
- 1 * getPipelineMock(" sh" )(' hub fork --remote-name=origin' )
372
+ 1 * getPipelineMock(" sh" )(' gh repo fork --remote-name=origin' )
375
373
1 * getPipelineMock(" sh" )(' git remote -v' )
376
374
}
377
375
@@ -382,14 +380,12 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
382
380
when :
383
381
groovyScript. forkRepo(' credentialsId' )
384
382
then :
385
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
386
383
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
387
384
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
388
385
389
386
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
390
387
1 * getPipelineMock(" sh" )(' git config user.name user' )
391
- 1 * getPipelineMock(" sh" )(' git config hub.protocol https' )
392
- 1 * getPipelineMock(" sh" )(' hub fork --remote-name=origin' )
388
+ 1 * getPipelineMock(" sh" )(' gh repo fork --remote-name=origin' )
393
389
1 * getPipelineMock(" sh" )(' git remote -v' )
394
390
}
395
391
@@ -400,12 +396,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
400
396
when :
401
397
def result = groovyScript. createPR(' PR Title' )
402
398
then :
403
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
404
399
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
405
400
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
406
401
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
407
402
1 * getPipelineMock(" sh" )(' git config user.name user' )
408
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -m 'PR Title' -m '' -b 'main'" ]) >> ' shResult'
403
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -t 'PR Title' -b '' -B 'main'" ]) >> ' shResult'
409
404
}
410
405
411
406
def " [githubscm.groovy] createPR without Credentials and target branch" () {
@@ -415,12 +410,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
415
410
when :
416
411
def result = groovyScript. createPR(' PR Title' , ' PR body.' )
417
412
then :
418
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
419
413
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
420
414
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
421
415
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
422
416
1 * getPipelineMock(" sh" )(' git config user.name user' )
423
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -m 'PR Title' -m 'PR body.' -b 'main'" ]) >> ' shResult'
417
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -t 'PR Title' -b 'PR body.' -B 'main'" ]) >> ' shResult'
424
418
}
425
419
426
420
def " [githubscm.groovy] createPR without Credentials and target branch throwing exception" () {
@@ -430,12 +424,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
430
424
when :
431
425
def result = groovyScript. createPR(' PR Title' )
432
426
then :
433
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
434
427
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
435
428
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
436
429
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
437
430
1 * getPipelineMock(" sh" )(' git config user.name user' )
438
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -m 'PR Title' -m '' -b 'main'" ]) >> { throw new Exception (' error' ) }
431
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -t 'PR Title' -b '' -B 'main'" ]) >> { throw new Exception (' error' ) }
439
432
thrown(Exception )
440
433
}
441
434
@@ -446,12 +439,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
446
439
when :
447
440
def result = groovyScript. createPR(' PR Title' , ' PR body.' , ' targetBranch' , ' credentialsId' )
448
441
then :
449
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
450
442
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
451
443
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
452
444
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
453
445
1 * getPipelineMock(" sh" )(' git config user.name user' )
454
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -m 'PR Title' -m 'PR body.' -b 'targetBranch'" ]) >> ' shResult'
446
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -t 'PR Title' -b 'PR body.' -B 'targetBranch'" ]) >> ' shResult'
455
447
}
456
448
457
449
def " [githubscm.groovy] createPrAsDraft without body, Credentials and target branch" () {
@@ -461,12 +453,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
461
453
when :
462
454
def result = groovyScript. createPrAsDraft(' PR Title' )
463
455
then :
464
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
465
456
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
466
457
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
467
458
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
468
459
1 * getPipelineMock(" sh" )(' git config user.name user' )
469
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -d -m 'PR Title' -m '' -b 'main'" ]) >> ' shResult'
460
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -d -t 'PR Title' -b '' -B 'main'" ]) >> ' shResult'
470
461
}
471
462
472
463
def " [githubscm.groovy] createPrAsDraft without Credentials and target branch" () {
@@ -476,12 +467,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
476
467
when :
477
468
def result = groovyScript. createPrAsDraft(' PR Title' , ' PR body.' )
478
469
then :
479
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
480
470
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
481
471
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
482
472
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
483
473
1 * getPipelineMock(" sh" )(' git config user.name user' )
484
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -d -m 'PR Title' -m 'PR body.' -b 'main'" ]) >> ' shResult'
474
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -d -t 'PR Title' -b 'PR body.' -B 'main'" ]) >> ' shResult'
485
475
}
486
476
487
477
def " [githubscm.groovy] createPrAsDraft without Credentials and target branch throwing exception" () {
@@ -491,12 +481,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
491
481
when :
492
482
def result = groovyScript. createPrAsDraft(' PR Title' )
493
483
then :
494
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
495
484
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
496
485
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
497
486
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
498
487
1 * getPipelineMock(" sh" )(' git config user.name user' )
499
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -d -m 'PR Title' -m '' -b 'main'" ]) >> { throw new Exception (' draft error' ) }
488
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -d -t 'PR Title' -b '' -B 'main'" ]) >> { throw new Exception (' draft error' ) }
500
489
thrown(Exception )
501
490
}
502
491
@@ -507,12 +496,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
507
496
when :
508
497
def result = groovyScript. createPrAsDraft(' PR Title' , ' PR body.' , ' targetBranch' , ' credentialsId' )
509
498
then :
510
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
511
499
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
512
500
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
513
501
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
514
502
1 * getPipelineMock(" sh" )(' git config user.name user' )
515
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -d -m 'PR Title' -m 'PR body.' -b 'targetBranch'" ]) >> ' shResult'
503
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -d -t 'PR Title' -b 'PR body.' -B 'targetBranch'" ]) >> ' shResult'
516
504
}
517
505
518
506
def " [githubscm.groovy] createPRWithLabels with body, Credentials and target branch" () {
@@ -522,27 +510,25 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
522
510
when :
523
511
def result = groovyScript. createPRWithLabels(' PR Title' , ' PR body.' , ' targetBranch' , [' label1' , ' label2' ] as String [], ' credentialsId' )
524
512
then :
525
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
526
513
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
527
514
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
528
515
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
529
516
1 * getPipelineMock(" sh" )(' git config user.name user' )
530
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hub pull-request -m 'PR Title' -m 'PR body.' -b 'targetBranch' -l 'label1','label2'" ]) >> ' shResult'
517
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " gh pr create -t 'PR Title' -b 'PR body.' -B 'targetBranch' -l 'label1','label2'" ]) >> ' shResult'
531
518
}
532
519
533
- def " [githubscm.groovy] executeHub with credentials" () {
520
+ def " [githubscm.groovy] executeGHCli with credentials" () {
534
521
setup :
535
522
groovyScript. getBinding(). setVariable(" GITHUB_USER" , ' user' )
536
523
groovyScript. getBinding(). setVariable(" GITHUB_TOKEN" , ' password' )
537
524
when :
538
- def result = groovyScript. executeHub( ' hubCommand ' , ' credentialsId' )
525
+ def result = groovyScript. executeGHCli( ' command ' , ' credentialsId' )
539
526
then :
540
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
541
527
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
542
528
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
543
529
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
544
530
1 * getPipelineMock(" sh" )(' git config user.name user' )
545
- 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " hubCommand " ]) >> ' shResult'
531
+ 1 * getPipelineMock(" sh" )([' returnStdout' : true , ' script' : " command " ]) >> ' shResult'
546
532
}
547
533
548
534
def " [githubscm.groovy] mergePR without Credentials" () {
@@ -552,12 +538,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
552
538
when :
553
539
groovyScript. mergePR(' pullRequestLink' )
554
540
then :
555
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
556
541
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
557
542
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
558
543
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
559
544
1 * getPipelineMock(" sh" )(' git config user.name user' )
560
- 1 * getPipelineMock(" sh" )(' hub merge pullRequestLink' )
545
+ 1 * getPipelineMock(" sh" )(' gh pr merge --admin --rebase --delete-branch pullRequestLink' )
561
546
}
562
547
563
548
def " [githubscm.groovy] mergePR without Credentials throwing exception" () {
@@ -567,12 +552,11 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
567
552
when :
568
553
groovyScript. mergePR(' pullRequestLink' )
569
554
then :
570
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
571
555
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
572
556
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
573
557
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
574
558
1 * getPipelineMock(" sh" )(' git config user.name user' )
575
- 1 * getPipelineMock(" sh" )(' hub merge pullRequestLink' ) >> { throw new Exception (' hub error' ) }
559
+ 1 * getPipelineMock(" sh" )(' gh pr merge --admin --rebase --delete-branch pullRequestLink' ) >> { throw new Exception (' merge error' ) }
576
560
thrown(Exception )
577
561
}
578
562
@@ -583,12 +567,40 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
583
567
when :
584
568
groovyScript. mergePR(' pullRequestLink' , ' credentialsId' )
585
569
then :
586
- 1 * getPipelineMock(" sh" )(" rm -rf ~/.config/hub" )
587
570
1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
588
571
1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
589
572
1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
590
573
1 * getPipelineMock(" sh" )(' git config user.name user' )
591
- 1 * getPipelineMock(" sh" )(' hub merge pullRequestLink' )
574
+ 1 * getPipelineMock(" sh" )(' gh pr merge --admin --rebase --delete-branch pullRequestLink' )
575
+ }
576
+
577
+ def " [githubscm.groovy] approvePR without Credentials throwing exception" () {
578
+ setup :
579
+ groovyScript. getBinding(). setVariable(" GITHUB_USER" , ' user' )
580
+ groovyScript. getBinding(). setVariable(" GITHUB_TOKEN" , ' password' )
581
+ when :
582
+ groovyScript. approvePR(' pullRequestLink' )
583
+ then :
584
+ 1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' kie-ci' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
585
+ 1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
586
+ 1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
587
+ 1 * getPipelineMock(" sh" )(' git config user.name user' )
588
+ 1 * getPipelineMock(" sh" )(' gh pr review pullRequestLink --approve' ) >> { throw new Exception (' approve error' ) }
589
+ thrown(Exception )
590
+ }
591
+
592
+ def " [githubscm.groovy] approvePR with Credentials" () {
593
+ setup :
594
+ groovyScript. getBinding(). setVariable(" GITHUB_USER" , ' user' )
595
+ groovyScript. getBinding(). setVariable(" GITHUB_TOKEN" , ' password' )
596
+ when :
597
+ groovyScript. approvePR(' pullRequestLink' , ' credentialsId' )
598
+ then :
599
+ 1 * getPipelineMock(' usernamePassword.call' )([credentialsId : ' credentialsId' , usernameVariable : ' GITHUB_USER' , passwordVariable : ' GITHUB_TOKEN' ]) >> ' userNamePassword'
600
+ 1 * getPipelineMock(" withCredentials" )([' userNamePassword' ], _ as Closure )
601
+ 1 * getPipelineMock(
" sh" )(
' git config user.email [email protected] ' )
602
+ 1 * getPipelineMock(" sh" )(' git config user.name user' )
603
+ 1 * getPipelineMock(" sh" )(' gh pr review pullRequestLink --approve' )
592
604
}
593
605
594
606
def " [githubscm.groovy] tagRepository with buildTag" () {
@@ -1023,13 +1035,6 @@ class GithubScmSpec extends JenkinsPipelineSpecification {
1023
1035
result == ' * BXMSPROD -819 '
1024
1036
}
1025
1037
1026
- def "[githubscm.groovy] cleanHubAuth"() {
1027
- when:
1028
- groovyScript.cleanHubAuth()
1029
- then:
1030
- 1 * getPipelineMock("sh")("rm -rf ~/.config/hub")
1031
- }
1032
-
1033
1038
def "[githubscm.groovy] cleanWorkingTree"() {
1034
1039
when:
1035
1040
groovyScript.cleanWorkingTree()
0 commit comments