Skip to content

Commit

Permalink
fix: prevent workflow graph getting weird when requires contains dupl…
Browse files Browse the repository at this point in the history
…icates
  • Loading branch information
petey committed Oct 26, 2017
1 parent a5a7a4d commit c4f34a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/getWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ const calculateEdges = (jobs) => {
const dest = j;

if (Array.isArray(job.requires)) {
const specialTriggers = job.requires.filter(name => name.charAt(0) === '~');
const normalTriggers = job.requires.filter(name => name.charAt(0) !== '~');
const isJoin = normalTriggers.length > 1;
const specialTriggers = new Set(job.requires.filter(name => name.charAt(0) === '~'));
const normalTriggers = new Set(job.requires.filter(name => name.charAt(0) !== '~'));
const isJoin = normalTriggers.size > 1;

specialTriggers.forEach((src) => {
edges.push({ src: filterNodeName(src), dest });
});

normalTriggers.forEach((src) => {
const obj = { src: filterNodeName(src), dest };
const obj = { src, dest };

if (isJoin) {
obj.join = true;
Expand Down
21 changes: 21 additions & 0 deletions test/lib/getWorkflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ describe('getWorkflow', () => {
});
});

it('should dedupe requires', () => {
const result = getWorkflow({
jobs: {
foo: { requires: ['A', 'A', 'A'] },
A: {}
}
});

assert.deepEqual(result, {
nodes: [
{ name: '~pr' },
{ name: '~commit' },
{ name: 'foo' },
{ name: 'A' }
],
edges: [
{ src: 'A', dest: 'foo' }
]
});
});

it('should handle joins', () => {
const result = getWorkflow({
jobs: {
Expand Down

0 comments on commit c4f34a1

Please sign in to comment.