Read about our upcoming Code of Conduct on this issue

last_commit.vue 5.29 KB
Newer Older
1
<script>
2
import { GlTooltipDirective, GlLink, GlButton, GlLoadingIcon } from '@gitlab/ui';
3
import defaultAvatarUrl from 'images/no_avatar.png';
4
5
6
7
8
9
10
import { sprintf, s__ } from '~/locale';
import Icon from '../../vue_shared/components/icon.vue';
import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import TimeagoTooltip from '../../vue_shared/components/time_ago_tooltip.vue';
import CiIcon from '../../vue_shared/components/ci_icon.vue';
import ClipboardButton from '../../vue_shared/components/clipboard_button.vue';
import getRefMixin from '../mixins/get_ref';
11
import getProjectPath from '../queries/getProjectPath.query.graphql';
12
13
14
15
16
17
18
19
20
21
22
import pathLastCommit from '../queries/pathLastCommit.query.graphql';

export default {
  components: {
    Icon,
    UserAvatarLink,
    TimeagoTooltip,
    ClipboardButton,
    CiIcon,
    GlLink,
    GlButton,
23
    GlLoadingIcon,
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  mixins: [getRefMixin],
  apollo: {
    projectPath: {
      query: getProjectPath,
    },
    commit: {
      query: pathLastCommit,
      variables() {
        return {
          projectPath: this.projectPath,
          ref: this.ref,
          path: this.currentPath.replace(/^\//, ''),
        };
      },
42
      update: data => {
43
        const pipelines = data.project?.repository?.tree?.lastCommit?.pipelines?.edges;
44
45

        return {
46
47
          ...data.project?.repository?.tree?.lastCommit,
          pipeline: pipelines?.length && pipelines[0].node,
48
49
        };
      },
50
51
52
      context: {
        isSingleRequest: true,
      },
53
54
55
      error(error) {
        throw error;
      },
56
57
58
59
60
61
62
63
64
65
66
67
    },
  },
  props: {
    currentPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      projectPath: '',
68
      commit: null,
69
70
71
72
73
74
      showDescription: false,
    };
  },
  computed: {
    statusTitle() {
      return sprintf(s__('Commits|Commit: %{commitText}'), {
75
        commitText: this.commit.pipeline.detailedStatus.text,
76
77
78
79
80
81
      });
    },
    isLoading() {
      return this.$apollo.queries.commit.loading;
    },
    showCommitId() {
82
      return this.commit.sha.substr(0, 8);
83
84
    },
  },
85
86
87
88
89
  watch: {
    currentPath() {
      this.commit = null;
    },
  },
90
91
92
93
94
  methods: {
    toggleShowDescription() {
      this.showDescription = !this.showDescription;
    },
  },
95
  defaultAvatarUrl,
96
97
98
99
};
</script>

<template>
100
  <div class="info-well d-none d-sm-flex project-last-commit commit p-3">
101
    <gl-loading-icon v-if="isLoading" size="md" color="dark" class="m-auto" />
102
    <template v-else-if="commit">
103
104
105
106
107
108
109
      <user-avatar-link
        v-if="commit.author"
        :link-href="commit.author.webUrl"
        :img-src="commit.author.avatarUrl"
        :img-size="40"
        class="avatar-cell"
      />
110
111
112
      <span v-else class="avatar-cell user-avatar-link">
        <img :src="$options.defaultAvatarUrl" width="40" height="40" class="avatar s40" />
      </span>
113
114
      <div class="commit-detail flex-list">
        <div class="commit-content qa-commit-content">
115
116
117
118
119
          <gl-link
            :href="commit.webUrl"
            :class="{ 'font-italic': !commit.message }"
            class="commit-row-message item-title"
          >
120
121
122
123
124
125
126
127
128
            {{ commit.title }}
          </gl-link>
          <gl-button
            v-if="commit.description"
            :class="{ open: showDescription }"
            :aria-label="__('Show commit description')"
            class="text-expander"
            @click="toggleShowDescription"
          >
129
            <icon name="ellipsis_h" :size="10" />
130
131
132
133
134
135
136
137
138
          </gl-button>
          <div class="committer">
            <gl-link
              v-if="commit.author"
              :href="commit.author.webUrl"
              class="commit-author-link js-user-link"
            >
              {{ commit.author.name }}
            </gl-link>
139
140
141
            <template v-else>
              {{ commit.authorName }}
            </template>
142
            {{ s__('LastCommit|authored') }}
143
144
145
146
            <timeago-tooltip :time="commit.authoredDate" tooltip-placement="bottom" />
          </div>
          <pre
            v-if="commit.description"
147
            :class="{ 'd-block': showDescription }"
148
            class="commit-row-description append-bottom-8"
149
            >{{ commit.description }}</pre
150
151
152
          >
        </div>
        <div class="commit-actions flex-row">
153
          <div v-if="commit.signatureHtml" v-html="commit.signatureHtml"></div>
154
          <div v-if="commit.pipeline" class="ci-status-link">
155
            <gl-link
156
              v-gl-tooltip.left
157
              :href="commit.pipeline.detailedStatus.detailsPath"
158
159
160
161
              :title="statusTitle"
              class="js-commit-pipeline"
            >
              <ci-icon
162
                :status="commit.pipeline.detailedStatus"
163
164
165
166
167
                :size="24"
                :aria-label="statusTitle"
              />
            </gl-link>
          </div>
168
169
170
171
172
173
          <div class="commit-sha-group d-flex">
            <div class="label label-monospace monospace">
              {{ showCommitId }}
            </div>
            <clipboard-button
              :text="commit.sha"
174
              :title="__('Copy commit SHA')"
175
176
              tooltip-placement="bottom"
            />
177
178
179
          </div>
        </div>
      </div>
180
    </template>
181
182
  </div>
</template>
183
184
185
186
187
188

<style scoped>
.commit {
  min-height: 4.75rem;
}
</style>