Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ci_lint.vue « components « ci_lint « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a55177b15f8562b87ccc9a256ce8edb87d937d5 (plain)
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
<script>
import { GlButton, GlFormCheckbox, GlIcon, GlLink, GlAlert } from '@gitlab/ui';
import CiLintResults from '~/pipeline_editor/components/lint/ci_lint_results.vue';
import lintCiMutation from '~/pipeline_editor/graphql/mutations/lint_ci.mutation.graphql';
import EditorLite from '~/vue_shared/components/editor_lite.vue';

export default {
  components: {
    GlButton,
    GlFormCheckbox,
    GlIcon,
    GlLink,
    GlAlert,
    CiLintResults,
    EditorLite,
  },
  props: {
    endpoint: {
      type: String,
      required: true,
    },
    lintHelpPagePath: {
      type: String,
      required: true,
    },
    pipelineSimulationHelpPagePath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      content: '',
      loading: false,
      valid: false,
      errors: null,
      warnings: null,
      jobs: [],
      dryRun: false,
      showingResults: false,
      apiError: null,
      isErrorDismissed: false,
    };
  },
  computed: {
    shouldShowError() {
      return this.apiError && !this.isErrorDismissed;
    },
  },
  methods: {
    async lint() {
      this.loading = true;
      try {
        const {
          data: {
            lintCI: { valid, errors, warnings, jobs },
          },
        } = await this.$apollo.mutate({
          mutation: lintCiMutation,
          variables: { endpoint: this.endpoint, content: this.content, dry: this.dryRun },
        });

        this.showingResults = true;
        this.valid = valid;
        this.errors = errors;
        this.warnings = warnings;
        this.jobs = jobs;
      } catch (error) {
        this.apiError = error;
        this.isErrorDismissed = false;
      } finally {
        this.loading = false;
      }
    },
    clear() {
      this.content = '';
    },
  },
};
</script>

<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>
        <editor-lite v-model="content" file-name="*.yml" />
      </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"
          :loading="loading"
          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') }}
          <gl-link :href="pipelineSimulationHelpPagePath" target="_blank"
            ><gl-icon class="gl-text-blue-600" name="question-o" /></gl-link
        ></gl-form-checkbox>
      </div>
      <gl-button data-testid="ci-lint-clear" @click="clear">{{ __('Clear') }}</gl-button>
    </div>

    <ci-lint-results
      v-if="showingResults"
      class="col-sm-12 gl-mt-5"
      :valid="valid"
      :jobs="jobs"
      :errors="errors"
      :warnings="warnings"
      :dry-run="dryRun"
      :lint-help-page-path="lintHelpPagePath"
    />
  </div>
</template>