2017-06-14 09:04:50 -04:00
|
|
|
<script>
|
2020-03-23 17:09:46 -04:00
|
|
|
import { isString, isEmpty } from 'lodash';
|
2020-08-24 11:10:11 -04:00
|
|
|
import { GlTooltipDirective, GlLink, GlIcon } from '@gitlab/ui';
|
2019-07-08 04:26:37 -04:00
|
|
|
import { __, sprintf } from '~/locale';
|
2019-06-12 02:50:05 -04:00
|
|
|
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate.vue';
|
2018-04-19 11:07:11 -04:00
|
|
|
import UserAvatarLink from './user_avatar/user_avatar_link.vue';
|
2017-06-14 09:04:50 -04:00
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
export default {
|
|
|
|
directives: {
|
2018-11-08 10:02:49 -05:00
|
|
|
GlTooltip: GlTooltipDirective,
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
UserAvatarLink,
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2019-03-20 11:39:27 -04:00
|
|
|
GlLink,
|
2019-06-12 02:50:05 -04:00
|
|
|
TooltipOnTruncate,
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
/**
|
2018-10-30 06:53:01 -04:00
|
|
|
* Indicates the existence of a tag.
|
2020-08-24 11:10:11 -04:00
|
|
|
* Used to render the correct GlIcon, if true will render `tag` GlIcon,
|
2018-04-19 11:07:11 -04:00
|
|
|
* if false will render a svg sprite fork icon
|
|
|
|
*/
|
|
|
|
tag: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-01-04 19:18:35 -05:00
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
/**
|
|
|
|
* If provided is used to render the branch name and url.
|
|
|
|
* Should contain the following properties:
|
|
|
|
* name
|
|
|
|
* ref_url
|
|
|
|
*/
|
|
|
|
commitRef: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
2019-03-20 11:39:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided, is used the render the MR IID and link
|
|
|
|
* in place of the branch name. Must contains the
|
|
|
|
* following properties:
|
|
|
|
* - iid (number)
|
|
|
|
* - path (non-empty string)
|
|
|
|
*
|
|
|
|
* May optionally contain the following properties:
|
|
|
|
* - title (string): used in a tooltip if provided
|
|
|
|
*
|
|
|
|
* Any additional properties are ignored.
|
|
|
|
*/
|
|
|
|
mergeRequestRef: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: undefined,
|
2020-12-23 16:10:24 -05:00
|
|
|
validator: (ref) =>
|
2020-03-23 17:09:46 -04:00
|
|
|
ref === undefined || (Number.isFinite(ref.iid) && isString(ref.path) && !isEmpty(ref.path)),
|
2019-03-20 11:39:27 -04:00
|
|
|
},
|
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
/**
|
|
|
|
* Used to link to the commit sha.
|
|
|
|
*/
|
|
|
|
commitUrl: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
2018-01-04 19:18:35 -05:00
|
|
|
},
|
2017-06-14 09:04:50 -04:00
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
/**
|
|
|
|
* Used to show the commit short sha that links to the commit url.
|
|
|
|
*/
|
|
|
|
shortSha: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* If provided shows the commit tile.
|
|
|
|
*/
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* If provided renders information about the author of the commit.
|
|
|
|
* When provided should include:
|
|
|
|
* `avatar_url` to render the avatar icon
|
|
|
|
* `web_url` to link to user profile
|
|
|
|
* `username` to render alt and title tags
|
|
|
|
*/
|
|
|
|
author: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
2019-03-20 11:39:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether or not to show the branch/MR ref info
|
|
|
|
*/
|
|
|
|
showRefInfo: {
|
2018-04-19 11:07:11 -04:00
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
2017-06-14 09:04:50 -04:00
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
/**
|
2021-01-12 16:10:47 -05:00
|
|
|
* Determines if we should render the ref info section based
|
2018-04-19 11:07:11 -04:00
|
|
|
*/
|
2019-03-20 11:39:27 -04:00
|
|
|
shouldShowRefInfo() {
|
|
|
|
return this.showRefInfo && (this.commitRef || this.mergeRequestRef);
|
2017-06-14 09:04:50 -04:00
|
|
|
},
|
2019-03-20 11:39:27 -04:00
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
/**
|
|
|
|
* Used to verify if all the properties needed to render the commit
|
|
|
|
* author section were provided.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasAuthor() {
|
|
|
|
return this.author && this.author.avatar_url && this.author.path && this.author.username;
|
2017-08-31 06:38:23 -04:00
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
/**
|
|
|
|
* If information about the author is provided will return a string
|
|
|
|
* to be rendered as the alt attribute of the img tag.
|
|
|
|
*
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
userImageAltDescription() {
|
2019-07-08 04:26:37 -04:00
|
|
|
return this.author && this.author.username
|
|
|
|
? sprintf(__("%{username}'s avatar"), { username: this.author.username })
|
|
|
|
: null;
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
2021-02-11 16:09:00 -05:00
|
|
|
refUrl() {
|
|
|
|
return this.commitRef.ref_url || this.commitRef.path;
|
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
|
|
|
};
|
2017-06-14 09:04:50 -04:00
|
|
|
</script>
|
|
|
|
<template>
|
2019-04-25 14:49:13 -04:00
|
|
|
<div class="branch-commit cgray">
|
2019-03-20 11:39:27 -04:00
|
|
|
<template v-if="shouldShowRefInfo">
|
2020-09-29 05:09:49 -04:00
|
|
|
<div class="icon-container gl-display-inline-block">
|
2020-08-24 11:10:11 -04:00
|
|
|
<gl-icon v-if="tag" name="tag" />
|
|
|
|
<gl-icon v-else-if="mergeRequestRef" name="git-merge" />
|
|
|
|
<gl-icon v-else name="branch" />
|
2017-10-18 12:30:31 -04:00
|
|
|
</div>
|
2017-06-14 09:04:50 -04:00
|
|
|
|
2019-03-20 11:39:27 -04:00
|
|
|
<gl-link
|
|
|
|
v-if="mergeRequestRef"
|
|
|
|
v-gl-tooltip
|
|
|
|
:href="mergeRequestRef.path"
|
|
|
|
:title="mergeRequestRef.title"
|
|
|
|
class="ref-name"
|
2019-08-06 05:52:50 -04:00
|
|
|
>{{ mergeRequestRef.iid }}</gl-link
|
2019-03-20 11:39:27 -04:00
|
|
|
>
|
|
|
|
<gl-link
|
|
|
|
v-else
|
|
|
|
v-gl-tooltip
|
2021-02-11 16:09:00 -05:00
|
|
|
:href="refUrl"
|
2019-03-20 11:39:27 -04:00
|
|
|
:title="commitRef.name"
|
|
|
|
class="ref-name"
|
2021-02-11 16:09:00 -05:00
|
|
|
data-testid="ref-name"
|
2019-08-06 05:52:50 -04:00
|
|
|
>{{ commitRef.name }}</gl-link
|
2019-03-20 11:39:27 -04:00
|
|
|
>
|
2017-10-18 12:30:31 -04:00
|
|
|
</template>
|
2020-08-24 11:10:11 -04:00
|
|
|
<gl-icon name="commit" class="commit-icon js-commit-icon" />
|
2017-06-14 09:04:50 -04:00
|
|
|
|
2019-08-06 05:52:50 -04:00
|
|
|
<gl-link :href="commitUrl" class="commit-sha mr-0">{{ shortSha }}</gl-link>
|
2017-06-14 09:04:50 -04:00
|
|
|
|
2019-08-06 05:52:50 -04:00
|
|
|
<div class="commit-title">
|
|
|
|
<span v-if="title" class="flex-truncate-parent">
|
2017-06-14 09:04:50 -04:00
|
|
|
<user-avatar-link
|
|
|
|
v-if="hasAuthor"
|
|
|
|
:link-href="author.path"
|
|
|
|
:img-src="author.avatar_url"
|
|
|
|
:img-alt="userImageAltDescription"
|
|
|
|
:tooltip-text="author.username"
|
2019-08-06 05:52:50 -04:00
|
|
|
class="avatar-image-container text-decoration-none"
|
2017-06-14 09:04:50 -04:00
|
|
|
/>
|
2019-08-06 05:52:50 -04:00
|
|
|
<tooltip-on-truncate :title="title" class="flex-truncate-child">
|
|
|
|
<gl-link :href="commitUrl" class="commit-row-message cgray">{{ title }}</gl-link>
|
|
|
|
</tooltip-on-truncate>
|
|
|
|
</span>
|
2019-07-08 04:26:37 -04:00
|
|
|
<span v-else>{{ __("Can't find HEAD commit for this branch") }}</span>
|
2017-06-14 09:04:50 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|