Commit ffad46c1 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'emilyring-terraform-pipeline' into 'master'

Add pipeline information to Terraform state list

See merge request gitlab-org/gitlab!49042
parents e6e68627 e4ac22ed
<script> <script>
import { GlBadge, GlIcon, GlSprintf, GlTable, GlTooltip } from '@gitlab/ui'; import { GlBadge, GlIcon, GlLink, GlSprintf, GlTable, GlTooltip } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import CiBadge from '~/vue_shared/components/ci_badge_link.vue';
import StateActions from './states_table_actions.vue'; import StateActions from './states_table_actions.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
export default { export default {
components: { components: {
CiBadge,
GlBadge, GlBadge,
GlIcon, GlIcon,
GlLink,
GlSprintf, GlSprintf,
GlTable, GlTable,
GlTooltip, GlTooltip,
...@@ -32,20 +36,24 @@ export default { ...@@ -32,20 +36,24 @@ export default {
const columns = [ const columns = [
{ {
key: 'name', key: 'name',
thClass: 'gl-display-none', label: this.$options.i18n.name,
},
{
key: 'pipeline',
label: this.$options.i18n.pipeline,
}, },
{ {
key: 'updated', key: 'updated',
thClass: 'gl-display-none', label: this.$options.i18n.details,
tdClass: 'gl-text-right',
}, },
]; ];
if (this.terraformAdmin) { if (this.terraformAdmin) {
columns.push({ columns.push({
key: 'actions', key: 'actions',
thClass: 'gl-display-none', label: this.$options.i18n.actions,
tdClass: 'gl-w-10', thClass: 'gl-w-12',
tdClass: 'gl-text-right',
}); });
} }
...@@ -53,8 +61,13 @@ export default { ...@@ -53,8 +61,13 @@ export default {
}, },
}, },
i18n: { i18n: {
actions: s__('Terraform|Actions'),
details: s__('Terraform|Details'),
jobStatus: s__('Terraform|Job status'),
locked: s__('Terraform|Locked'), locked: s__('Terraform|Locked'),
lockedByUser: s__('Terraform|Locked by %{user} %{timeAgo}'), lockedByUser: s__('Terraform|Locked by %{user} %{timeAgo}'),
name: s__('Terraform|Name'),
pipeline: s__('Terraform|Pipeline'),
unknownUser: s__('Terraform|Unknown User'), unknownUser: s__('Terraform|Unknown User'),
updatedUser: s__('Terraform|%{user} updated %{timeAgo}'), updatedUser: s__('Terraform|%{user} updated %{timeAgo}'),
}, },
...@@ -65,6 +78,21 @@ export default { ...@@ -65,6 +78,21 @@ export default {
lockedByUserName(item) { lockedByUserName(item) {
return item.lockedByUser?.name || this.$options.i18n.unknownUser; return item.lockedByUser?.name || this.$options.i18n.unknownUser;
}, },
pipelineDetailedStatus(item) {
return item.latestVersion?.job?.detailedStatus;
},
pipelineID(item) {
let id = item.latestVersion?.job?.pipeline?.id;
if (id) {
id = getIdFromGraphQLId(id);
}
return id;
},
pipelinePath(item) {
return item.latestVersion?.job?.pipeline?.path;
},
updatedTime(item) { updatedTime(item) {
return item.latestVersion?.updatedAt || item.updatedAt; return item.latestVersion?.updatedAt || item.updatedAt;
}, },
...@@ -73,9 +101,18 @@ export default { ...@@ -73,9 +101,18 @@ export default {
</script> </script>
<template> <template>
<gl-table :items="states" :fields="fields" data-testid="terraform-states-table"> <gl-table
:items="states"
:fields="fields"
data-testid="terraform-states-table"
fixed
stacked="md"
>
<template #cell(name)="{ item }"> <template #cell(name)="{ item }">
<div class="gl-display-flex align-items-center" data-testid="terraform-states-table-name"> <div
class="gl-display-flex align-items-center gl-justify-content-end gl-justify-content-md-start"
data-testid="terraform-states-table-name"
>
<p class="gl-font-weight-bold gl-m-0 gl-text-gray-900"> <p class="gl-font-weight-bold gl-m-0 gl-text-gray-900">
{{ item.name }} {{ item.name }}
</p> </p>
...@@ -105,6 +142,34 @@ export default { ...@@ -105,6 +142,34 @@ export default {
</div> </div>
</template> </template>
<template #cell(pipeline)="{ item }">
<div data-testid="terraform-states-table-pipeline" class="gl-min-h-7">
<gl-link v-if="pipelineID(item)" :href="pipelinePath(item)">
#{{ pipelineID(item) }}
</gl-link>
<div
v-if="pipelineDetailedStatus(item)"
:id="`terraformJobStatusContainer${item.name}`"
class="gl-my-2"
>
<ci-badge
:id="`terraformJobStatus${item.name}`"
:status="pipelineDetailedStatus(item)"
class="gl-py-1"
/>
<gl-tooltip
:container="`terraformJobStatusContainer${item.name}`"
:target="`terraformJobStatus${item.name}`"
placement="right"
>
{{ $options.i18n.jobStatus }}
</gl-tooltip>
</div>
</div>
</template>
<template #cell(updated)="{ item }"> <template #cell(updated)="{ item }">
<p class="gl-m-0" data-testid="terraform-states-table-updated"> <p class="gl-m-0" data-testid="terraform-states-table-updated">
<gl-sprintf :message="$options.i18n.updatedUser"> <gl-sprintf :message="$options.i18n.updatedUser">
......
...@@ -8,4 +8,19 @@ fragment StateVersion on TerraformStateVersion { ...@@ -8,4 +8,19 @@ fragment StateVersion on TerraformStateVersion {
createdByUser { createdByUser {
...User ...User
} }
job {
detailedStatus {
detailsPath
group
icon
label
text
}
pipeline {
id
path
}
}
} }
...@@ -20,6 +20,7 @@ import CiIcon from './ci_icon.vue'; ...@@ -20,6 +20,7 @@ import CiIcon from './ci_icon.vue';
* - Pipeline show view - header * - Pipeline show view - header
* - Job show view - header * - Job show view - header
* - MR widget * - MR widget
* - Terraform table
*/ */
export default { export default {
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
class JobType < BaseObject class JobType < BaseObject
graphql_name 'CiJob' graphql_name 'CiJob'
field :pipeline, Types::Ci::PipelineType, null: false, field :pipeline, Types::Ci::PipelineType, null: true,
description: 'Pipeline the job belongs to' description: 'Pipeline the job belongs to'
field :name, GraphQL::STRING_TYPE, null: true, field :name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the job' description: 'Name of the job'
......
- add_page_specific_style 'page_bundles/ci_status'
- breadcrumb_title _('Terraform') - breadcrumb_title _('Terraform')
- page_title _('Terraform') - page_title _('Terraform')
......
---
title: Add pipeline information to Terraform state list
merge_request: 49042
author:
type: added
...@@ -2498,7 +2498,7 @@ type CiJob { ...@@ -2498,7 +2498,7 @@ type CiJob {
""" """
Pipeline the job belongs to Pipeline the job belongs to
""" """
pipeline: Pipeline! pipeline: Pipeline
""" """
Schedule for the build Schedule for the build
......
...@@ -6737,13 +6737,9 @@ ...@@ -6737,13 +6737,9 @@
], ],
"type": { "type": {
"kind": "NON_NULL", "kind": "OBJECT",
"name": null, "name": "Pipeline",
"ofType": { "ofType": null
"kind": "OBJECT",
"name": "Pipeline",
"ofType": null
}
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
...@@ -430,7 +430,7 @@ Represents the total number of issues and their weights for a particular day. ...@@ -430,7 +430,7 @@ Represents the total number of issues and their weights for a particular day.
| `detailedStatus` | DetailedStatus | Detailed status of the job | | `detailedStatus` | DetailedStatus | Detailed status of the job |
| `name` | String | Name of the job | | `name` | String | Name of the job |
| `needs` | CiJobConnection | Builds that must complete before the jobs run | | `needs` | CiJobConnection | Builds that must complete before the jobs run |
| `pipeline` | Pipeline! | Pipeline the job belongs to | | `pipeline` | Pipeline | Pipeline the job belongs to |
| `scheduledAt` | Time | Schedule for the build | | `scheduledAt` | Time | Schedule for the build |
### CiJobArtifact ### CiJobArtifact
......
...@@ -27075,9 +27075,15 @@ msgstr "" ...@@ -27075,9 +27075,15 @@ msgstr ""
msgid "Terraform|A Terraform report was generated in your pipelines." msgid "Terraform|A Terraform report was generated in your pipelines."
msgstr "" msgstr ""
msgid "Terraform|Actions"
msgstr ""
msgid "Terraform|An error occurred while loading your Terraform States" msgid "Terraform|An error occurred while loading your Terraform States"
msgstr "" msgstr ""
msgid "Terraform|Details"
msgstr ""
msgid "Terraform|Download JSON" msgid "Terraform|Download JSON"
msgstr "" msgstr ""
...@@ -27090,6 +27096,9 @@ msgstr "" ...@@ -27090,6 +27096,9 @@ msgstr ""
msgid "Terraform|Get started with Terraform" msgid "Terraform|Get started with Terraform"
msgstr "" msgstr ""
msgid "Terraform|Job status"
msgstr ""
msgid "Terraform|Lock" msgid "Terraform|Lock"
msgstr "" msgstr ""
...@@ -27099,6 +27108,12 @@ msgstr "" ...@@ -27099,6 +27108,12 @@ msgstr ""
msgid "Terraform|Locked by %{user} %{timeAgo}" msgid "Terraform|Locked by %{user} %{timeAgo}"
msgstr "" msgstr ""
msgid "Terraform|Name"
msgstr ""
msgid "Terraform|Pipeline"
msgstr ""
msgid "Terraform|Reported Resource Changes: %{addNum} to add, %{changeNum} to change, %{deleteNum} to delete" msgid "Terraform|Reported Resource Changes: %{addNum} to add, %{changeNum} to change, %{deleteNum} to delete"
msgstr "" msgstr ""
......
...@@ -38,6 +38,19 @@ describe('StatesTable', () => { ...@@ -38,6 +38,19 @@ describe('StatesTable', () => {
createdByUser: { createdByUser: {
name: 'user-3', name: 'user-3',
}, },
job: {
detailedStatus: {
detailsPath: '/job-path-3',
group: 'failed',
icon: 'status_failed',
label: 'failed',
text: 'failed',
},
pipeline: {
id: 'gid://gitlab/Ci::Pipeline/3',
path: '/pipeline-path-3',
},
},
}, },
}, },
{ {
...@@ -48,6 +61,19 @@ describe('StatesTable', () => { ...@@ -48,6 +61,19 @@ describe('StatesTable', () => {
latestVersion: { latestVersion: {
updatedAt: '2020-10-09T00:00:00Z', updatedAt: '2020-10-09T00:00:00Z',
createdByUser: null, createdByUser: null,
job: {
detailedStatus: {
detailsPath: '/job-path-4',
group: 'passed',
icon: 'status_success',
label: 'passed',
text: 'passed',
},
pipeline: {
id: 'gid://gitlab/Ci::Pipeline/4',
path: '/pipeline-path-4',
},
},
}, },
}, },
], ],
...@@ -107,6 +133,23 @@ describe('StatesTable', () => { ...@@ -107,6 +133,23 @@ describe('StatesTable', () => {
expect(state.text()).toMatchInterpolatedText(updateTime); expect(state.text()).toMatchInterpolatedText(updateTime);
}); });
it.each`
pipelineText | toolTipAdded | lineNumber
${''} | ${false} | ${0}
${''} | ${false} | ${1}
${'#3 failed Job status'} | ${true} | ${2}
${'#4 passed Job status'} | ${true} | ${3}
`(
'displays the pipeline information for line "$lineNumber"',
({ pipelineText, toolTipAdded, lineNumber }) => {
const states = wrapper.findAll('[data-testid="terraform-states-table-pipeline"]');
const state = states.at(lineNumber);
expect(state.find(GlTooltip).exists()).toBe(toolTipAdded);
expect(state.text()).toMatchInterpolatedText(pipelineText);
},
);
it('displays no actions dropdown', () => { it('displays no actions dropdown', () => {
expect(findActions().length).toEqual(0); expect(findActions().length).toEqual(0);
}); });
......
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