Skip to content

Commit

Permalink
feat(1922): Add openPr method. BREAKING CHANGE: pull in new scm-base (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
klu909 authored May 20, 2020
1 parent 778f877 commit f8eae1e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
artifacts/
features/*.feature
package-lock.json
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ class ScmRouter extends Scm {
_getBranchList(config) {
return this.chooseScm(config).then(scm => scm.getBranchList(config));
}

/**
* Open a pull request on the repository
* @method _openPr
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
* @return {Object} Created PR
*/
_openPr(config) {
return this.chooseScm(config).then(scm => scm.openPr(config));
}
}

module.exports = ScmRouter;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"async": "^2.6.1",
"screwdriver-scm-base": "^5.0.0",
"screwdriver-scm-base": "^6.0.0",
"screwdriver-logger": "^1.0.0"
},
"release": {
Expand Down
35 changes: 34 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('index test', () => {
'getChangedFiles',
'getOpenedPRs',
'getPrInfo',
'getBranchList'
'getBranchList',
'openPr'
].forEach((method) => {
mock[method] = sinon.stub().resolves(plugin);
});
Expand Down Expand Up @@ -980,4 +981,36 @@ describe('index test', () => {
});
});
});

describe('_openPr', () => {
const config = {
checkoutUrl: 'git@github.com:screwdriver-cd/scm-github.git#master',
token: 'thisisatoken',
files: [{
name: 'file.txt',
content: 'content'
}, {
name: 'file2.txt',
content: 'content'
}],
title: 'update file',
message: 'update file',
scmContext: 'example.context'
};

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

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

0 comments on commit f8eae1e

Please sign in to comment.