All files / app/assets/javascripts/vue_merge_request_widget/components mr_widget_pipeline.vue

92.59% Statements 25/27
65.51% Branches 19/29
87.5% Functions 14/16
92.59% Lines 25/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300  5x                                                                                                                                                                                 36x 36x     46x     47x     44x         44x           44x           44x     44x     22x 22x 18x   4x 2x   2x     34x     34x 34x 18x   16x 2x   14x     34x             34x                                                                                                                                                                                                                                                                                                    
<script>
/* eslint-disable vue/require-default-prop */
import {
  GlIcon,
  GlLink,
  GlLoadingIcon,
  GlSprintf,
  GlTooltip,
  GlTooltipDirective,
} from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
import { s__, n__ } from '~/locale';
import CiIcon from '~/vue_shared/components/ci_icon/ci_icon.vue';
import { keepLatestDownstreamPipelines } from '~/ci/pipeline_details/utils/parsing_utils';
import PipelineArtifacts from '~/ci/pipelines_page/components/pipelines_artifacts.vue';
import LegacyPipelineMiniGraph from '~/ci/pipeline_mini_graph/legacy_pipeline_mini_graph.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate/tooltip_on_truncate.vue';
import { MT_MERGE_STRATEGY } from '../constants';
 
export default {
  name: 'MRWidgetPipeline',
  components: {
    CiIcon,
    GlLink,
    GlLoadingIcon,
    GlIcon,
    GlSprintf,
    GlTooltip,
    LegacyPipelineMiniGraph,
    PipelineArtifacts,
    TimeAgoTooltip,
    TooltipOnTruncate,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
    SafeHtml,
  },
  props: {
    pipeline: {
      type: Object,
      required: true,
    },
    pipelineCoverageDelta: {
      type: String,
      required: false,
    },
    buildsWithCoverage: {
      type: Array,
      required: false,
      default: () => [],
    },
    // 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,
    },
    ciStatus: {
      type: String,
      required: false,
    },
    pipelineMustSucceed: {
      type: Boolean,
      required: false,
    },
    sourceBranchLink: {
      type: String,
      required: false,
    },
    sourceBranch: {
      type: String,
      required: false,
    },
    mrTroubleshootingDocsPath: {
      type: String,
      required: true,
    },
    ciTroubleshootingDocsPath: {
      type: String,
      required: true,
    },
    mergeStrategy: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    downstreamPipelines() {
      const downstream = this.pipeline.triggered;
      return keepLatestDownstreamPipelines(downstream);
    },
    hasPipeline() {
      return this.pipeline && Object.keys(this.pipeline).length > 0;
    },
    hasCIError() {
      return this.hasPipeline && !this.ciStatus;
    },
    status() {
      return this.pipeline.details && this.pipeline.details.status
        ? this.pipeline.details.status
        : {};
    },
    artifacts() {
      return this.pipeline?.details?.artifacts;
    },
    hasStages() {
      return this.pipeline?.details?.stages?.length > 0;
    },
    hasCommitInfo() {
      return this.pipeline.commit && Object.keys(this.pipeline.commit).length > 0;
    },
    isMergeRequestPipeline() {
      return Boolean(this.pipeline.flags && this.pipeline.flags.merge_request_pipeline);
    },
    showSourceBranch() {
      return Boolean(this.pipeline.ref.branch);
    },
    finishedAt() {
      return this.pipeline?.details?.finished_at;
    },
    coverageDeltaClass() {
      const delta = this.pipelineCoverageDelta;
      if (delta && parseFloat(delta) > 0) {
        return 'text-success';
      }
      if (delta && parseFloat(delta) < 0) {
        return 'text-danger';
      }
      return '';
    },
    pipelineCoverageJobNumberText() {
      return n__('from %d job', 'from %d jobs', this.buildsWithCoverage.length);
    },
    pipelineCoverageTooltipDeltaDescription() {
      const delta = parseFloat(this.pipelineCoverageDelta) || 0;
      if (delta > 0) {
        return s__('Pipeline|This change will increase the overall test coverage if merged.');
      }
      if (delta < 0) {
        return s__('Pipeline|This change will decrease the overall test coverage if merged.');
      }
      return s__('Pipeline|This change will not change the overall test coverage if merged.');
    },
    pipelineCoverageTooltipDescription() {
      return n__(
        'Test coverage value for this pipeline was calculated by the coverage value of %d job.',
        'Test coverage value for this pipeline was calculated by averaging the resulting coverage values of %d jobs.',
        this.buildsWithCoverage.length,
      );
    },
    isMergeTrain() {
      return this.mergeStrategy === MT_MERGE_STRATEGY;
    },
  },
  errorText: s__(
    'Pipeline|Could not retrieve the pipeline status. For troubleshooting steps, read the %{linkStart}documentation%{linkEnd}.',
  ),
  monitoringPipelineText: s__('Pipeline|Checking pipeline status.'),
};
</script>
<template>
  <div class="ci-widget media">
    <template v-if="hasCIError">
      <gl-icon name="status_failed" class="gl-text-red-500" :size="24" />
      <p class="gl-flex-grow-1 gl-ml-5 gl-mb-0" data-testid="ci-error-message">
        <gl-sprintf :message="$options.errorText">
          <template #link="{ content }">
            <gl-link :href="mrTroubleshootingDocsPath">{{ content }}</gl-link>
          </template>
        </gl-sprintf>
      </p>
    </template>
    <template v-else-if="!hasPipeline">
      <gl-loading-icon size="sm" />
      <p
        class="gl-flex-grow-1 gl-display-flex gl-ml-3 gl-mb-0"
        data-testid="monitoring-pipeline-message"
      >
        {{ $options.monitoringPipelineText }}
        <gl-link
          v-gl-tooltip
          :href="ciTroubleshootingDocsPath"
          target="_blank"
          :title="__('Get more information about troubleshooting pipelines')"
          class="gl-display-flex gl-align-items-center gl-ml-2"
        >
          <gl-icon
            name="question-o"
            :aria-label="__('Link to go to GitLab pipeline documentation')"
          />
        </gl-link>
      </p>
    </template>
    <template v-else-if="hasPipeline">
      <ci-icon :status="status" class="gl-align-self-start gl-mt-2 gl-mr-3" />
      <div class="ci-widget-container d-flex">
        <div class="ci-widget-content">
          <div class="media-body">
            <div
              data-testid="pipeline-info-container"
              class="gl-display-flex gl-flex-wrap gl-align-items-center gl-justify-content-space-between"
            >
              <p
                class="mr-pipeline-title gl-align-self-start gl-m-0! gl-mr-3! gl-font-weight-bold gl-text-gray-900"
              >
                {{ pipeline.details.event_type_name }}
                <gl-link :href="pipeline.path" class="pipeline-id" data-testid="pipeline-id"
                  >#{{ pipeline.id }}</gl-link
                >
                {{ pipeline.details.status.label }}
              </p>
              <div
                class="gl-align-items-center gl-display-inline-flex gl-flex-grow-1 gl-justify-content-space-between"
              >
                <legacy-pipeline-mini-graph
                  v-if="pipeline.details.stages"
                  :downstream-pipelines="downstreamPipelines"
                  :is-merge-train="isMergeTrain"
                  :pipeline-path="pipeline.path"
                  :stages="pipeline.details.stages"
                  :upstream-pipeline="pipeline.triggered_by"
                />
                <pipeline-artifacts
                  :pipeline-id="pipeline.id"
                  :artifacts="artifacts"
                  class="gl-ml-3"
                />
              </div>
            </div>
            <p data-testid="pipeline-details-container" class="gl-font-sm gl-text-gray-500 gl-m-0">
              {{ pipeline.details.event_type_name }} {{ pipeline.details.status.label }}
              <template v-if="hasCommitInfo">
                {{ s__('Pipeline|for') }}
                <gl-link
                  :href="pipeline.commit.commit_path"
                  class="commit-sha-container"
                  data-testid="commit-link"
                  >{{ pipeline.commit.short_id }}</gl-link
                >
              </template>
              <template v-if="showSourceBranch">
                {{ s__('Pipeline|on') }}
                <tooltip-on-truncate
                  v-safe-html="sourceBranchLink"
                  :title="sourceBranch"
                  truncate-target="child"
                  class="label-branch label-truncate ref-container"
                />
              </template>
              <template v-if="finishedAt">
                <time-ago-tooltip
                  :time="finishedAt"
                  tooltip-placement="bottom"
                  data-testid="finished-at"
                />
              </template>
            </p>
            <div v-if="pipeline.coverage" class="coverage gl-mt-1" data-testid="pipeline-coverage">
              {{ s__('Pipeline|Test coverage') }} {{ pipeline.coverage }}%
              <span
                v-if="pipelineCoverageDelta"
                ref="pipelineCoverageDelta"
                :class="coverageDeltaClass"
                data-testid="pipeline-coverage-delta"
              >
                ({{ pipelineCoverageDelta }}%)
              </span>
              {{ pipelineCoverageJobNumberText }}
              <span ref="pipelineCoverageQuestion">
                <gl-icon name="question-o" :size="12" />
              </span>
              <gl-tooltip
                :target="() => $refs.pipelineCoverageQuestion"
                data-testid="pipeline-coverage-tooltip"
              >
                {{ pipelineCoverageTooltipDescription }}
                <div
                  v-for="(build, index) in buildsWithCoverage"
                  :key="`${build.name}-${index}`"
                  class="gl-mt-3 gl-text-left gl-px-4"
                >
                  {{ build.name }} ({{ build.coverage }}%)
                </div>
              </gl-tooltip>
              <gl-tooltip
                :target="() => $refs.pipelineCoverageDelta"
                data-testid="pipeline-coverage-delta-tooltip"
              >
                {{ pipelineCoverageTooltipDeltaDescription }}
              </gl-tooltip>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>