@@ -401,23 +401,50 @@ test('Throw SemanticReleaseError for invalid repositoryUrl', async (t) => {
401
401
t . is ( error . code , 'EINVALIDGITHUBURL' ) ;
402
402
} ) ;
403
403
404
- test . serial ( "Throw SemanticReleaseError if token doesn't have the push permission on the repository" , async ( t ) => {
405
- const owner = 'test_user' ;
406
- const repo = 'test_repo' ;
407
- const env = { GH_TOKEN : 'github_token' } ;
408
- const github = authenticate ( env )
409
- . get ( `/repos/${ owner } /${ repo } ` )
410
- . reply ( 200 , { permissions : { push : false } } ) ;
404
+ test . serial (
405
+ "Throw SemanticReleaseError if token doesn't have the push permission on the repository and it's not a Github installation token" ,
406
+ async ( t ) => {
407
+ const owner = 'test_user' ;
408
+ const repo = 'test_repo' ;
409
+ const env = { GH_TOKEN : 'github_token' } ;
410
+ const github = authenticate ( env )
411
+ . get ( `/repos/${ owner } /${ repo } ` )
412
+ . reply ( 200 , { permissions : { push : false } } )
413
+ . head ( '/installation/repositories' )
414
+ . query ( { per_page : 1 } )
415
+ . reply ( 403 ) ;
411
416
412
- const [ error , ...errors ] = await t . throwsAsync (
413
- verify ( { } , { env, options : { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } , logger : t . context . logger } )
414
- ) ;
417
+ const [ error , ...errors ] = await t . throwsAsync (
418
+ verify ( { } , { env, options : { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } , logger : t . context . logger } )
419
+ ) ;
415
420
416
- t . is ( errors . length , 0 ) ;
417
- t . is ( error . name , 'SemanticReleaseError' ) ;
418
- t . is ( error . code , 'EGHNOPERMISSION' ) ;
419
- t . true ( github . isDone ( ) ) ;
420
- } ) ;
421
+ t . is ( errors . length , 0 ) ;
422
+ t . is ( error . name , 'SemanticReleaseError' ) ;
423
+ t . is ( error . code , 'EGHNOPERMISSION' ) ;
424
+ t . true ( github . isDone ( ) ) ;
425
+ }
426
+ ) ;
427
+
428
+ test . serial (
429
+ "Do not throw SemanticReleaseError if token doesn't have the push permission but it is a Github installation token" ,
430
+ async ( t ) => {
431
+ const owner = 'test_user' ;
432
+ const repo = 'test_repo' ;
433
+ const env = { GH_TOKEN : 'github_token' } ;
434
+ const github = authenticate ( env )
435
+ . get ( `/repos/${ owner } /${ repo } ` )
436
+ . reply ( 200 , { permissions : { push : false } } )
437
+ . head ( '/installation/repositories' )
438
+ . query ( { per_page : 1 } )
439
+ . reply ( 200 ) ;
440
+
441
+ await t . notThrowsAsync (
442
+ verify ( { } , { env, options : { repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } , logger : t . context . logger } )
443
+ ) ;
444
+
445
+ t . true ( github . isDone ( ) ) ;
446
+ }
447
+ ) ;
421
448
422
449
test . serial ( "Throw SemanticReleaseError if the repository doesn't exist" , async ( t ) => {
423
450
const owner = 'test_user' ;
0 commit comments