2021-03-08 18:12:59 +05:30
|
|
|
import { capitalize } from 'lodash';
|
|
|
|
import {
|
|
|
|
securityReportTypeEnumToReportType,
|
|
|
|
REPORT_FILE_TYPES,
|
|
|
|
} from 'ee_else_ce/vue_shared/security_reports/constants';
|
|
|
|
|
|
|
|
const addReportTypeIfExists = (acc, reportTypes, reportType, getName, downloadPath) => {
|
|
|
|
if (reportTypes && reportTypes.includes(reportType)) {
|
|
|
|
acc.push({
|
|
|
|
reportType,
|
|
|
|
name: getName(reportType),
|
|
|
|
path: downloadPath,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
export const extractSecurityReportArtifacts = (reportTypes, jobs) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
return jobs.reduce((acc, job) => {
|
|
|
|
const artifacts = job.artifacts?.nodes ?? [];
|
|
|
|
|
|
|
|
artifacts.forEach(({ downloadPath, fileType }) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
addReportTypeIfExists(
|
|
|
|
acc,
|
|
|
|
reportTypes,
|
|
|
|
securityReportTypeEnumToReportType[fileType],
|
|
|
|
() => job.name,
|
|
|
|
downloadPath,
|
|
|
|
);
|
|
|
|
|
|
|
|
addReportTypeIfExists(
|
|
|
|
acc,
|
|
|
|
reportTypes,
|
|
|
|
REPORT_FILE_TYPES[fileType],
|
|
|
|
(reportType) => `${job.name} ${capitalize(reportType)}`,
|
|
|
|
downloadPath,
|
|
|
|
);
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
};
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
export const extractSecurityReportArtifactsFromPipeline = (reportTypes, data) => {
|
|
|
|
const jobs = data.project?.pipeline?.jobs?.nodes ?? [];
|
|
|
|
return extractSecurityReportArtifacts(reportTypes, jobs);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const extractSecurityReportArtifactsFromMergeRequest = (reportTypes, data) => {
|
|
|
|
const jobs = data.project?.mergeRequest?.headPipeline?.jobs?.nodes ?? [];
|
|
|
|
return extractSecurityReportArtifacts(reportTypes, jobs);
|
|
|
|
};
|