Skip to content

Commit 5a87c53

Browse files
committed
feat: Grant access to private repo
1 parent 780269b commit 5a87c53

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class GithubScm extends Scm {
8282
* Constructor
8383
* @method constructor
8484
* @param {Object} options Configuration options
85+
* @param {Boolean} [options.privateRepo=false] Request 'repo' scope, which allows read/write access for public & private repos
8586
* @param {String} [options.gheHost=null] If using GitHub Enterprise, the host/port of the deployed instance
8687
* @param {String} [options.gheProtocol=https] If using GitHub Enterprise, the protocol to use
8788
* @param {Boolean} [options.https=false] Is the Screwdriver API running over HTTPS
@@ -96,6 +97,7 @@ class GithubScm extends Scm {
9697

9798
// Validate configuration
9899
this.config = joi.attempt(config, joi.object().keys({
100+
privateRepo: joi.boolean().optional().default(false),
99101
gheProtocol: joi.string().optional().default('https'),
100102
gheHost: joi.string().optional().description('GitHub Enterpise host'),
101103
https: joi.boolean().optional().default(false),
@@ -694,11 +696,12 @@ class GithubScm extends Scm {
694696
* @return {Promise}
695697
*/
696698
_getBellConfiguration() {
699+
const scope = ['admin:repo_hook', 'read:org', 'repo:status'];
697700
const bellConfig = {
698701
provider: 'github',
699702
clientId: this.config.oauthClientId,
700703
clientSecret: this.config.oauthClientSecret,
701-
scope: ['admin:repo_hook', 'read:org', 'repo:status'],
704+
scope: this.config.privateRepo === true ? scope.concat('repo') : scope,
702705
isSecure: this.config.https,
703706
forceHttps: this.config.https
704707
};

test/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,35 @@ jobs:
11871187
});
11881188
});
11891189
});
1190+
1191+
it('add repo scope to support private repo', () => {
1192+
scm = new GithubScm({
1193+
oauthClientId: 'abcdefg',
1194+
oauthClientSecret: 'hijklmno',
1195+
gheHost: 'github.screwdriver.cd',
1196+
secret: 'somesecret',
1197+
privateRepo: true
1198+
});
1199+
1200+
return scm.getBellConfiguration().then((config) => {
1201+
assert.deepEqual(config, {
1202+
clientId: 'abcdefg',
1203+
clientSecret: 'hijklmno',
1204+
config: {
1205+
uri: 'https://github.screwdriver.cd'
1206+
},
1207+
forceHttps: false,
1208+
isSecure: false,
1209+
provider: 'github',
1210+
scope: [
1211+
'admin:repo_hook',
1212+
'read:org',
1213+
'repo:status',
1214+
'repo'
1215+
]
1216+
});
1217+
});
1218+
});
11901219
});
11911220

11921221
describe('addWebhook', () => {

0 commit comments

Comments
 (0)