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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import { reportToSentry } from '../utils';
2022-03-02 08:16:31 +05:30
import { EXPLICIT_NEEDS_PROPERTY, NEEDS_PROPERTY } from '../constants';
2021-04-29 21:17:54 +05:30
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) => {
2022-03-02 08:16:31 +05:30
if (job[prop]) {
return { ...job, [prop]: job[prop].nodes.map((item) => item[field] || '') };
}
return job;
2021-02-22 17:27:13 +05:30
});
};
2021-03-08 18:12:59 +05:30
const unwrapJobWithNeeds = (denodedJobArray) => {
2022-03-02 08:16:31 +05:30
const explicitNeedsUnwrapped = unwrapNodesWithName(denodedJobArray, EXPLICIT_NEEDS_PROPERTY);
return unwrapNodesWithName(explicitNeedsUnwrapped, NEEDS_PROPERTY);
2021-02-22 17:27:13 +05:30
};
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,
};