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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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,
});
}
};
const extractSecurityReportArtifacts = (reportTypes, jobs) => {
return jobs.reduce((acc, job) => {
const artifacts = job.artifacts?.nodes ?? [];
artifacts.forEach(({ downloadPath, fileType }) => {
addReportTypeIfExists(
acc,
reportTypes,
securityReportTypeEnumToReportType[fileType],
() => job.name,
downloadPath,
);
addReportTypeIfExists(
acc,
reportTypes,
REPORT_FILE_TYPES[fileType],
(reportType) => `${job.name} ${capitalize(reportType)}`,
downloadPath,
);
});
return acc;
}, []);
};
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);
};
|