Skip to content

Commit

Permalink
feat(1082): Add getBranchList function (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichi10 authored and tkyi committed Jun 8, 2018
1 parent 93d4b01 commit 391ec4f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ class ScmRouter extends Scm {
getDisplayName(config) {
return this.scms[config.scmContext].getDisplayName();
}

/**
* Get branch info of scmContext
* @method _getBranchList
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
* @return {String} branch info of scmContext
*/
_getBranchList(config) {
return this.chooseScm(config).then(scm => scm.getBranchList(config));
}
}

module.exports = ScmRouter;
22 changes: 21 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ describe('index test', () => {
'getFile',
'getChangedFiles',
'getOpenedPRs',
'getPrInfo'
'getPrInfo',
'getBranchList'
].forEach((method) => {
mock[method] = sinon.stub().resolves(plugin);
});
Expand Down Expand Up @@ -900,4 +901,23 @@ describe('index test', () => {
assert.calledOnce(exampleScm.getDisplayName);
});
});

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

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

return scm._getBranchList(config)
.then((result) => {
assert.strictEqual(result, 'example');
assert.notCalled(scmGithub.getBranchList);
assert.notCalled(scmGitlab.getBranchList);
assert.calledOnce(exampleScm.getBranchList);
assert.calledWith(exampleScm.getBranchList, config);
});
});
});
});

0 comments on commit 391ec4f

Please sign in to comment.