Commit 90a1b81b authored by Miguel Rincon's avatar Miguel Rincon

Add CI config fields to lint tab

This change adds a few fields from the CI config that are now available
in the GraphQL API such as `script` and `allow_failure`.
parent 3438395c
<script> <script>
import { flatten } from 'lodash';
import { CI_CONFIG_STATUS_VALID } from '../../constants'; import { CI_CONFIG_STATUS_VALID } from '../../constants';
import CiLintResults from './ci_lint_results.vue'; import CiLintResults from './ci_lint_results.vue';
...@@ -25,14 +26,18 @@ export default { ...@@ -25,14 +26,18 @@ export default {
return this.ciConfig?.stages || []; return this.ciConfig?.stages || [];
}, },
jobs() { jobs() {
return this.stages.reduce((acc, { groups, name: stageName }) => { const groupedJobs = this.stages.reduce((acc, { groups, name: stageName }) => {
return acc.concat( return acc.concat(
groups.map(({ name: groupName }) => ({ groups.map(({ jobs }) => {
stage: stageName, return jobs.map((job) => ({
name: groupName, stage: stageName,
})), ...job,
}));
}),
); );
}, []); }, []);
return flatten(groupedJobs);
}, },
}, },
}; };
......
...@@ -14,7 +14,7 @@ export default { ...@@ -14,7 +14,7 @@ export default {
}, },
computed: { computed: {
tagList() { tagList() {
return this.item.tagList?.join(', '); return this.item.tags?.join(', ');
}, },
onlyPolicy() { onlyPolicy() {
return this.item.only ? this.item.only.refs.join(', ') : this.item.only; return this.item.only ? this.item.only.refs.join(', ') : this.item.only;
......
...@@ -15,7 +15,7 @@ mutation lintCI($endpoint: String, $content: String, $dry: Boolean) { ...@@ -15,7 +15,7 @@ mutation lintCI($endpoint: String, $content: String, $dry: Boolean) {
} }
afterScript afterScript
stage stage
tagList tags
when when
} }
} }
......
...@@ -27,7 +27,7 @@ export const resolvers = { ...@@ -27,7 +27,7 @@ export const resolvers = {
beforeScript: job.before_script, beforeScript: job.before_script,
script: job.script, script: job.script,
afterScript: job.after_script, afterScript: job.after_script,
tagList: job.tag_list, tags: job.tag_list,
environment: job.environment, environment: job.environment,
when: job.when, when: job.when,
allowFailure: job.allow_failure, allowFailure: job.allow_failure,
......
...@@ -8,6 +8,19 @@ fragment PipelineStagesConnection on CiConfigStageConnection { ...@@ -8,6 +8,19 @@ fragment PipelineStagesConnection on CiConfigStageConnection {
jobs { jobs {
nodes { nodes {
name name
script
beforeScript
afterScript
environment
allowFailure
tags
when
only {
refs
}
except {
refs
}
needs { needs {
nodes { nodes {
name name
......
...@@ -23,6 +23,7 @@ describe('~/pipeline_editor/components/lint/ci_lint.vue', () => { ...@@ -23,6 +23,7 @@ describe('~/pipeline_editor/components/lint/ci_lint.vue', () => {
const findAlert = () => wrapper.find(GlAlert); const findAlert = () => wrapper.find(GlAlert);
const findLintParameters = () => findAllByTestId('ci-lint-parameter'); const findLintParameters = () => findAllByTestId('ci-lint-parameter');
const findLintParameterAt = (i) => findLintParameters().at(i); const findLintParameterAt = (i) => findLintParameters().at(i);
const findLintValueAt = (i) => findAllByTestId('ci-lint-value').at(i);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -50,6 +51,20 @@ describe('~/pipeline_editor/components/lint/ci_lint.vue', () => { ...@@ -50,6 +51,20 @@ describe('~/pipeline_editor/components/lint/ci_lint.vue', () => {
expect(findLintParameterAt(2).text()).toBe('Build Job - job_build'); expect(findLintParameterAt(2).text()).toBe('Build Job - job_build');
}); });
it('displays jobs details', () => {
expect(findLintParameters()).toHaveLength(3);
expect(findLintValueAt(0).text()).toMatchInterpolatedText(
'echo "test 1" Only policy: branches, tags When: on_success',
);
expect(findLintValueAt(1).text()).toMatchInterpolatedText(
'echo "test 2" Only policy: branches, tags When: on_success',
);
expect(findLintValueAt(2).text()).toMatchInterpolatedText(
'echo "build" Only policy: branches, tags When: on_success',
);
});
it('displays invalid results', () => { it('displays invalid results', () => {
createComponent( createComponent(
{ {
......
...@@ -27,7 +27,7 @@ Object { ...@@ -27,7 +27,7 @@ Object {
"echo 'script 1'", "echo 'script 1'",
], ],
"stage": "test", "stage": "test",
"tagList": Array [ "tags": Array [
"tag 1", "tag 1",
], ],
"when": "on_success", "when": "on_success",
...@@ -61,7 +61,7 @@ Object { ...@@ -61,7 +61,7 @@ Object {
"echo 'script 2'", "echo 'script 2'",
], ],
"stage": "test", "stage": "test",
"tagList": Array [ "tags": Array [
"tag 2", "tag 2",
], ],
"when": "on_success", "when": "on_success",
......
...@@ -35,6 +35,21 @@ job_build: ...@@ -35,6 +35,21 @@ job_build:
needs: ["job_test_2"] needs: ["job_test_2"]
`; `;
const mockJobFields = {
beforeScript: [],
afterScript: [],
environment: null,
allowFailure: false,
tags: [],
when: 'on_success',
only: { refs: ['branches', 'tags'], __typename: 'CiJobLimitType' },
except: null,
needs: { nodes: [], __typename: 'CiConfigNeedConnection' },
__typename: 'CiConfigJob',
};
// Mock result of the graphql query at:
// app/assets/javascripts/pipeline_editor/graphql/queries/ci_config.graphql
export const mockCiConfigQueryResponse = { export const mockCiConfigQueryResponse = {
data: { data: {
ciConfig: { ciConfig: {
...@@ -54,8 +69,8 @@ export const mockCiConfigQueryResponse = { ...@@ -54,8 +69,8 @@ export const mockCiConfigQueryResponse = {
nodes: [ nodes: [
{ {
name: 'job_test_1', name: 'job_test_1',
needs: { nodes: [], __typename: 'CiConfigNeedConnection' }, script: ['echo "test 1"'],
__typename: 'CiConfigJob', ...mockJobFields,
}, },
], ],
__typename: 'CiConfigJobConnection', __typename: 'CiConfigJobConnection',
...@@ -69,9 +84,8 @@ export const mockCiConfigQueryResponse = { ...@@ -69,9 +84,8 @@ export const mockCiConfigQueryResponse = {
nodes: [ nodes: [
{ {
name: 'job_test_2', name: 'job_test_2',
script: ['echo "test 2"'],
needs: { nodes: [], __typename: 'CiConfigNeedConnection' }, ...mockJobFields,
__typename: 'CiConfigJob',
}, },
], ],
__typename: 'CiConfigJobConnection', __typename: 'CiConfigJobConnection',
...@@ -94,11 +108,8 @@ export const mockCiConfigQueryResponse = { ...@@ -94,11 +108,8 @@ export const mockCiConfigQueryResponse = {
nodes: [ nodes: [
{ {
name: 'job_build', name: 'job_build',
needs: { script: ['echo "build"'],
nodes: [{ name: 'job_test_2', __typename: 'CiConfigNeed' }], ...mockJobFields,
__typename: 'CiConfigNeedConnection',
},
__typename: 'CiConfigJob',
}, },
], ],
__typename: 'CiConfigJobConnection', __typename: 'CiConfigJobConnection',
......
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