1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
<script>
import { GlButton, GlIcon, GlLink, GlLoadingIcon, GlSprintf, GlTooltipDirective } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { truncateSha } from '~/lib/utils/text_utility';
import { s__ } from '~/locale';
import getPipelineQuery from '~/ci/pipeline_editor/graphql/queries/pipeline.query.graphql';
import getPipelineEtag from '~/ci/pipeline_editor/graphql/queries/client/pipeline_etag.query.graphql';
import { getQueryHeaders, toggleQueryPollingByVisibility } from '~/ci/pipeline_details/graph/utils';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import CiBadgeLink from '~/vue_shared/components/ci_badge_link.vue';
import PipelineMiniGraph from '~/ci/pipeline_mini_graph/pipeline_mini_graph.vue';
import PipelineEditorMiniGraph from './pipeline_editor_mini_graph.vue';
const POLL_INTERVAL = 10000;
export const i18n = {
fetchError: s__('Pipeline|We are currently unable to fetch pipeline data'),
fetchLoading: s__('Pipeline|Checking pipeline status'),
pipelineInfo: s__(
`Pipeline|Pipeline %{idStart}#%{idEnd} %{statusStart}%{statusEnd} for %{commitStart}%{commitEnd}`,
),
viewBtn: s__('Pipeline|View pipeline'),
viewCommit: s__('Pipeline|View commit'),
};
export default {
i18n,
components: {
CiBadgeLink,
GlButton,
GlIcon,
GlLink,
GlLoadingIcon,
GlSprintf,
PipelineEditorMiniGraph,
PipelineMiniGraph,
},
directives: {
GlTooltip: GlTooltipDirective,
},
mixins: [glFeatureFlagsMixin()],
inject: ['projectFullPath'],
props: {
commitSha: {
type: String,
required: false,
default: '',
},
},
apollo: {
pipelineEtag: {
query: getPipelineEtag,
update(data) {
return data.etags?.pipeline;
},
},
pipeline: {
context() {
return getQueryHeaders(this.pipelineEtag);
},
query: getPipelineQuery,
variables() {
return {
fullPath: this.projectFullPath,
sha: this.commitSha,
};
},
update(data) {
const { id, iid, commit = {}, detailedStatus = {}, stages, status } =
data.project?.pipeline || {};
return {
id,
iid,
commit,
detailedStatus,
stages,
status,
};
},
result(res) {
if (res.data?.project?.pipeline) {
this.hasError = false;
}
},
error() {
this.hasError = true;
},
pollInterval: POLL_INTERVAL,
},
},
data() {
return {
hasError: false,
};
},
computed: {
commitText() {
const shortSha = truncateSha(this.commitSha);
const commitTitle = this.pipeline.commit.title || '';
if (commitTitle.length > 0) {
return `${shortSha}: ${commitTitle}`;
}
return shortSha;
},
hasPipelineData() {
return Boolean(this.pipeline?.id);
},
isUsingPipelineMiniGraphQueries() {
return this.glFeatures.ciGraphqlPipelineMiniGraph;
},
pipelineId() {
return getIdFromGraphQLId(this.pipeline.id);
},
showLoadingState() {
// the query is set to poll regularly, so if there is no pipeline data
// (e.g. pipeline is null during fetch when the pipeline hasn't been
// triggered yet), we can just show the loading state until the pipeline
// details are ready to be fetched
return (
this.$apollo.queries.pipeline.loading ||
this.commitSha.length === 0 ||
(!this.hasPipelineData && !this.hasError)
);
},
shortSha() {
return truncateSha(this.commitSha);
},
status() {
return this.pipeline.detailedStatus;
},
},
mounted() {
toggleQueryPollingByVisibility(this.$apollo.queries.pipeline, POLL_INTERVAL);
},
};
</script>
<template>
<div
class="gl-display-flex gl-justify-content-space-between gl-align-items-center gl-flex-wrap gl-w-full"
>
<template v-if="showLoadingState">
<div>
<gl-loading-icon class="gl-mr-auto gl-display-inline-block" size="sm" />
<span data-testid="pipeline-loading-msg">{{ $options.i18n.fetchLoading }}</span>
</div>
</template>
<template v-else-if="hasError">
<div>
<gl-icon class="gl-mr-auto" name="warning-solid" />
<span data-testid="pipeline-error-msg">{{ $options.i18n.fetchError }}</span>
</div>
</template>
<template v-else>
<div class="gl-text-truncate gl-md-max-w-50p gl-mr-1">
<a :href="status.detailsPath" class="gl-mr-auto">
<ci-badge-link
:status="status"
badge-size="md"
:show-text="false"
data-testid="pipeline-status-icon"
/>
</a>
<span class="gl-font-weight-bold">
<gl-sprintf :message="$options.i18n.pipelineInfo">
<template #id="{ content }">
<span data-testid="pipeline-id"> {{ content }}{{ pipelineId }} </span>
</template>
<template #status>{{ status.text }}</template>
<template #commit>
<gl-link
v-gl-tooltip.hover
:href="pipeline.commit.webPath"
:title="$options.i18n.viewCommit"
data-testid="pipeline-commit"
>
{{ commitText }}
</gl-link>
</template>
</gl-sprintf>
</span>
</div>
<div class="gl-display-flex gl-flex-wrap-wrap">
<pipeline-mini-graph
v-if="isUsingPipelineMiniGraphQueries"
:full-path="projectFullPath"
:iid="pipeline.iid"
:pipeline-etag="pipelineEtag"
/>
<pipeline-editor-mini-graph v-else :pipeline="pipeline" v-on="$listeners" />
<gl-button
class="gl-ml-3 gl-align-self-center"
size="small"
:href="status.detailsPath"
data-testid="pipeline-view-btn"
>
{{ $options.i18n.viewBtn }}
</gl-button>
</div>
</template>
</div>
</template>
|