debian-mirror-gitlab/app/assets/javascripts/repository/components/last_commit.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

211 lines
6.3 KiB
Vue
Raw Normal View History

2019-09-30 21:07:59 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlTooltipDirective, GlLink, GlButton, GlButtonGroup, GlLoadingIcon } from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
2019-12-26 22:10:19 +05:30
import defaultAvatarUrl from 'images/no_avatar.png';
2021-01-03 14:25:43 +05:30
import pathLastCommitQuery from 'shared_queries/repository/path_last_commit.query.graphql';
2019-09-30 21:07:59 +05:30
import { sprintf, s__ } from '~/locale';
2022-06-21 17:19:12 +05:30
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2022-07-16 23:28:13 +05:30
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
2023-05-27 22:25:52 +05:30
import SignatureBadge from '~/commit/components/signature_badge.vue';
2019-09-30 21:07:59 +05:30
import getRefMixin from '../mixins/get_ref';
2020-10-24 23:57:45 +05:30
import projectPathQuery from '../queries/project_path.query.graphql';
2019-09-30 21:07:59 +05:30
export default {
components: {
UserAvatarLink,
TimeagoTooltip,
ClipboardButton,
CiIcon,
2021-01-03 14:25:43 +05:30
GlButton,
GlButtonGroup,
2019-09-30 21:07:59 +05:30
GlLink,
GlLoadingIcon,
2022-07-16 23:28:13 +05:30
UserAvatarImage,
2023-05-27 22:25:52 +05:30
SignatureBadge,
2019-09-30 21:07:59 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
2023-03-04 22:38:38 +05:30
SafeHtml,
2019-09-30 21:07:59 +05:30
},
mixins: [getRefMixin],
apollo: {
projectPath: {
2020-10-24 23:57:45 +05:30
query: projectPathQuery,
2019-09-30 21:07:59 +05:30
},
commit: {
2020-10-24 23:57:45 +05:30
query: pathLastCommitQuery,
2019-09-30 21:07:59 +05:30
variables() {
return {
projectPath: this.projectPath,
ref: this.ref,
path: this.currentPath.replace(/^\//, ''),
};
},
2021-03-08 18:12:59 +05:30
update: (data) => {
2022-08-13 15:12:31 +05:30
const lastCommit = data.project?.repository?.paginatedTree?.nodes[0]?.lastCommit;
const pipelines = lastCommit?.pipelines?.edges;
2019-12-26 22:10:19 +05:30
return {
2022-08-13 15:12:31 +05:30
...lastCommit,
2020-03-13 15:44:24 +05:30
pipeline: pipelines?.length && pipelines[0].node,
2019-12-26 22:10:19 +05:30
};
},
2019-09-30 21:07:59 +05:30
context: {
isSingleRequest: true,
},
2020-03-13 15:44:24 +05:30
error(error) {
throw error;
},
2019-09-30 21:07:59 +05:30
},
},
props: {
currentPath: {
type: String,
required: false,
default: '',
},
},
data() {
return {
projectPath: '',
2020-03-13 15:44:24 +05:30
commit: null,
2019-09-30 21:07:59 +05:30
showDescription: false,
};
},
computed: {
statusTitle() {
2020-04-08 14:13:33 +05:30
return sprintf(s__('PipelineStatusTooltip|Pipeline: %{ciStatus}'), {
ciStatus: this.commit.pipeline.detailedStatus.text,
2019-09-30 21:07:59 +05:30
});
},
isLoading() {
return this.$apollo.queries.commit.loading;
},
showCommitId() {
2020-03-13 15:44:24 +05:30
return this.commit?.sha?.substr(0, 8);
},
2021-03-08 18:12:59 +05:30
commitDescription() {
// Strip the newline at the beginning
return this.commit?.descriptionHtml?.replace(/^&#x000A;/, '');
},
2020-03-13 15:44:24 +05:30
},
watch: {
currentPath() {
this.commit = null;
2019-09-30 21:07:59 +05:30
},
},
methods: {
toggleShowDescription() {
this.showDescription = !this.showDescription;
},
},
2019-12-26 22:10:19 +05:30
defaultAvatarUrl,
2021-12-11 22:18:48 +05:30
safeHtmlConfig: {
ADD_TAGS: ['gl-emoji'],
},
2019-09-30 21:07:59 +05:30
};
</script>
<template>
2022-07-16 23:28:13 +05:30
<div class="well-segment commit gl-p-5 gl-w-full gl-display-flex">
2022-07-23 23:45:48 +05:30
<gl-loading-icon v-if="isLoading" size="lg" color="dark" class="m-auto" />
2020-03-13 15:44:24 +05:30
<template v-else-if="commit">
2019-09-30 21:07:59 +05:30
<user-avatar-link
v-if="commit.author"
2020-10-24 23:57:45 +05:30
:link-href="commit.author.webPath"
2019-09-30 21:07:59 +05:30
:img-src="commit.author.avatarUrl"
2022-07-16 23:28:13 +05:30
:img-size="32"
class="gl-my-2 gl-mr-4"
/>
<user-avatar-image
v-else
class="gl-my-2 gl-mr-4"
:img-src="commit.authorGravatar || $options.defaultAvatarUrl"
:size="32"
2019-09-30 21:07:59 +05:30
/>
2022-08-13 15:12:31 +05:30
<div
class="commit-detail flex-list gl-display-flex gl-justify-content-space-between gl-align-items-flex-start gl-flex-grow-1 gl-min-w-0"
>
2022-10-11 01:57:18 +05:30
<div class="commit-content" data-qa-selector="commit_content">
2020-03-13 15:44:24 +05:30
<gl-link
2021-12-11 22:18:48 +05:30
v-safe-html:[$options.safeHtmlConfig]="commit.titleHtml"
2020-10-24 23:57:45 +05:30
:href="commit.webPath"
2020-03-13 15:44:24 +05:30
:class="{ 'font-italic': !commit.message }"
class="commit-row-message item-title"
2020-05-24 23:13:21 +05:30
/>
2021-01-03 14:25:43 +05:30
<gl-button
2020-10-24 23:57:45 +05:30
v-if="commit.descriptionHtml"
2022-04-04 11:22:00 +05:30
v-gl-tooltip
2019-09-30 21:07:59 +05:30
:class="{ open: showDescription }"
2022-04-04 11:22:00 +05:30
:title="__('Toggle commit description')"
:aria-label="__('Toggle commit description')"
2022-10-11 01:57:18 +05:30
:selected="showDescription"
2021-01-03 14:25:43 +05:30
class="text-expander gl-vertical-align-bottom!"
icon="ellipsis_h"
2019-09-30 21:07:59 +05:30
@click="toggleShowDescription"
2021-01-03 14:25:43 +05:30
/>
2019-09-30 21:07:59 +05:30
<div class="committer">
<gl-link
v-if="commit.author"
2020-10-24 23:57:45 +05:30
:href="commit.author.webPath"
2019-09-30 21:07:59 +05:30
class="commit-author-link js-user-link"
>
2021-01-29 00:20:46 +05:30
{{ commit.author.name }}</gl-link
>
2019-12-26 22:10:19 +05:30
<template v-else>
{{ commit.authorName }}
</template>
2019-12-21 20:55:43 +05:30
{{ s__('LastCommit|authored') }}
2019-09-30 21:07:59 +05:30
<timeago-tooltip :time="commit.authoredDate" tooltip-placement="bottom" />
</div>
<pre
2021-03-08 18:12:59 +05:30
v-if="commitDescription"
2021-12-11 22:18:48 +05:30
v-safe-html:[$options.safeHtmlConfig]="commitDescription"
2019-12-26 22:10:19 +05:30
:class="{ 'd-block': showDescription }"
2022-11-25 23:54:43 +05:30
class="commit-row-description gl-mb-3 gl-white-space-pre-line"
2020-10-24 23:57:45 +05:30
></pre>
2019-09-30 21:07:59 +05:30
</div>
2022-07-16 23:28:13 +05:30
<div class="gl-flex-grow-1"></div>
<div
class="commit-actions gl-display-flex gl-flex-align gl-align-items-center gl-flex-direction-row"
>
2023-05-27 22:25:52 +05:30
<signature-badge v-if="commit.signature" :signature="commit.signature" />
2019-12-26 22:10:19 +05:30
<div v-if="commit.pipeline" class="ci-status-link">
<gl-link
v-gl-tooltip.left
:href="commit.pipeline.detailedStatus.detailsPath"
:title="statusTitle"
class="js-commit-pipeline"
>
<ci-icon
:status="commit.pipeline.detailedStatus"
:size="24"
:aria-label="statusTitle"
/>
</gl-link>
</div>
2021-01-03 14:25:43 +05:30
<gl-button-group class="gl-ml-4 js-commit-sha-group">
2022-08-27 11:52:29 +05:30
<gl-button label class="gl-font-monospace" data-testid="last-commit-id-label">{{
showCommitId
}}</gl-button>
2019-09-30 21:07:59 +05:30
<clipboard-button
:text="commit.sha"
2019-12-21 20:55:43 +05:30
:title="__('Copy commit SHA')"
2021-01-03 14:25:43 +05:30
class="input-group-text"
2019-09-30 21:07:59 +05:30
/>
2021-01-03 14:25:43 +05:30
</gl-button-group>
2019-09-30 21:07:59 +05:30
</div>
</div>
</template>
</div>
</template>
2019-12-26 22:10:19 +05:30
<style scoped>
.commit {
min-height: 4.75rem;
}
</style>