pipelines_table_row.js 5.8 KB
Newer Older
1 2 3
/* eslint-disable no-param-reassign */
/* global Vue */

F
Filipa Lacerda 已提交
4 5 6 7 8 9
require('../../vue_pipelines_index/status');
require('../../vue_pipelines_index/pipeline_url');
require('../../vue_pipelines_index/stage');
require('../../vue_pipelines_index/pipeline_actions');
require('../../vue_pipelines_index/time_ago');
require('./commit');
10 11 12 13 14
/**
 * Pipeline table row.
 *
 * Given the received object renders a table row in the pipelines' table.
 */
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(() => {
  window.gl = window.gl || {};
  gl.pipelines = gl.pipelines || {};

  gl.pipelines.PipelinesTableRowComponent = Vue.component('pipelines-table-row-component', {

    props: {
      pipeline: {
        type: Object,
        required: true,
        default: () => ({}),
      },

    },

    components: {
      'commit-component': gl.CommitComponent,
32 33 34 35
      'pipeline-actions': gl.VuePipelineActions,
      'dropdown-stage': gl.VueStage,
      'pipeline-url': gl.VuePipelineUrl,
      'status-scope': gl.VueStatusScope,
36
      'time-ago': gl.VueTimeAgo,
37 38 39 40 41 42 43
    },

    computed: {
      /**
       * If provided, returns the commit tag.
       * Needed to render the commit component column.
       *
44 45 46 47 48 49 50 51
       * This field needs a lot of verification, because of different possible cases:
       *
       * 1. person who is an author of a commit might be a GitLab user
       * 2. if person who is an author of a commit is a GitLab user he/she can have a GitLab avatar
       * 3. If GitLab user does not have avatar he/she might have a Gravatar
       * 4. If committer is not a GitLab User he/she can have a Gravatar
       * 5. We do not have consistent API object in this case
       * 6. We should improve API and the code
52
       *
53 54 55
       * @returns {Object|Undefined}
       */
      commitAuthor() {
56
        let commitAuthorInformation;
57

58
        // 1. person who is an author of a commit might be a GitLab user
59 60 61
        if (this.pipeline &&
          this.pipeline.commit &&
          this.pipeline.commit.author) {
62 63 64 65 66 67 68 69 70 71 72
          // 2. if person who is an author of a commit is a GitLab user
          // he/she can have a GitLab avatar
          if (this.pipeline.commit.author.avatar_url) {
            commitAuthorInformation = this.pipeline.commit.author;

            // 3. If GitLab user does not have avatar he/she might have a Gravatar
          } else if (this.pipeline.commit.author_gravatar_url) {
            commitAuthorInformation = Object.assign({}, this.pipeline.commit.author, {
              avatar_url: this.pipeline.commit.author_gravatar_url,
            });
          }
73 74
        }

75
        // 4. If committer is not a GitLab User he/she can have a Gravatar
76
        if (this.pipeline &&
77 78
          this.pipeline.commit) {
          commitAuthorInformation = {
79 80 81 82 83 84
            avatar_url: this.pipeline.commit.author_gravatar_url,
            web_url: `mailto:${this.pipeline.commit.author_email}`,
            username: this.pipeline.commit.author_name,
          };
        }

85
        return commitAuthorInformation;
86 87
      },

88 89 90 91 92 93 94
      /**
       * If provided, returns the commit tag.
       * Needed to render the commit component column.
       *
       * @returns {String|Undefined}
       */
      commitTag() {
95 96 97 98
        if (this.pipeline.ref &&
          this.pipeline.ref.tag) {
          return this.pipeline.ref.tag;
        }
99 100 101 102 103 104 105
        return undefined;
      },

      /**
       * If provided, returns the commit ref.
       * Needed to render the commit component column.
       *
106
       * Matches `path` prop sent in the API to `ref_url` prop needed
107 108
       * in the commit component.
       *
109 110 111 112 113
       * @returns {Object|Undefined}
       */
      commitRef() {
        if (this.pipeline.ref) {
          return Object.keys(this.pipeline.ref).reduce((accumulator, prop) => {
114 115
            if (prop === 'path') {
              accumulator.ref_url = this.pipeline.ref[prop];
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
            } else {
              accumulator[prop] = this.pipeline.ref[prop];
            }
            return accumulator;
          }, {});
        }

        return undefined;
      },

      /**
       * If provided, returns the commit url.
       * Needed to render the commit component column.
       *
       * @returns {String|Undefined}
       */
      commitUrl() {
        if (this.pipeline.commit &&
          this.pipeline.commit.commit_path) {
          return this.pipeline.commit.commit_path;
        }
        return undefined;
      },

      /**
       * If provided, returns the commit short sha.
       * Needed to render the commit component column.
       *
       * @returns {String|Undefined}
       */
      commitShortSha() {
        if (this.pipeline.commit &&
          this.pipeline.commit.short_id) {
          return this.pipeline.commit.short_id;
        }
        return undefined;
      },

      /**
       * If provided, returns the commit title.
       * Needed to render the commit component column.
       *
       * @returns {String|Undefined}
       */
      commitTitle() {
        if (this.pipeline.commit &&
          this.pipeline.commit.title) {
          return this.pipeline.commit.title;
        }
        return undefined;
      },
    },

    template: `
      <tr class="commit">
F
Filipa Lacerda 已提交
171
        <status-scope :pipeline="pipeline"/>
172

173
        <pipeline-url :pipeline="pipeline"></pipeline-url>
174 175 176 177 178 179 180 181

        <td>
          <commit-component
            :tag="commitTag"
            :commit-ref="commitRef"
            :commit-url="commitUrl"
            :short-sha="commitShortSha"
            :title="commitTitle"
F
Filipa Lacerda 已提交
182
            :author="commitAuthor"/>
183 184 185
        </td>

        <td class="stage-cell">
186 187 188
          <div class="stage-container dropdown js-mini-pipeline-graph"
            v-if="pipeline.details.stages.length > 0"
            v-for="stage in pipeline.details.stages">
F
Filipa Lacerda 已提交
189
            <dropdown-stage :stage="stage"/>
190 191 192
          </div>
        </td>

F
Filipa Lacerda 已提交
193
        <time-ago :pipeline="pipeline"/>
194

F
Filipa Lacerda 已提交
195
        <pipeline-actions :pipeline="pipeline" />
196 197 198 199
      </tr>
    `,
  });
})();