summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/security_reports/utils.js
blob: 827a87f9aafc81489db7c1b166343734b6d1f907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { securityReportTypeEnumToReportType } from './constants';

export const extractSecurityReportArtifacts = (reportTypes, data) => {
  const jobs = data.project?.mergeRequest?.headPipeline?.jobs?.nodes ?? [];

  return jobs.reduce((acc, job) => {
    const artifacts = job.artifacts?.nodes ?? [];

    artifacts.forEach(({ downloadPath, fileType }) => {
      const reportType = securityReportTypeEnumToReportType[fileType];
      if (reportType && reportTypes.includes(reportType)) {
        acc.push({
          name: job.name,
          reportType,
          path: downloadPath,
        });
      }
    });

    return acc;
  }, []);
};