Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7a82bb99
Commit
7a82bb99
authored
Dec 02, 2020
by
Sarah Groff Hennigh-Palermo
Committed by
Andrew Fontaine
Dec 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move and break up unwrapping utils for sharing
parent
8b207939
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
25 deletions
+172
-25
app/assets/javascripts/pipelines/components/graph/utils.js
app/assets/javascripts/pipelines/components/graph/utils.js
+9
-25
app/assets/javascripts/pipelines/components/unwrapping_utils.js
...sets/javascripts/pipelines/components/unwrapping_utils.js
+36
-0
spec/frontend/pipelines/unwrapping_utils_spec.js
spec/frontend/pipelines/unwrapping_utils_spec.js
+127
-0
No files found.
app/assets/javascripts/pipelines/components/graph/utils.js
View file @
7a82bb99
import
{
unwrapStagesWithNeeds
}
from
'
../unwrapping_utils
'
;
const
addMulti
=
(
mainId
,
pipeline
)
=>
{
return
{
...
pipeline
,
multiproject
:
mainId
!==
pipeline
.
id
};
};
const
unwrapPipelineData
=
(
mainPipelineId
,
data
)
=>
{
if
(
!
data
?.
project
?.
pipeline
)
{
return
null
;
...
...
@@ -10,35 +16,13 @@ const unwrapPipelineData = (mainPipelineId, data) => {
stages
:
{
nodes
:
stages
},
}
=
data
.
project
.
pipeline
;
const
unwrappedNestedGroups
=
stages
.
map
(
stage
=>
{
const
{
groups
:
{
nodes
:
groups
},
}
=
stage
;
return
{
...
stage
,
groups
};
});
const
nodes
=
unwrappedNestedGroups
.
map
(({
name
,
status
,
groups
})
=>
{
const
groupsWithJobs
=
groups
.
map
(
group
=>
{
const
jobs
=
group
.
jobs
.
nodes
.
map
(
job
=>
{
const
{
needs
}
=
job
;
return
{
...
job
,
needs
:
needs
.
nodes
.
map
(
need
=>
need
.
name
)
};
});
return
{
...
group
,
jobs
};
});
return
{
name
,
status
,
groups
:
groupsWithJobs
};
});
const
addMulti
=
pipeline
=>
{
return
{
...
pipeline
,
multiproject
:
mainPipelineId
!==
pipeline
.
id
};
};
const
nodes
=
unwrapStagesWithNeeds
(
stages
);
return
{
id
,
stages
:
nodes
,
upstream
:
upstream
?
[
upstream
].
map
(
addMulti
)
:
[],
downstream
:
downstream
?
downstream
.
map
(
addMulti
)
:
[],
upstream
:
upstream
?
[
upstream
].
map
(
addMulti
.
bind
(
null
,
mainPipelineId
)
)
:
[],
downstream
:
downstream
?
downstream
.
map
(
addMulti
.
bind
(
null
,
mainPipelineId
)
)
:
[],
};
};
...
...
app/assets/javascripts/pipelines/components/unwrapping_utils.js
0 → 100644
View file @
7a82bb99
const
unwrapGroups
=
stages
=>
{
return
stages
.
map
(
stage
=>
{
const
{
groups
:
{
nodes
:
groups
},
}
=
stage
;
return
{
...
stage
,
groups
};
});
};
const
unwrapNodesWithName
=
(
jobArray
,
prop
,
field
=
'
name
'
)
=>
{
return
jobArray
.
map
(
job
=>
{
return
{
...
job
,
[
prop
]:
job
[
prop
].
nodes
.
map
(
item
=>
item
[
field
])
};
});
};
const
unwrapJobWithNeeds
=
denodedJobArray
=>
{
return
unwrapNodesWithName
(
denodedJobArray
,
'
needs
'
);
};
const
unwrapStagesWithNeeds
=
denodedStages
=>
{
const
unwrappedNestedGroups
=
unwrapGroups
(
denodedStages
);
const
nodes
=
unwrappedNestedGroups
.
map
(
node
=>
{
const
{
groups
}
=
node
;
const
groupsWithJobs
=
groups
.
map
(
group
=>
{
const
jobs
=
unwrapJobWithNeeds
(
group
.
jobs
.
nodes
);
return
{
...
group
,
jobs
};
});
return
{
...
node
,
groups
:
groupsWithJobs
};
});
return
nodes
;
};
export
{
unwrapGroups
,
unwrapNodesWithName
,
unwrapJobWithNeeds
,
unwrapStagesWithNeeds
};
spec/frontend/pipelines/unwrapping_utils_spec.js
0 → 100644
View file @
7a82bb99
import
{
unwrapGroups
,
unwrapNodesWithName
,
unwrapStagesWithNeeds
,
}
from
'
~/pipelines/components/unwrapping_utils
'
;
const
groupsArray
=
[
{
name
:
'
build_a
'
,
size
:
1
,
status
:
{
label
:
'
passed
'
,
group
:
'
success
'
,
icon
:
'
status_success
'
,
},
},
{
name
:
'
bob_the_build
'
,
size
:
1
,
status
:
{
label
:
'
passed
'
,
group
:
'
success
'
,
icon
:
'
status_success
'
,
},
},
];
const
basicStageInfo
=
{
name
:
'
center_stage
'
,
status
:
{
action
:
null
,
},
};
const
stagesAndGroups
=
[
{
...
basicStageInfo
,
groups
:
{
nodes
:
groupsArray
,
},
},
];
const
needArray
=
[
{
name
:
'
build_b
'
,
},
];
const
elephantArray
=
[
{
name
:
'
build_b
'
,
elephant
:
'
gray
'
,
},
];
const
baseJobs
=
{
name
:
'
test_d
'
,
status
:
{
icon
:
'
status_success
'
,
tooltip
:
null
,
hasDetails
:
true
,
detailsPath
:
'
/root/abcd-dag/-/pipelines/162
'
,
group
:
'
success
'
,
action
:
null
,
},
};
const
jobArrayWithNeeds
=
[
{
...
baseJobs
,
needs
:
{
nodes
:
needArray
,
},
},
];
const
jobArrayWithElephant
=
[
{
...
baseJobs
,
needs
:
{
nodes
:
elephantArray
,
},
},
];
const
completeMock
=
[
{
...
basicStageInfo
,
groups
:
{
nodes
:
groupsArray
.
map
(
group
=>
({
...
group
,
jobs
:
{
nodes
:
jobArrayWithNeeds
}
})),
},
},
];
describe
(
'
Shared pipeline unwrapping utils
'
,
()
=>
{
describe
(
'
unwrapGroups
'
,
()
=>
{
it
(
'
takes stages without nodes and returns the unwrapped groups
'
,
()
=>
{
expect
(
unwrapGroups
(
stagesAndGroups
)[
0
].
groups
).
toEqual
(
groupsArray
);
});
it
(
'
keeps other stage properties intact
'
,
()
=>
{
expect
(
unwrapGroups
(
stagesAndGroups
)[
0
]).
toMatchObject
(
basicStageInfo
);
});
});
describe
(
'
unwrapNodesWithName
'
,
()
=>
{
it
(
'
works with no field argument
'
,
()
=>
{
expect
(
unwrapNodesWithName
(
jobArrayWithNeeds
,
'
needs
'
)[
0
].
needs
).
toEqual
([
needArray
[
0
].
name
]);
});
it
(
'
works with custom field argument
'
,
()
=>
{
expect
(
unwrapNodesWithName
(
jobArrayWithElephant
,
'
needs
'
,
'
elephant
'
)[
0
].
needs
).
toEqual
([
elephantArray
[
0
].
elephant
,
]);
});
});
describe
(
'
unwrapStagesWithNeeds
'
,
()
=>
{
it
(
'
removes nodes from groups, jobs, and needs
'
,
()
=>
{
const
firstProcessedGroup
=
unwrapStagesWithNeeds
(
completeMock
)[
0
].
groups
[
0
];
expect
(
firstProcessedGroup
).
toMatchObject
(
groupsArray
[
0
]);
expect
(
firstProcessedGroup
.
jobs
[
0
]).
toMatchObject
(
baseJobs
);
expect
(
firstProcessedGroup
.
jobs
[
0
].
needs
[
0
]).
toBe
(
needArray
[
0
].
name
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment