diff options
Diffstat (limited to 'app/assets/javascripts/pipelines/utils.js')
-rw-r--r-- | app/assets/javascripts/pipelines/utils.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/assets/javascripts/pipelines/utils.js b/app/assets/javascripts/pipelines/utils.js index 800a363cada..02a9e5b7fc6 100644 --- a/app/assets/javascripts/pipelines/utils.js +++ b/app/assets/javascripts/pipelines/utils.js @@ -39,7 +39,13 @@ export const generateJobNeedsDict = (jobs = {}) => { } return jobs[jobName].needs - .map((job) => { + .reduce((needsAcc, job) => { + // It's possible that a needs refer to an optional job + // that is not defined in which case we don't add that entry + if (!jobs[job]) { + return needsAcc; + } + // If we already have the needs of a job in the accumulator, // then we use the memoized data instead of the recursive call // to save some performance. @@ -50,11 +56,11 @@ export const generateJobNeedsDict = (jobs = {}) => { // to the list of `needs` to ensure we can properly reference it. const group = jobs[job]; if (group.size > 1) { - return [job, group.name, newNeeds]; + return [...needsAcc, job, group.name, newNeeds]; } - return [job, newNeeds]; - }) + return [...needsAcc, job, newNeeds]; + }, []) .flat(Infinity); }; |