Commit e6dc23df authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'pipeline-fn-cleanup' into 'master'

Remove unwrapArrayOfJobs function

See merge request gitlab-org/gitlab!50944
parents ff86a2e8 4111bddf
......@@ -6,7 +6,6 @@ import JobPill from './job_pill.vue';
import StagePill from './stage_pill.vue';
import { generateLinksData } from './drawing_utils';
import { parseData } from '../parsing_utils';
import { unwrapArrayOfJobs } from '../unwrapping_utils';
import { DRAW_FAILURE, DEFAULT, INVALID_CI_CONFIG, EMPTY_PIPELINE_DATA } from '../../constants';
import { createJobsHash, generateJobNeedsDict } from '../../utils';
import { CI_CONFIG_STATUS_INVALID } from '~/pipeline_editor/constants';
......@@ -136,7 +135,7 @@ export default {
methods: {
prepareLinkData() {
try {
const arrayOfJobs = unwrapArrayOfJobs(this.pipelineStages);
const arrayOfJobs = this.pipelineStages.flatMap(({ groups }) => groups);
const parsedData = parseData(arrayOfJobs);
this.links = generateLinksData(parsedData, this.$options.CONTAINER_ID);
} catch {
......
/**
* This function takes the stages and add the stage name
* at the group level as `category` to have an easier
* implementation while constructions nodes with D3
* @param {Array} stages
* @returns {Array} - Array of stages with stage name at the group level as `category`
*/
export const unwrapArrayOfJobs = (stages = []) => {
return stages
.map(({ name, groups }) => {
return groups.map((group) => {
return { category: name, ...group };
});
})
.flat(2);
};
const unwrapGroups = (stages) => {
return stages.map((stage) => {
const {
......
import {
unwrapArrayOfJobs,
unwrapGroups,
unwrapNodesWithName,
unwrapStagesWithNeeds,
......@@ -95,29 +94,6 @@ const completeMock = [
];
describe('Shared pipeline unwrapping utils', () => {
describe('unwrapArrayOfJobs', () => {
it('returns an empty array if the input is an empty undefined', () => {
expect(unwrapArrayOfJobs(undefined)).toEqual([]);
});
it('returns an empty array if the input is an empty array', () => {
expect(unwrapArrayOfJobs([])).toEqual([]);
});
it('returns a flatten array of each job with their data and stage name', () => {
expect(
unwrapArrayOfJobs([
{ name: 'build', groups: [{ name: 'job_a_1' }, { name: 'job_a_2' }] },
{ name: 'test', groups: [{ name: 'job_b' }] },
]),
).toMatchObject([
{ category: 'build', name: 'job_a_1' },
{ category: 'build', name: 'job_a_2' },
{ category: 'test', name: 'job_b' },
]);
});
});
describe('unwrapGroups', () => {
it('takes stages without nodes and returns the unwrapped groups', () => {
expect(unwrapGroups(stagesAndGroups)[0].groups).toEqual(groupsArray);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment