debian-mirror-gitlab/app/assets/javascripts/ci_lint/components/ci_lint.vue

132 lines
3.3 KiB
Vue
Raw Normal View History

2020-11-24 15:15:51 +05:30
<script>
2021-01-03 14:25:43 +05:30
import { GlButton, GlFormCheckbox, GlIcon, GlLink, GlAlert } from '@gitlab/ui';
2021-02-22 17:27:13 +05:30
import CiLintResults from '~/pipeline_editor/components/lint/ci_lint_results.vue';
2022-01-26 12:08:38 +05:30
import lintCiMutation from '~/pipeline_editor/graphql/mutations/client/lint_ci.mutation.graphql';
2021-09-30 23:02:18 +05:30
import SourceEditor from '~/vue_shared/components/source_editor.vue';
2021-01-03 14:25:43 +05:30
2020-11-24 15:15:51 +05:30
export default {
2021-01-03 14:25:43 +05:30
components: {
GlButton,
GlFormCheckbox,
GlIcon,
GlLink,
GlAlert,
CiLintResults,
2021-09-30 23:02:18 +05:30
SourceEditor,
2021-01-03 14:25:43 +05:30
},
2020-11-24 15:15:51 +05:30
props: {
endpoint: {
type: String,
required: true,
},
2021-01-29 00:20:46 +05:30
lintHelpPagePath: {
type: String,
required: true,
},
pipelineSimulationHelpPagePath: {
2021-01-03 14:25:43 +05:30
type: String,
required: true,
},
},
data() {
return {
content: '',
2021-01-29 00:20:46 +05:30
loading: false,
2021-04-29 21:17:54 +05:30
isValid: false,
2021-01-03 14:25:43 +05:30
errors: null,
warnings: null,
jobs: [],
dryRun: false,
showingResults: false,
apiError: null,
isErrorDismissed: false,
};
},
computed: {
shouldShowError() {
return this.apiError && !this.isErrorDismissed;
},
},
methods: {
async lint() {
2021-01-29 00:20:46 +05:30
this.loading = true;
2021-01-03 14:25:43 +05:30
try {
const {
data: {
lintCI: { valid, errors, warnings, jobs },
},
} = await this.$apollo.mutate({
2021-02-22 17:27:13 +05:30
mutation: lintCiMutation,
2021-01-03 14:25:43 +05:30
variables: { endpoint: this.endpoint, content: this.content, dry: this.dryRun },
});
this.showingResults = true;
2021-04-29 21:17:54 +05:30
this.isValid = valid;
2021-01-03 14:25:43 +05:30
this.errors = errors;
this.warnings = warnings;
this.jobs = jobs;
} catch (error) {
this.apiError = error;
this.isErrorDismissed = false;
2021-01-29 00:20:46 +05:30
} finally {
this.loading = false;
2021-01-03 14:25:43 +05:30
}
},
clear() {
this.content = '';
},
2020-11-24 15:15:51 +05:30
},
};
</script>
2021-01-03 14:25:43 +05:30
<template>
<div class="row">
<div class="col-sm-12">
<gl-alert
v-if="shouldShowError"
class="gl-mb-3"
variant="danger"
@dismiss="isErrorDismissed = true"
>{{ apiError }}</gl-alert
>
<div class="file-holder gl-mb-3">
<div class="js-file-title file-title clearfix">
{{ __('Contents of .gitlab-ci.yml') }}
</div>
2021-09-30 23:02:18 +05:30
<source-editor v-model="content" file-name="*.yml" />
2021-01-03 14:25:43 +05:30
</div>
</div>
<div class="col-sm-12 gl-display-flex gl-justify-content-space-between">
<div class="gl-display-flex gl-align-items-center">
<gl-button
class="gl-mr-4"
2021-01-29 00:20:46 +05:30
:loading="loading"
2021-01-03 14:25:43 +05:30
category="primary"
variant="success"
data-testid="ci-lint-validate"
@click="lint"
>{{ __('Validate') }}</gl-button
>
<gl-form-checkbox v-model="dryRun"
>{{ __('Simulate a pipeline created for the default branch') }}
2021-01-29 00:20:46 +05:30
<gl-link :href="pipelineSimulationHelpPagePath" target="_blank"
2021-03-08 18:12:59 +05:30
><gl-icon class="gl-text-blue-600" name="question-o" /></gl-link
2021-01-03 14:25:43 +05:30
></gl-form-checkbox>
</div>
<gl-button data-testid="ci-lint-clear" @click="clear">{{ __('Clear') }}</gl-button>
</div>
<ci-lint-results
v-if="showingResults"
2021-02-22 17:27:13 +05:30
class="col-sm-12 gl-mt-5"
2021-04-29 21:17:54 +05:30
:is-valid="isValid"
2021-01-03 14:25:43 +05:30
:jobs="jobs"
:errors="errors"
:warnings="warnings"
:dry-run="dryRun"
2021-01-29 00:20:46 +05:30
:lint-help-page-path="lintHelpPagePath"
2021-01-03 14:25:43 +05:30
/>
</div>
</template>