mr_widget_pipeline.vue 2.9 KB
Newer Older
1 2 3 4 5 6 7
<script>
  import pipelineStage from '../../pipelines/components/stage.vue';
  import ciIcon from '../../vue_shared/components/ci_icon.vue';
  import icon from '../../vue_shared/components/icon.vue';

  export default {
    name: 'MRWidgetPipeline',
F
Filipa Lacerda 已提交
8 9 10 11 12
    components: {
      pipelineStage,
      ciIcon,
      icon,
    },
13 14 15 16 17 18 19 20 21 22
    props: {
      pipeline: {
        type: Object,
        required: true,
      },
      // This prop needs to be camelCase, html attributes are case insensive
      // https://vuejs.org/v2/guide/components.html#camelCase-vs-kebab-case
      hasCi: {
        type: Boolean,
        required: false,
F
Filipa Lacerda 已提交
23
        default: false,
24 25 26 27
      },
      ciStatus: {
        type: String,
        required: false,
F
Filipa Lacerda 已提交
28
        default: '',
29 30 31 32 33 34 35
      },
    },
    computed: {
      hasPipeline() {
        return this.pipeline && Object.keys(this.pipeline).length > 0;
      },
      hasCIError() {
F
Filipa Lacerda 已提交
36
        return this.hasCi && this.ciStatus !== '';
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
      },
      status() {
        return this.pipeline.details &&
          this.pipeline.details.status ? this.pipeline.details.status : {};
      },
      hasStages() {
        return this.pipeline.details &&
          this.pipeline.details.stages &&
          this.pipeline.details.stages.length;
      },
    },
  };
</script>

<template>
  <div
    v-if="hasPipeline || hasCIError"
    class="mr-widget-heading">
    <div class="ci-widget media">
      <template v-if="hasCIError">
        <div class="ci-status-icon ci-status-icon-failed ci-error js-ci-error append-right-10">
          <icon name="status_failed" />
        </div>
        <div class="media-body">
          Could not connect to the CI server. Please check your settings and try again
        </div>
      </template>
      <template v-else-if="hasPipeline">
        <a
          class="append-right-10"
F
Filipa Lacerda 已提交
67 68
          :href="status.details_path"
        >
69 70 71 72 73 74 75
          <ci-icon :status="status" />
        </a>

        <div class="media-body">
          Pipeline
          <a
            :href="pipeline.path"
F
Filipa Lacerda 已提交
76 77 78
            class="pipeline-id"
          >
            #{{ pipeline.id }}
79 80
          </a>

F
Filipa Lacerda 已提交
81
          {{ pipeline.details.status.label }} for
82 83 84

          <a
            :href="pipeline.commit.commit_path"
F
Filipa Lacerda 已提交
85 86 87
            class="commit-sha js-commit-link"
          >
          {{ pipeline.commit.short_id }}</a>.
88 89

          <span class="mr-widget-pipeline-graph">
F
Filipa Lacerda 已提交
90 91 92 93
            <span
              class="stage-cell"
              v-if="hasStages"
            >
94 95 96
              <div
                v-for="(stage, i) in pipeline.details.stages"
                :key="i"
F
Filipa Lacerda 已提交
97 98
                class="stage-container dropdown js-mini-pipeline-graph"
              >
99 100 101 102 103 104
                <pipeline-stage :stage="stage" />
              </div>
            </span>
          </span>

          <template v-if="pipeline.coverage">
F
Filipa Lacerda 已提交
105
            Coverage {{ pipeline.coverage }}%
106 107 108 109 110 111
          </template>
        </div>
      </template>
    </div>
  </div>
</template>