summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/jobs/utils.js
blob: c8414d44d141208ed401c1a1a016d1e098e0b2b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
    We get the failure and failure summary from Rails which has
    a summary failure log. Here we combine that data with the data
    from GraphQL to display the log.

    failedJobs is from GraphQL
    failedJobsSummary is from Rails
  */

export const prepareFailedJobs = (failedJobs = [], failedJobsSummary = []) => {
  const combinedJobs = [];

  if (failedJobs.length > 0 && failedJobsSummary.length > 0) {
    failedJobs.forEach((failedJob) => {
      const foundJob = failedJobsSummary.find(
        (failedJobSummary) => failedJob.normalizedId === failedJobSummary.id,
      );

      if (foundJob) {
        combinedJobs.push({
          ...failedJob,
          failure: foundJob?.failure,
          failureSummary: foundJob?.failure_summary,
          // this field is needed for the slot row-details
          // on the failed_jobs_table.vue component
          _showDetails: true,
        });
      }
    });
  }

  return combinedJobs;
};