Skip to content

Commit c135512

Browse files
authored
feat(scm-router): Add addDeployKey method (#23)
1 parent f8eae1e commit c135512

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ class ScmRouter extends Scm {
154154
return this.chooseScm(config).then(scm => scm.addWebhook(config));
155155
}
156156

157+
/**
158+
* Parse the url for a repo for the specific source control
159+
* @method _addDeployKey
160+
* @param {Object} config Configuration
161+
* @param {String} config.scmContext Name of scm context
162+
* @return {Promise}
163+
*/
164+
_addDeployKey(config) {
165+
return this.chooseScm(config).then(scm => scm.addDeployKey(config));
166+
}
167+
157168
/**
158169
* Parse the url for a repo for the specific source control
159170
* @method _parseUrl

test/index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('index test', () => {
3737
'dummyFunction',
3838
'dummyRejectFunction',
3939
'addWebhook',
40+
'addDeployKey',
4041
'parseUrl',
4142
'parseHook',
4243
'getCheckoutCommand',
@@ -561,6 +562,25 @@ describe('index test', () => {
561562
});
562563
});
563564

565+
describe('_addDeployKey', () => {
566+
const config = { scmContext: 'example.context' };
567+
568+
it('call origin addDeployKey', () => {
569+
const scmGithub = scm.scms['github.context'];
570+
const exampleScm = scm.scms['example.context'];
571+
const scmGitlab = scm.scms['gitlab.context'];
572+
573+
return scm._addDeployKey(config)
574+
.then((result) => {
575+
assert.strictEqual(result, 'example');
576+
assert.notCalled(scmGithub.addDeployKey);
577+
assert.notCalled(scmGitlab.addDeployKey);
578+
assert.calledOnce(exampleScm.addDeployKey);
579+
assert.calledWith(exampleScm.addDeployKey, config);
580+
});
581+
});
582+
});
583+
564584
describe('_parseUrl', () => {
565585
const config = { scmContext: 'example.context' };
566586

0 commit comments

Comments
 (0)