Skip to content

Commit

Permalink
add backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
d2lam committed Oct 21, 2019
1 parent 10f8a28 commit 5861f58
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/getWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ const buildExternalNodes = async (root, children, nodes, triggerFactory) => {
const calculateNodes = async (jobs, triggerFactory, pipelineId) => {
const nodes = new Set(['~pr', '~commit']);

// for backward compatibility
if (!triggerFactory) {
Object.keys(jobs).forEach((name) => {
nodes.add(name);
if (Array.isArray(jobs[name].requires)) {
jobs[name].requires.forEach(n => nodes.add(filterNodeName(n)));
}
});

return [...nodes].map(name => ({ name }));
}

await Promise.all(Object.keys(jobs).map(async (jobName) => {
nodes.add(jobName);

Expand Down Expand Up @@ -98,6 +110,37 @@ const buildExternalEdges = async (root, children, edges, triggerFactory) => {
const calculateEdges = async (jobs, triggerFactory, pipelineId) => {
const edges = [];

if (!triggerFactory) {
Object.keys(jobs).forEach((j) => {
const job = jobs[j];
const dest = j;

if (Array.isArray(job.requires)) {
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, dest };

if (isJoin) {
obj.join = true;
}

edges.push(obj);
});
}
});

return edges;
}

await Promise.all(Object.keys(jobs).map(async (jobName) => {
const job = jobs[jobName];

Expand Down

0 comments on commit 5861f58

Please sign in to comment.