Skip to content

Commit

Permalink
feat(1415): Add handling of events mapping in scm (#27)
Browse files Browse the repository at this point in the history
* feat(1415): Add handling of events mapping in scm

* fix(1415): Minor fixes
  • Loading branch information
supra08 authored Oct 12, 2020
1 parent dd9af13 commit fa1f394
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ class ScmRouter extends Scm {
return this.chooseScm(config).then(scm => scm.addWebhook(config));
}

/**
* Get the webhook events mapping of screwdriver events and scm events
* @method _getWebhookEventsMapping
* @return {Object} Returns a mapping of the events
*/
_getWebhookEventsMapping(config) {
return this.scms[config.scmContext].getWebhookEventsMapping();
}

/**
* Returns whether auto deploy key generation is enabled on or not
* @method autoDeployKeyGenerationEnabled
Expand Down
20 changes: 19 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('index test', () => {
'getOpenedPRs',
'getPrInfo',
'getBranchList',
'openPr'
'openPr',
'getWebhookEventsMapping'
].forEach((method) => {
mock[method] = sinon.stub().resolves(plugin);
});
Expand All @@ -66,6 +67,7 @@ describe('index test', () => {
mock.getScmContexts = sinon.stub().returns([`${plugin}.context`]);
mock.getDisplayName = sinon.stub().returns(plugin);
mock.autoDeployKeyGenerationEnabled = sinon.stub().returns(plugin);
mock.getWebhookEventsMapping = sinon.stub().returns({ pr: 'pull_request' });

return mock;
};
Expand Down Expand Up @@ -1001,6 +1003,22 @@ describe('index test', () => {
});
});

describe('getWebhookEventsMapping', () => {
const config = { scmContext: 'example.context' };

it('call origin getWebhookEventsMapping', () => {
const scmGithub = scm.scms['github.context'];
const exampleScm = scm.scms['example.context'];
const scmGitlab = scm.scms['gitlab.context'];
const result = scm._getWebhookEventsMapping(config);

assert.deepEqual(result, { pr: 'pull_request' });
assert.notCalled(scmGithub.getWebhookEventsMapping);
assert.notCalled(scmGitlab.getWebhookEventsMapping);
assert.calledOnce(exampleScm.getWebhookEventsMapping);
});
});

describe('_getBranchList', () => {
const config = { scmContext: 'example.context' };

Expand Down

0 comments on commit fa1f394

Please sign in to comment.