Skip to content

Commit 9425c23

Browse files
committed
feat(911): Add getChangedFiles method
1 parent bf7f70d commit 9425c23

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install screwdriver-scm-router
1717

1818
### Interface
1919

20-
It will initialize any routers specified in the [default.yaml](https://github.com/screwdriver-cd/screwdriver/blob/master/config/default.yaml#L123-L156) under the `scms` keyword.
20+
It will initialize any routers specified in the [default.yaml](https://github.com/screwdriver-cd/screwdriver/blob/master/config/default.yaml#L147-L185) under the `scms` keyword.
2121

2222
**Example scm yaml section:**
2323
```

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ScmRouter extends Scm {
3232
throw new Error('No scm config passed in.');
3333
}
3434

35-
const options = hoek.applyToDefaults({ displayName }, scm.config); // Add displayName to scm options
35+
const options = hoek.applyToDefaults({ displayName }, scm.config); // Add displayName to scm options
3636

3737
this.loadPlugin(scm.plugin, options);
3838
});
@@ -274,6 +274,17 @@ class ScmRouter extends Scm {
274274
return this.chooseScm(config).then(scm => scm.getFile(config));
275275
}
276276

277+
/**
278+
* Fetch changed files
279+
* @method _getChangedFiles
280+
* @param {Object} config Configuration
281+
* @param {String} config.scmContext Name of scm context
282+
* @return {Promise} Changed files for scmContext
283+
*/
284+
_getChangedFiles(config) {
285+
return this.chooseScm(config).then(scm => scm.getChangedFiles(config));
286+
}
287+
277288
/**
278289
* Get list of objects which consists of opened PR names and its ref
279290
* @method _getOpenedPRs

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
],
3434
"devDependencies": {
3535
"chai": "^3.5.0",
36-
"eslint": "^3.9.1",
37-
"eslint-config-screwdriver": "^2.0.9",
38-
"hoek": "^4.1.1",
36+
"eslint": "^4.19.1",
37+
"eslint-config-screwdriver": "^3.0.0",
38+
"hoek": "^5.0.3",
3939
"jenkins-mocha": "^4.0.0",
4040
"mockery": "^2.0.0",
4141
"sinon": "^2.3.4"

screwdriver.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
publish:
1212
requires: [main]
13-
template: screwdriver-cd/semantic-release
13+
template: screwdriver-cd/semantic-release
1414
secrets:
1515
# Publishing to NPM
1616
- NPM_TOKEN

test/index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('index test', () => {
4747
'getCommitSha',
4848
'updateCommitStatus',
4949
'getFile',
50+
'getChangedFiles',
5051
'getOpenedPRs',
5152
'getPrInfo'
5253
].forEach((method) => {
@@ -746,6 +747,25 @@ describe('index test', () => {
746747
});
747748
});
748749

750+
describe('_getChangedFiles', () => {
751+
const config = { scmContext: 'example.context' };
752+
753+
it('call origin getChangedFiles', () => {
754+
const scmGithub = scm.scms['github.context'];
755+
const exampleScm = scm.scms['example.context'];
756+
const scmGitlab = scm.scms['gitlab.context'];
757+
758+
return scm._getChangedFiles(config)
759+
.then((result) => {
760+
assert.strictEqual(result, 'example');
761+
assert.notCalled(scmGithub.getChangedFiles);
762+
assert.notCalled(scmGitlab.getChangedFiles);
763+
assert.calledOnce(exampleScm.getChangedFiles);
764+
assert.calledWith(exampleScm.getChangedFiles, config);
765+
});
766+
});
767+
});
768+
749769
describe('_getOpenedPRs', () => {
750770
const config = { scmContext: 'example.context' };
751771

0 commit comments

Comments
 (0)