Skip to content

Commit

Permalink
feat(1082): Fix to enable branch specific PR trigger (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
yokawara authored and tkyi committed Jul 19, 2018
1 parent 2c065c6 commit a652efe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lib/getNextJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ const getNextJobs = (workflowGraph, config) => {
}

workflowGraph.edges.forEach((edge) => {
// Check if edge src is specific branch commit with regexp
const edgeSrcBranchRegExp = new RegExp('^~commit:/(.+)/$');
// Check if edge src is specific branch commit or pr with regexp
const edgeSrcBranchRegExp = new RegExp('^~(pr|commit):/(.+)/$');
const edgeSrcBranch = edge.src.match(edgeSrcBranchRegExp);

if (edgeSrcBranch) {
// Check if trigger is specific branch commit
const triggerBranchRegExp = new RegExp('^~commit:(.+)$');
// Check if trigger is specific branch commit or pr
const triggerBranchRegExp = new RegExp('^~(pr|commit):(.+)$');
const triggerBranch = config.trigger.match(triggerBranchRegExp);

if (triggerBranch) {
if (triggerBranch[1].match(edgeSrcBranch[1])) {
// Check whether job types of trigger and edge src match
if (triggerBranch && triggerBranch[1] === edgeSrcBranch[1]) {
// Check if trigger branch and edge src branch regex match
if (triggerBranch[2].match(edgeSrcBranch[2])) {
jobs.add(edge.dest);
}
}
Expand Down
14 changes: 13 additions & 1 deletion test/lib/getNextJobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe('getNextJobs', () => {
{ src: '~commit', dest: 'a' },
{ src: '~commit:foo', dest: 'b' },
{ src: '~commit:/foo-/', dest: 'c' },
{ src: '~commit:/^bar-.*$/', dest: 'd' }
{ src: '~commit:/^bar-.*$/', dest: 'd' },
{ src: '~pr:foo', dest: 'e' },
{ src: '~pr:/foo-/', dest: 'f' },
{ src: '~pr:/^bar-.*$/', dest: 'g' }
]
};

Expand All @@ -66,5 +69,14 @@ describe('getNextJobs', () => {
// trigger "bar-foo-prod" branch commit
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~commit:bar-foo-prod' }),
['c', 'd']);
// trigger by a pull request on "foo" branch
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~pr:foo', prNum: '123' }),
['e']);
// trigger by a pull request on "foo-bar-dev" branch
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~pr:foo-bar-dev',
prNum: '123' }), ['f']);
// trigger by a pull request on "bar-foo-prod" branch
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~pr:bar-foo-prod',
prNum: '123' }), ['f', 'g']);
});
});

0 comments on commit a652efe

Please sign in to comment.