diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 09:15:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 09:15:26 +0300 |
commit | 4d84411275a3e21204078ba6e39ccbf612b528f0 (patch) | |
tree | eb45ee5075eccacc84038a58a6279f8fe14675c3 | |
parent | 4f44872f804dd1087a9a166cb5c6a14c70183f17 (diff) |
Add latest changes from gitlab-org/gitlab@master
6 files changed, 180 insertions, 2 deletions
diff --git a/app/assets/javascripts/environments/components/commit.vue b/app/assets/javascripts/environments/components/commit.vue new file mode 100644 index 00000000000..54b94480685 --- /dev/null +++ b/app/assets/javascripts/environments/components/commit.vue @@ -0,0 +1,54 @@ +<script> +import { GlAvatar, GlAvatarLink, GlLink, GlTooltipDirective as GlTooltip } from '@gitlab/ui'; +import { escape } from 'lodash'; + +export default { + components: { + GlAvatar, + GlAvatarLink, + GlLink, + }, + directives: { + GlTooltip, + }, + props: { + commit: { + required: true, + type: Object, + }, + }, + computed: { + commitMessage() { + return this.commit?.message; + }, + commitAuthorPath() { + // eslint-disable-next-line @gitlab/require-i18n-strings + return this.commit?.author?.path || `mailto:${escape(this.commit?.authorEmail)}`; + }, + commitAuthorAvatar() { + return this.commit?.author?.avatarUrl || this.commit?.authorGravatarUrl; + }, + commitAuthor() { + return this.commit?.author?.name || this.commit?.authorName; + }, + commitPath() { + return this.commit?.commitPath; + }, + }, +}; +</script> +<template> + <div data-testid="deployment-commit" class="gl-display-flex gl-align-items-center"> + <gl-avatar-link v-gl-tooltip :title="commitAuthor" :href="commitAuthorPath"> + <gl-avatar :size="16" :src="commitAuthorAvatar" /> + </gl-avatar-link> + <gl-link + v-gl-tooltip + :title="commitMessage" + :href="commitPath" + class="gl-ml-3 gl-str-truncated" + > + {{ commitMessage }} + </gl-link> + </div> +</template> diff --git a/app/assets/javascripts/environments/components/deployment.vue b/app/assets/javascripts/environments/components/deployment.vue index b36d0d5f2e0..b3a27628272 100644 --- a/app/assets/javascripts/environments/components/deployment.vue +++ b/app/assets/javascripts/environments/components/deployment.vue @@ -5,10 +5,12 @@ import { __, s__ } from '~/locale'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import DeploymentStatusBadge from './deployment_status_badge.vue'; +import Commit from './commit.vue'; export default { components: { ClipboardButton, + Commit, DeploymentStatusBadge, GlBadge, GlButton, @@ -41,7 +43,7 @@ export default { return this.deployment?.iid; }, shortSha() { - return this.deployment?.commit?.shortId; + return this.commit?.shortId; }, createdAt() { return this.deployment?.createdAt; @@ -57,6 +59,9 @@ export default { detailsButtonClasses() { return this.isMobile ? 'gl-sr-only' : ''; }, + commit() { + return this.deployment?.commit; + }, }, methods: { toggleCollapse() { @@ -143,6 +148,7 @@ export default { {{ detailsButton.text }} </gl-button> </div> + <commit v-if="commit" :commit="commit" class="gl-mt-3" /> <gl-collapse :visible="visible" /> </div> </template> diff --git a/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb b/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb new file mode 100644 index 00000000000..252b4a01d04 --- /dev/null +++ b/db/post_migrate/20220201141705_cleanup_background_migration_populate_test_reports_issue_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CleanupBackgroundMigrationPopulateTestReportsIssueId < Gitlab::Database::Migration[1.0] + disable_ddl_transaction! + + MIGRATION = 'PopulateTestReportsIssueId' + + def up + finalize_background_migration(MIGRATION) + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20220201141705 b/db/schema_migrations/20220201141705 new file mode 100644 index 00000000000..92835993156 --- /dev/null +++ b/db/schema_migrations/20220201141705 @@ -0,0 +1 @@ +9eb0c4609fbec79370215d05a9a1faf4208b9dcc2bfeb861feeb7c9f354489ab
\ No newline at end of file diff --git a/spec/frontend/environments/commit_spec.js b/spec/frontend/environments/commit_spec.js new file mode 100644 index 00000000000..32eb4b77528 --- /dev/null +++ b/spec/frontend/environments/commit_spec.js @@ -0,0 +1,71 @@ +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import Commit from '~/environments/components/commit.vue'; +import { resolvedEnvironment } from './graphql/mock_data'; + +describe('~/environments/components/commit.vue', () => { + let commit; + let wrapper; + + beforeEach(() => { + commit = resolvedEnvironment.lastDeployment.commit; + }); + + const createWrapper = ({ propsData = {} } = {}) => + mountExtended(Commit, { + propsData: { + commit, + ...propsData, + }, + }); + + afterEach(() => { + wrapper?.destroy(); + }); + + describe('with gitlab user', () => { + beforeEach(() => { + wrapper = createWrapper(); + }); + + it('links to the user profile', () => { + const link = wrapper.findByRole('link', { name: commit.author.name }); + expect(link.attributes('href')).toBe(commit.author.path); + }); + + it('displays the user avatar', () => { + const avatar = wrapper.findByRole('img', { name: 'avatar' }); + expect(avatar.attributes('src')).toBe(commit.author.avatarUrl); + }); + + it('links the commit message to the commit', () => { + const message = wrapper.findByRole('link', { name: commit.message }); + + expect(message.attributes('href')).toBe(commit.commitPath); + }); + }); + describe('without gitlab user', () => { + beforeEach(() => { + commit = { + ...commit, + author: null, + }; + wrapper = createWrapper(); + }); + + it('links to the user profile', () => { + const link = wrapper.findByRole('link', { name: commit.authorName }); + expect(link.attributes('href')).toBe(`mailto:${commit.authorEmail}`); + }); + + it('displays the user avatar', () => { + const avatar = wrapper.findByRole('img', { name: 'avatar' }); + expect(avatar.attributes('src')).toBe(commit.authorGravatarUrl); + }); + + it('displays the commit message', () => { + const message = wrapper.findByRole('link', { name: commit.message }); + + expect(message.attributes('href')).toBe(commit.commitPath); + }); + }); +}); diff --git a/spec/frontend/environments/deployment_spec.js b/spec/frontend/environments/deployment_spec.js index 24992711a4a..992bffd6e3f 100644 --- a/spec/frontend/environments/deployment_spec.js +++ b/spec/frontend/environments/deployment_spec.js @@ -6,15 +6,20 @@ import { formatDate } from '~/lib/utils/datetime_utility'; import { __, s__ } from '~/locale'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import Deployment from '~/environments/components/deployment.vue'; +import Commit from '~/environments/components/commit.vue'; import DeploymentStatusBadge from '~/environments/components/deployment_status_badge.vue'; import { resolvedEnvironment } from './graphql/mock_data'; describe('~/environments/components/deployment.vue', () => { useFakeDate(2022, 0, 8, 16); - const deployment = resolvedEnvironment.lastDeployment; + let deployment; let wrapper; + beforeEach(() => { + deployment = resolvedEnvironment.lastDeployment; + }); + const createWrapper = ({ propsData = {} } = {}) => mountExtended(Deployment, { propsData: { @@ -152,6 +157,32 @@ describe('~/environments/components/deployment.vue', () => { }); }); + describe('commit message', () => { + describe('with commit', () => { + beforeEach(() => { + wrapper = createWrapper(); + }); + + it('shows the commit component', () => { + const commit = wrapper.findComponent(Commit); + expect(commit.props('commit')).toBe(deployment.commit); + }); + }); + + describe('without a commit', () => { + it('displays nothing', () => { + const noCommit = { + ...deployment, + commit: null, + }; + wrapper = createWrapper({ propsData: { deployment: noCommit } }); + + const commit = wrapper.findComponent(Commit); + expect(commit.exists()).toBe(false); + }); + }); + }); + describe('collapse', () => { let collapse; let button; |