diff options
-rw-r--r-- | app/assets/javascripts/notes/components/noteable_discussion.vue | 11 | ||||
-rw-r--r-- | app/assets/javascripts/notes/components/noteable_note.vue | 30 | ||||
-rw-r--r-- | app/helpers/notes_helper.rb | 2 | ||||
-rw-r--r-- | spec/features/merge_request/user_sees_discussions_spec.rb | 10 | ||||
-rw-r--r-- | spec/helpers/notes_helper_spec.rb | 4 |
5 files changed, 52 insertions, 5 deletions
diff --git a/app/assets/javascripts/notes/components/noteable_discussion.vue b/app/assets/javascripts/notes/components/noteable_discussion.vue index 4480ec74182..aeb7171068a 100644 --- a/app/assets/javascripts/notes/components/noteable_discussion.vue +++ b/app/assets/javascripts/notes/components/noteable_discussion.vue @@ -212,6 +212,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() { @@ -376,6 +386,7 @@ Please check your network connection and try again.`; :is="componentName(initialDiscussion)" :note="componentData(initialDiscussion)" :line="line" + :commit="commit" :help-page-path="helpPagePath" @handleDeleteNote="deleteNoteHandler" > diff --git a/app/assets/javascripts/notes/components/noteable_note.vue b/app/assets/javascripts/notes/components/noteable_note.vue index 4c02588127e..c39dcc71aa6 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() { @@ -205,8 +230,9 @@ export default { :author="author" :created-at="note.created_at" :note-id="note.id" - action-text="commented" - /> + > + <span v-html="actionText"></span> + </note-header> <note-actions :author-id="author.id" :note-id="note.id" diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 033686823a2..293dd20ad49 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/spec/features/merge_request/user_sees_discussions_spec.rb b/spec/features/merge_request/user_sees_discussions_spec.rb index 4ab9a87ad4b..409dd41405b 100644 --- a/spec/features/merge_request/user_sees_discussions_spec.rb +++ b/spec/features/merge_request/user_sees_discussions_spec.rb @@ -88,5 +88,15 @@ 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 + page.within(find("#note_#{note.id}", match: :first)) do + expect(page).to have_content "commented on commit #{note.commit_id[0...7]}" + end + end + end end end diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index 21461e46cf4..0715f34dafe 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 |