Skip to content

Commit f8eae1e

Browse files
authored
feat(1922): Add openPr method. BREAKING CHANGE: pull in new scm-base (#21)
1 parent 778f877 commit f8eae1e

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
artifacts/
33
features/*.feature
4+
package-lock.json

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ class ScmRouter extends Scm {
406406
_getBranchList(config) {
407407
return this.chooseScm(config).then(scm => scm.getBranchList(config));
408408
}
409+
410+
/**
411+
* Open a pull request on the repository
412+
* @method _openPr
413+
* @param {Object} config Configuration
414+
* @param {String} config.scmContext Name of scm context
415+
* @return {Object} Created PR
416+
*/
417+
_openPr(config) {
418+
return this.chooseScm(config).then(scm => scm.openPr(config));
419+
}
409420
}
410421

411422
module.exports = ScmRouter;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"dependencies": {
4545
"async": "^2.6.1",
46-
"screwdriver-scm-base": "^5.0.0",
46+
"screwdriver-scm-base": "^6.0.0",
4747
"screwdriver-logger": "^1.0.0"
4848
},
4949
"release": {

test/index.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ describe('index test', () => {
5353
'getChangedFiles',
5454
'getOpenedPRs',
5555
'getPrInfo',
56-
'getBranchList'
56+
'getBranchList',
57+
'openPr'
5758
].forEach((method) => {
5859
mock[method] = sinon.stub().resolves(plugin);
5960
});
@@ -980,4 +981,36 @@ describe('index test', () => {
980981
});
981982
});
982983
});
984+
985+
describe('_openPr', () => {
986+
const config = {
987+
checkoutUrl: 'git@github.com:screwdriver-cd/scm-github.git#master',
988+
token: 'thisisatoken',
989+
files: [{
990+
name: 'file.txt',
991+
content: 'content'
992+
}, {
993+
name: 'file2.txt',
994+
content: 'content'
995+
}],
996+
title: 'update file',
997+
message: 'update file',
998+
scmContext: 'example.context'
999+
};
1000+
1001+
it('call origin openPr', () => {
1002+
const scmGithub = scm.scms['github.context'];
1003+
const exampleScm = scm.scms['example.context'];
1004+
const scmGitlab = scm.scms['gitlab.context'];
1005+
1006+
return scm._openPr(config)
1007+
.then((result) => {
1008+
assert.strictEqual(result, 'example');
1009+
assert.notCalled(scmGithub.openPr);
1010+
assert.notCalled(scmGitlab.openPr);
1011+
assert.calledOnce(exampleScm.openPr);
1012+
assert.calledWith(exampleScm.openPr, config);
1013+
});
1014+
});
1015+
});
9831016
});

0 commit comments

Comments
 (0)