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
|
<script>
import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui';
import { __ } from '~/locale';
import getPipelineWarnings from '../../graphql/queries/get_pipeline_warnings.query.graphql';
export default {
// eslint-disable-next-line @gitlab/require-i18n-strings
expectedMessage: 'will be removed in',
i18n: {
title: __('Found warning in your .gitlab-ci.yml'),
rootTypesWarning: __(
'%{codeStart}types%{codeEnd} is deprecated and will be removed in 15.0. Use %{codeStart}stages%{codeEnd} instead. %{linkStart}Learn More %{linkEnd}',
),
typeWarning: __(
'%{codeStart}type%{codeEnd} is deprecated and will be removed in 15.0. Use %{codeStart}stage%{codeEnd} instead. %{linkStart}Learn More %{linkEnd}',
),
},
components: {
GlAlert,
GlLink,
GlSprintf,
},
inject: ['deprecatedKeywordsDocPath', 'fullPath', 'pipelineIid'],
apollo: {
warnings: {
query: getPipelineWarnings,
variables() {
return {
fullPath: this.fullPath,
iid: this.pipelineIid,
};
},
update(data) {
return data?.project?.pipeline?.warningMessages || [];
},
error() {
this.hasError = true;
},
},
},
data() {
return {
warnings: [],
hasError: false,
};
},
computed: {
deprecationWarnings() {
return this.warnings.filter(({ content }) => {
return content.includes(this.$options.expectedMessage);
});
},
formattedWarnings() {
// The API doesn't have a mechanism currently to return a
// type instead of just the error message. To work around this,
// we check if the deprecation message is found within the warnings
// and show a FE version of that message with the link to the documentation
// and translated. We can have only 2 types of warnings: root types and individual
// type. If the word `root` is present, then we know it's the root type deprecation
// and if not, it's the normal type. This has to be deleted in 15.0.
// Follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/350810
return this.deprecationWarnings.map(({ content }) => {
if (content.includes('root')) {
return this.$options.i18n.rootTypesWarning;
}
return this.$options.i18n.typeWarning;
});
},
hasDeprecationWarning() {
return this.formattedWarnings.length > 0;
},
showWarning() {
return (
!this.$apollo.queries.warnings?.loading && !this.hasError && this.hasDeprecationWarning
);
},
},
};
</script>
<template>
<div>
<gl-alert
v-if="showWarning"
:title="$options.i18n.title"
variant="warning"
:dismissible="false"
>
<ul class="gl-mb-0">
<li v-for="warning in formattedWarnings" :key="warning">
<gl-sprintf :message="warning">
<template #code="{ content }">
<code> {{ content }}</code>
</template>
<template #link="{ content }">
<gl-link :href="deprecatedKeywordsDocPath" target="_blank"> {{ content }}</gl-link>
</template>
</gl-sprintf>
</li>
</ul>
</gl-alert>
</div>
</template>
|