sidebar.vue 7.6 KB
Newer Older
1
<script>
2 3 4 5 6 7 8 9 10 11 12
import _ from 'underscore';
import { mapActions, mapState } from 'vuex';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { timeIntervalInWords } from '~/lib/utils/datetime_utility';
import Icon from '~/vue_shared/components/icon.vue';
import DetailRow from './sidebar_detail_row.vue';
import ArtifactsBlock from './artifacts_block.vue';
import TriggerBlock from './trigger_block.vue';
import CommitBlock from './commit_block.vue';
import StagesDropdown from './stages_dropdown.vue';
import JobsContainer from './jobs_container.vue';
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
export default {
  name: 'JobSidebar',
  components: {
    ArtifactsBlock,
    CommitBlock,
    DetailRow,
    Icon,
    TriggerBlock,
    StagesDropdown,
    JobsContainer,
  },
  mixins: [timeagoMixin],
  props: {
    runnerHelpUrl: {
      type: String,
      required: false,
      default: '',
31
    },
32 33
  },
  computed: {
34
    ...mapState(['job', 'stages', 'jobs', 'selectedStage', 'isLoadingStages']),
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
    coverage() {
      return `${this.job.coverage}%`;
    },
    duration() {
      return timeIntervalInWords(this.job.duration);
    },
    queued() {
      return timeIntervalInWords(this.job.queued);
    },
    runnerId() {
      return `${this.job.runner.description} (#${this.job.runner.id})`;
    },
    retryButtonClass() {
      let className =
        'js-retry-button float-right btn btn-retry d-none d-md-block d-lg-block d-xl-block';
      className +=
        this.job.status && this.job.recoverable ? ' btn-primary' : ' btn-inverted-secondary';
      return className;
    },
    hasTimeout() {
      return this.job.metadata != null && this.job.metadata.timeout_human_readable !== null;
    },
    timeout() {
      if (this.job.metadata == null) {
        return '';
      }
61

62 63 64 65
      let t = this.job.metadata.timeout_human_readable;
      if (this.job.metadata.timeout_source !== '') {
        t += ` (from ${this.job.metadata.timeout_source})`;
      }
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
      return t;
    },
    renderBlock() {
      return (
        this.job.merge_request ||
        this.job.duration ||
        this.job.finished_data ||
        this.job.erased_at ||
        this.job.queued ||
        this.job.runner ||
        this.job.coverage ||
        this.job.tags.length ||
        this.job.cancel_path
      );
    },
    hasArtifact() {
      return !_.isEmpty(this.job.artifact);
    },
    hasTriggers() {
      return !_.isEmpty(this.job.trigger);
    },
    hasStages() {
      return (
        (this.job &&
          this.job.pipeline &&
          this.job.pipeline.stages &&
          this.job.pipeline.stages.length > 0) ||
        false
      );
96
    },
97
    commit() {
98
      return this.job.pipeline && this.job.pipeline.commit ? this.job.pipeline.commit : {};
99
    },
100 101
  },
  methods: {
102
    ...mapActions(['fetchJobsForStage', 'toggleSidebar']),
103 104
  },
};
105 106 107
</script>
<template>
  <aside
108
    class="right-sidebar build-sidebar"
109 110 111 112 113
    data-offset-top="101"
    data-spy="affix"
  >
    <div class="sidebar-container">
      <div class="blocks-container">
114 115 116 117 118 119 120 121 122 123
        <div class="block">
          <strong class="inline prepend-top-8">
            {{ job.name }}
          </strong>
          <a
            v-if="job.retry_path"
            :class="retryButtonClass"
            :href="job.retry_path"
            data-method="post"
            rel="nofollow"
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
            {{ __('Retry') }}
          </a>
          <a
            v-if="job.terminal_path"
            :href="job.terminal_path"
            class="js-terminal-link pull-right btn btn-primary
      btn-inverted visible-md-block visible-lg-block"
            target="_blank"
          >
            {{ __('Debug') }}
            <icon name="external-link" />
          </a>
          <button
            :aria-label="__('Toggle Sidebar')"
            type="button"
            class="btn btn-blank gutter-toggle
        float-right d-block d-md-none js-sidebar-build-toggle"
            @click="toggleSidebar"
          >
            <i
              aria-hidden="true"
              data-hidden="true"
              class="fa fa-angle-double-right"
            ></i>
          </button>
        </div>
        <div
          v-if="job.retry_path || job.new_issue_path"
          class="block retry-link"
        >
          <a
            v-if="job.new_issue_path"
            :href="job.new_issue_path"
            class="js-new-issue btn btn-success btn-inverted"
          >
            {{ __('New issue') }}
          </a>
          <a
            v-if="job.retry_path"
            :href="job.retry_path"
            class="js-retry-job btn btn-inverted-secondary"
            data-method="post"
            rel="nofollow"
          >
            {{ __('Retry') }}
          </a>
        </div>
        <div :class="{ block : renderBlock }">
          <p
            v-if="job.merge_request"
            class="build-detail-row js-job-mr"
          >
            <span class="build-light-text">
              {{ __('Merge Request:') }}
            </span>
            <a :href="job.merge_request.path">
              !{{ job.merge_request.iid }}
182
            </a>
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
          </p>

          <detail-row
            v-if="job.duration"
            :value="duration"
            class="js-job-duration"
            title="Duration"
          />
          <detail-row
            v-if="job.finished_at"
            :value="timeFormated(job.finished_at)"
            class="js-job-finished"
            title="Finished"
          />
          <detail-row
            v-if="job.erased_at"
            :value="timeFormated(job.erased_at)"
            class="js-job-erased"
            title="Erased"
          />
          <detail-row
            v-if="job.queued"
            :value="queued"
            class="js-job-queued"
            title="Queued"
          />
          <detail-row
            v-if="hasTimeout"
            :help-url="runnerHelpUrl"
            :value="timeout"
            class="js-job-timeout"
            title="Timeout"
          />
          <detail-row
            v-if="job.runner"
            :value="runnerId"
            class="js-job-runner"
            title="Runner"
          />
          <detail-row
            v-if="job.coverage"
            :value="coverage"
            class="js-job-coverage"
            title="Coverage"
          />
          <p
            v-if="job.tags.length"
            class="build-detail-row js-job-tags"
          >
            <span class="build-light-text">
              {{ __('Tags:') }}
            </span>
            <span
              v-for="(tag, i) in job.tags"
              :key="i"
              class="label label-primary">
              {{ tag }}
            </span>
          </p>

          <div
            v-if="job.cancel_path"
            class="btn-group prepend-top-5"
            role="group">
247
            <a
248 249
              :href="job.cancel_path"
              class="js-cancel-job btn btn-sm btn-default"
250 251 252
              data-method="post"
              rel="nofollow"
            >
253
              {{ __('Cancel') }}
254 255
            </a>
          </div>
256
        </div>
257

258 259 260 261 262 263 264 265 266 267 268 269 270
        <artifacts-block
          v-if="hasArtifact"
          :artifact="job.artifact"
        />
        <trigger-block
          v-if="hasTriggers"
          :trigger="job.trigger"
        />
        <commit-block
          :is-last-block="hasStages"
          :commit="commit"
          :merge-request="job.merge_request"
        />
271

272
        <stages-dropdown
273
          v-if="!isLoadingStages"
274 275 276 277
          :stages="stages"
          :pipeline="job.pipeline"
          :selected-stage="selectedStage"
          @requestSidebarStageDropdown="fetchJobsForStage"
278 279 280 281
        />
      </div>

      <jobs-container
282
        v-if="jobs.length"
283 284 285 286 287 288
        :jobs="jobs"
        :job-id="job.id"
      />
    </div>
  </aside>
</template>