From 28393f582d470cef9a85b4fe67a65d4f0876004f Mon Sep 17 00:00:00 2001 From: Hiroki tktk Date: Sat, 9 Mar 2019 08:38:17 +0900 Subject: [PATCH] feat: Add _getCommitRefSha() (#17) --- index.js | 11 +++++++++++ test/index.test.js | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/index.js b/index.js index 6f5774e..6e30430 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/test/index.test.js b/test/index.test.js index 9f3820d..df30b03 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -46,6 +46,7 @@ describe('index test', () => { 'getPermissions', 'getOrgPermissions', 'getCommitSha', + 'getCommitRefSha', 'addPrComment', 'updateCommitStatus', 'getFile', @@ -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' };