debian-mirror-gitlab/app/assets/javascripts/pipelines/components/unwrapping_utils.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import { reportToSentry } from '../utils';
2021-03-08 18:12:59 +05:30
const unwrapGroups = (stages) => {
2021-04-29 21:17:54 +05:30
return stages.map((stage, idx) => {
2021-02-22 17:27:13 +05:30
const {
groups: { nodes: groups },
} = stage;
2021-04-29 21:17:54 +05:30
/*
Being peformance conscious here means we don't want to spread and copy the
group value just to add one parameter.
*/
/* eslint-disable no-param-reassign */
const groupsWithStageName = groups.map((group) => {
group.stageName = stage.name;
return group;
});
/* eslint-enable no-param-reassign */
return { node: { ...stage, groups: groupsWithStageName }, lookup: { stageIdx: idx } };
2021-02-22 17:27:13 +05:30
});
};
const unwrapNodesWithName = (jobArray, prop, field = 'name') => {
2021-04-29 21:17:54 +05:30
if (jobArray.length < 1) {
reportToSentry('unwrapping_utils', 'undefined_job_hunt, array empty from backend');
}
2021-03-08 18:12:59 +05:30
return jobArray.map((job) => {
2021-04-29 21:17:54 +05:30
return { ...job, [prop]: job[prop].nodes.map((item) => item[field] || '') };
2021-02-22 17:27:13 +05:30
});
};
2021-03-08 18:12:59 +05:30
const unwrapJobWithNeeds = (denodedJobArray) => {
2021-02-22 17:27:13 +05:30
return unwrapNodesWithName(denodedJobArray, 'needs');
};
2021-04-29 21:17:54 +05:30
const unwrapStagesWithNeedsAndLookup = (denodedStages) => {
2021-02-22 17:27:13 +05:30
const unwrappedNestedGroups = unwrapGroups(denodedStages);
2021-04-29 21:17:54 +05:30
const lookupMap = {};
const nodes = unwrappedNestedGroups.map(({ node, lookup }) => {
2021-02-22 17:27:13 +05:30
const { groups } = node;
2021-04-29 21:17:54 +05:30
const groupsWithJobs = groups.map((group, idx) => {
2021-02-22 17:27:13 +05:30
const jobs = unwrapJobWithNeeds(group.jobs.nodes);
2021-04-29 21:17:54 +05:30
lookupMap[group.name] = { ...lookup, groupIdx: idx };
2021-02-22 17:27:13 +05:30
return { ...group, jobs };
});
return { ...node, groups: groupsWithJobs };
});
2021-04-29 21:17:54 +05:30
return { stages: nodes, lookup: lookupMap };
};
const unwrapStagesWithNeeds = (denodedStages) => {
return unwrapStagesWithNeedsAndLookup(denodedStages).stages;
2021-02-22 17:27:13 +05:30
};
2021-04-29 21:17:54 +05:30
export {
unwrapGroups,
unwrapJobWithNeeds,
unwrapNodesWithName,
unwrapStagesWithNeeds,
unwrapStagesWithNeedsAndLookup,
};