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

failed_job_details.vue « failure_widget « pipelines_list « components « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edf4cc87a873d5db8b08910434c60a4732638b13 (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
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
<script>
import { GlButton, GlIcon, GlLink, GlTooltip } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { __, s__, sprintf } from '~/locale';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import SafeHtml from '~/vue_shared/directives/safe_html';
import { BRIDGE_KIND } from '~/pipelines/components/graph/constants';
import RetryMrFailedJobMutation from '../../../graphql/mutations/retry_mr_failed_job.mutation.graphql';

export default {
  components: {
    CiIcon,
    GlButton,
    GlIcon,
    GlLink,
    GlTooltip,
  },
  directives: {
    SafeHtml,
  },
  props: {
    job: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isHovered: false,
      isJobLogVisible: false,
      isLoadingAction: false,
    };
  },
  computed: {
    canReadBuild() {
      return this.job.userPermissions.readBuild;
    },
    canRetryJob() {
      return this.job.retryable && this.job.userPermissions.updateBuild && !this.isBridgeJob;
    },
    isBridgeJob() {
      return this.job.kind === BRIDGE_KIND;
    },
    jobChevronName() {
      return this.isJobLogVisible ? 'chevron-down' : 'chevron-right';
    },
    jobTrace() {
      if (this.canReadBuild) {
        return this.job?.trace?.htmlSummary || this.$options.i18n.noTraceText;
      }

      return this.$options.i18n.cannotReadBuild;
    },
    parsedJobId() {
      return getIdFromGraphQLId(this.job.id);
    },
    tooltipErrorText() {
      return this.isBridgeJob
        ? this.$options.i18n.cannotRetryTrigger
        : this.$options.i18n.cannotRetry;
    },
    tooltipText() {
      return sprintf(this.$options.i18n.jobActionTooltipText, { jobName: this.job.name });
    },
  },
  methods: {
    setActiveRow() {
      this.isHovered = true;
    },
    resetActiveRow() {
      this.isHovered = false;
    },
    async retryJob() {
      try {
        this.isLoadingAction = true;

        const {
          data: {
            jobRetry: { errors },
          },
        } = await this.$apollo.mutate({
          mutation: RetryMrFailedJobMutation,
          variables: { id: this.job.id },
        });

        if (errors.length > 0) {
          throw new Error(errors[0]);
        }

        this.$emit('job-retried', this.job.name);
      } catch (error) {
        createAlert({ message: error?.message || this.$options.i18n.retryError });
      } finally {
        this.isLoadingAction = false;
      }
    },
    toggleJobLog(event) {
      // Do not toggle the log visibility when clicking on a link
      if (event.target.tagName === 'A') {
        return;
      }
      this.isJobLogVisible = !this.isJobLogVisible;
    },
  },
  i18n: {
    cannotReadBuild: s__("Job|You do not have permission to read this job's log."),
    cannotRetry: s__('Job|You do not have permission to run this job again.'),
    cannotRetryTrigger: s__('Job|You cannot rerun trigger jobs from this list.'),
    jobActionTooltipText: s__('Pipelines|Retry %{jobName} Job'),
    noTraceText: s__('Job|No job log'),
    retry: __('Retry'),
    retryError: __('There was an error while retrying this job'),
  },
};
</script>
<template>
  <div class="container-fluid gl-grid-tpl-rows-auto">
    <div
      class="row gl-my-3 gl-cursor-pointer gl-display-flex gl-align-items-center"
      :aria-pressed="isJobLogVisible"
      role="button"
      tabindex="0"
      data-testid="widget-row"
      @click="toggleJobLog"
      @keyup.enter="toggleJobLog"
      @keyup.space="toggleJobLog"
      @mouseover="setActiveRow"
      @mouseout="resetActiveRow"
    >
      <div class="col-6 gl-text-gray-900 gl-font-weight-bold gl-text-left">
        <gl-icon :name="jobChevronName" />
        <ci-icon :status="job.detailedStatus" />
        {{ job.name }}
      </div>
      <div class="col-2 gl-text-left">{{ job.stage.name }}</div>
      <div class="col-2 gl-text-left">
        <gl-link :href="job.detailedStatus.detailsPath">#{{ parsedJobId }}</gl-link>
      </div>
      <gl-tooltip v-if="!canRetryJob" :target="() => $refs.retryBtn" placement="top">
        {{ tooltipErrorText }}
      </gl-tooltip>
      <div class="col-2 gl-text-right">
        <span ref="retryBtn">
          <gl-button
            :disabled="!canRetryJob"
            icon="retry"
            category="tertiary"
            :loading="isLoadingAction"
            :title="$options.i18n.retry"
            :aria-label="$options.i18n.retry"
            @click.stop="retryJob"
          />
        </span>
      </div>
    </div>
    <div v-if="isJobLogVisible" class="row">
      <pre
        v-safe-html="jobTrace"
        class="gl-bg-gray-900 gl-text-white gl-w-full"
        data-testid="job-log"
      ></pre>
    </div>
  </div>
</template>