Skip to content

Commit 43ed752

Browse files
authored
feat(2437): Add method to get read only flag(#30)
1 parent db3a64a commit 43ed752

File tree

4 files changed

+237
-268
lines changed

4 files changed

+237
-268
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ npm-debug.log
44
.DS_STORE
55
.*.swp
66
.nyc_output/
7+
package-lock.json

index.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,26 @@ class ScmRouter extends Scm {
395395
}
396396

397397
/**
398-
* Get an array of scm context (e.g. [github:github.com, gitlab:mygitlab])
398+
* Get an array of scm contexts (e.g. [github:github.com, gitlab:mygitlab])
399399
* @method _getScmContexts
400400
* @return {Array}
401401
*/
402402
_getScmContexts() {
403403
return Object.keys(this.scms);
404404
}
405405

406+
/**
407+
* Get an scm context given a hostname (e.g. github:github.com)
408+
* @method _getScmContext
409+
* @param {Object} config
410+
* @param {String} [config.hostname] Hostname for scmContext (e.g. github.com)
411+
* @return {String} Full scmContext (e.g. github:github.com)
412+
*/
413+
_getScmContext({ hostname }) {
414+
return Object.keys(this.scms).find(scmContext =>
415+
scmContext.split(':')[1] === hostname);
416+
}
417+
406418
/**
407419
* Determine a scm module can handle the received webhook
408420
* @method _canHandleWebhook
@@ -427,6 +439,21 @@ class ScmRouter extends Scm {
427439
return this.scms[config.scmContext].getDisplayName();
428440
}
429441

442+
/**
443+
* Get read only config
444+
* @method getReadOnlyInfo
445+
* @param {Object} config Configuration
446+
* @param {String} config.scmContext Name of scm context
447+
* @return {Object} Read only config of scmContext (e.g.: {
448+
* "enabled": true,
449+
* "username": 'headless-user',
450+
* "accessToken": 'token'
451+
* })
452+
*/
453+
getReadOnlyInfo(config) {
454+
return this.scms[config.scmContext].getReadOnlyInfo();
455+
}
456+
430457
/**
431458
* Get branch info of scmContext
432459
* @method _getBranchList

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"sinon": "^2.3.4"
4545
},
4646
"dependencies": {
47-
"async": "^2.6.1",
4847
"@hapi/hoek": "^9.0.4",
48+
"async": "^2.6.3",
4949
"screwdriver-logger": "^1.0.0",
50-
"screwdriver-scm-base": "^7.0.0"
50+
"screwdriver-scm-base": "^7.1.3"
5151
},
5252
"release": {
5353
"debug": false,

0 commit comments

Comments
 (0)