Skip to content

Commit 28393f5

Browse files
tk3fftktkyi
authored andcommitted
feat: Add _getCommitRefSha() (#17)
1 parent f780c6f commit 28393f5

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
@@ -261,6 +261,17 @@ class ScmRouter extends Scm {
261261
return this.chooseScm(config).then(scm => scm.getCommitSha(config));
262262
}
263263

264+
/**
265+
* Get a commit sha from a reference
266+
* @method _getCommitRefSha
267+
* @param {Object} config Configuration
268+
* @param {String} config.scmContext Name of scm context
269+
* @return {Promise}
270+
*/
271+
_getCommitRefSha(config) {
272+
return this.chooseScm(config).then(scm => scm.getCommitRefSha(config));
273+
}
274+
264275
/**
265276
* Add a comment on a pull request
266277
* @method _addPrComment

test/index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('index test', () => {
4646
'getPermissions',
4747
'getOrgPermissions',
4848
'getCommitSha',
49+
'getCommitRefSha',
4950
'addPrComment',
5051
'updateCommitStatus',
5152
'getFile',
@@ -731,6 +732,25 @@ describe('index test', () => {
731732
});
732733
});
733734

735+
describe('_getCommitRefSha', () => {
736+
const config = { scmContext: 'example.context' };
737+
738+
it('call origin getCommitRefSha', () => {
739+
const scmGithub = scm.scms['github.context'];
740+
const exampleScm = scm.scms['example.context'];
741+
const scmGitlab = scm.scms['gitlab.context'];
742+
743+
return scm._getCommitRefSha(config)
744+
.then((result) => {
745+
assert.strictEqual(result, 'example');
746+
assert.notCalled(scmGithub.getCommitRefSha);
747+
assert.notCalled(scmGitlab.getCommitRefSha);
748+
assert.calledOnce(exampleScm.getCommitRefSha);
749+
assert.calledWith(exampleScm.getCommitRefSha, config);
750+
});
751+
});
752+
});
753+
734754
describe('_addPrComment', () => {
735755
const config = { scmContext: 'example.context' };
736756

0 commit comments

Comments
 (0)