diff --git a/app/assets/javascripts/notes/components/noteable_discussion.vue b/app/assets/javascripts/notes/components/noteable_discussion.vue index 7c184f6578fb340e40442a313da933c3ba98e397..9ce3ad53099558fe6b703f87df6f7132fca3e980 100644 --- a/app/assets/javascripts/notes/components/noteable_discussion.vue +++ b/app/assets/javascripts/notes/components/noteable_discussion.vue @@ -221,6 +221,16 @@ export default { return this.line; }, + commit() { + if (!this.discussion.for_commit) { + return null; + } + + return { + id: this.discussion.commit_id, + url: this.discussion.discussion_path, + }; + }, }, watch: { isReplying() { @@ -386,6 +396,7 @@ Please check your network connection and try again.`; :note="componentData(initialDiscussion)" :line="line" :help-page-path="helpPagePath" + :commit="commit" @handleDeleteNote="deleteNoteHandler" > <note-edited-text diff --git a/app/assets/javascripts/notes/components/noteable_note.vue b/app/assets/javascripts/notes/components/noteable_note.vue index e13ffbb2383a6be4062c24444ca1ee0752b84782..f5e67f2d82c79672ec4b4140a353df75d8aadd0b 100644 --- a/app/assets/javascripts/notes/components/noteable_note.vue +++ b/app/assets/javascripts/notes/components/noteable_note.vue @@ -2,6 +2,8 @@ import $ from 'jquery'; import { mapGetters, mapActions } from 'vuex'; import { escape } from 'underscore'; +import { truncateSha } from '~/lib/utils/text_utility'; +import { s__, sprintf } from '~/locale'; import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue'; import Flash from '../../flash'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; @@ -37,6 +39,11 @@ export default { required: false, default: '', }, + commit: { + type: Object, + required: false, + default: () => null, + }, }, data() { return { @@ -73,6 +80,24 @@ export default { isTarget() { return this.targetNoteHash === this.noteAnchorId; }, + actionText() { + if (this.commit) { + const { id, url } = this.commit; + const linkStart = `<a class="commit-sha monospace" href="${escape(url)}">`; + const linkEnd = '</a>'; + return sprintf( + s__('MergeRequests|commented on commit %{linkStart}%{commitId}%{linkEnd}'), + { + commitId: truncateSha(id), + linkStart, + linkEnd, + }, + false, + ); + } + + return '<span class="d-none d-sm-inline">·</span>'; + }, }, created() { @@ -204,14 +229,9 @@ export default { </div> <div class="timeline-content"> <div class="note-header"> - <note-header - v-once - :author="author" - :created-at="note.created_at" - :note-id="note.id" - action-text="commented" - > - <slot slot="note-header-info" name="note-header-info"> </slot> + <note-header v-once :author="author" :created-at="note.created_at" :note-id="note.id"> + <slot slot="note-header-info" name="note-header-info"></slot> + <span v-html="actionText"></span> </note-header> <note-actions :author-id="author.id" diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 1949145c0377fd984d551213feee3e1b60d92c49..0a4a0b9b72a761919565cf4836cae06be1993064 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -85,7 +85,7 @@ module NotesHelper diffs_project_merge_request_path(discussion.project, discussion.noteable, path_params) elsif discussion.for_commit? - anchor = discussion.line_code if discussion.diff_discussion? + anchor = discussion.diff_discussion? ? discussion.line_code : "note_#{discussion.first_note.id}" project_commit_path(discussion.project, discussion.noteable, anchor: anchor) end diff --git a/changelogs/unreleased/winh-discussion-header-commented.yml b/changelogs/unreleased/winh-discussion-header-commented.yml new file mode 100644 index 0000000000000000000000000000000000000000..8d08409b504d0a1f0cd2d068d13fb73045f8a684 --- /dev/null +++ b/changelogs/unreleased/winh-discussion-header-commented.yml @@ -0,0 +1,5 @@ +--- +title: Display "commented" only for commit discussions on merge requests +merge_request: 23622 +author: +type: fixed diff --git a/ee/spec/features/epics/referencing_epics_spec.rb b/ee/spec/features/epics/referencing_epics_spec.rb index b66df70403972f80edffffded5f8c236f7a4a470..b9b210f9caf6c27ffc5dd629459684e7839b9111 100644 --- a/ee/spec/features/epics/referencing_epics_spec.rb +++ b/ee/spec/features/epics/referencing_epics_spec.rb @@ -137,7 +137,7 @@ describe 'Referencing Epics', :js do find('div#notes li.note div.note-text a').click - page.within('div#notes li.note .system-note-message') do + page.within('div#notes li.note.system-note .system-note-message') do expect(page).to have_content('mentioned in epic') expect(page.find('a')).to have_content(epic.to_reference(full: true)) end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 90c9d5404a4ce13e76899066929407a978ad4dd1..d08ee5be2217c1e91f54bd6f0703b37b942c0fd5 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -5426,6 +5426,9 @@ msgstr "" msgid "MergeRequests|View replaced file @ %{commitId}" msgstr "" +msgid "MergeRequests|commented on commit %{linkStart}%{commitId}%{linkEnd}" +msgstr "" + msgid "MergeRequests|started a discussion" msgstr "" diff --git a/spec/features/merge_request/user_sees_discussions_spec.rb b/spec/features/merge_request/user_sees_discussions_spec.rb index 4ab9a87ad4b8af674fca900fd67351128a695f1c..d130ea056547098905e68d23ab429685c8d080ee 100644 --- a/spec/features/merge_request/user_sees_discussions_spec.rb +++ b/spec/features/merge_request/user_sees_discussions_spec.rb @@ -88,5 +88,13 @@ describe 'Merge request > User sees discussions', :js do expect(page).to have_content "started a discussion on commit #{note.commit_id[0...7]}" end end + + context 'a commit non-diff discussion' do + let(:note) { create(:discussion_note_on_commit, project: project) } + + it 'displays correct header' do + expect(page).to have_content "commented on commit #{note.commit_id[0...7]}" + end + end end end diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index 21461e46cf4c40faea74d7d295c9b4bd7ae42030..0715f34dafe5032fcc36de124cf88c52c3b05a27 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -185,8 +185,8 @@ describe NotesHelper do context 'for a non-diff discussion' do let(:discussion) { create(:discussion_note_on_commit, project: project).to_discussion } - it 'returns the commit path' do - expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit)) + it 'returns the commit path with the note anchor' do + expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: "note_#{discussion.first_note.id}")) end end end