Skip to content

Commit

Permalink
feat: Add _getCommitRefSha() (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tk3fftk authored and tkyi committed Mar 8, 2019
1 parent f780c6f commit 28393f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ class ScmRouter extends Scm {
return this.chooseScm(config).then(scm => scm.getCommitSha(config));
}

/**
* Get a commit sha from a reference
* @method _getCommitRefSha
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
* @return {Promise}
*/
_getCommitRefSha(config) {
return this.chooseScm(config).then(scm => scm.getCommitRefSha(config));
}

/**
* Add a comment on a pull request
* @method _addPrComment
Expand Down
20 changes: 20 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('index test', () => {
'getPermissions',
'getOrgPermissions',
'getCommitSha',
'getCommitRefSha',
'addPrComment',
'updateCommitStatus',
'getFile',
Expand Down Expand Up @@ -731,6 +732,25 @@ describe('index test', () => {
});
});

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

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

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

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

Expand Down

0 comments on commit 28393f5

Please sign in to comment.