Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(1082):[5] Check the trigger does match the regex or not #12

Merged
merged 3 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/getNextJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ const getNextJobs = (workflowGraph, config) => {
}

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

if (edgeSrcBranch) {
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']);
});
});