Skip to content

Commit

Permalink
feat(1082): Check if the trigger matches the branch regex or not (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumada626 authored and tkyi committed Jun 8, 2018
1 parent f963c63 commit 2c065c6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/getNextJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ const getNextJobs = (workflowGraph, config) => {
}

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

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

if (triggerBranch) {
if (triggerBranch[1].match(edgeSrcBranch[1])) {
jobs.add(edge.dest);
}
}
} else if (edge.src === config.trigger) {
// Make PR jobs PR-$num:$cloneJob (not sure how to better handle multiple PR jobs)
jobs.add(config.trigger === '~pr' ? `PR-${config.prNum}:${edge.dest}` : edge.dest);
}
Expand Down
20 changes: 20 additions & 0 deletions test/lib/getNextJobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,25 @@ describe('getNextJobs', () => {
['b', 'c', 'd']);
// trigger one after job "b"
assert.deepEqual(getNextJobs(parallelWorkflow, { trigger: 'b' }), ['e']);

const specificBranchWorkflow = {
edges: [
{ src: '~commit', dest: 'a' },
{ src: '~commit:foo', dest: 'b' },
{ src: '~commit:/foo-/', dest: 'c' },
{ src: '~commit:/^bar-.*$/', dest: 'd' }
]
};

// trigger own pipeline commit
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~commit' }), ['a']);
// trigger "foo" branch commit
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~commit:foo' }), ['b']);
// trigger "foo-bar-dev" branch commit
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~commit:foo-bar-dev' }),
['c']);
// trigger "bar-foo-prod" branch commit
assert.deepEqual(getNextJobs(specificBranchWorkflow, { trigger: '~commit:bar-foo-prod' }),
['c', 'd']);
});
});

0 comments on commit 2c065c6

Please sign in to comment.