From accbe3f428334998c2e1ee654b2157b558acaeea Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 4 Aug 2023 12:10:33 +0100 Subject: [PATCH] Added bot comments filter option to merge requests https://gitlab.com/gitlab-org/gitlab/-/issues/420909 --- .../notes/components/mr_discussion_filter.vue | 2 +- app/assets/javascripts/notes/constants.js | 5 +++++ app/assets/javascripts/notes/stores/getters.js | 8 +++++--- app/serializers/note_user_entity.rb | 2 ++ .../api/schemas/entities/note_user_entity.json | 6 +++++- locale/gitlab.pot | 3 +++ .../api/schemas/entities/note_user_entity.json | 6 +++++- .../notes/components/mr_discussion_filter_spec.js | 7 ++++--- spec/frontend/notes/stores/getters_spec.js | 13 +++++++++++++ 9 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/notes/components/mr_discussion_filter.vue b/app/assets/javascripts/notes/components/mr_discussion_filter.vue index c2ac95ca56eb74..4d78a888be7056 100644 --- a/app/assets/javascripts/notes/components/mr_discussion_filter.vue +++ b/app/assets/javascripts/notes/components/mr_discussion_filter.vue @@ -85,7 +85,7 @@ export default { /> diff --git a/app/assets/javascripts/notes/constants.js b/app/assets/javascripts/notes/constants.js index 999ef8ff905784..464c1cd181ed19 100644 --- a/app/assets/javascripts/notes/constants.js +++ b/app/assets/javascripts/notes/constants.js @@ -76,6 +76,11 @@ export const MR_FILTER_OPTIONS = [ s__('IssuableEvents|unassigned'), ], }, + { + text: __('Bot comments'), + value: 'bot_comments', + bot: true, + }, { text: __('Comments'), value: 'comments', diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index 62d991c2d9e8c1..56bbb44df53966 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -33,13 +33,15 @@ const hideActivity = (filters, discussion) => { // the first in a discussion or a single note // If the filter option filters based on icon check against the first notes system note icon f.systemNoteIcons?.includes(firstNote.system_note_icon_name) || - // If the filter option filters based on note type user the first notes type - f.noteType?.includes(firstNote.type) || + // If the filter option filters based on note type use the first notes type + (f.noteType?.includes(firstNote.type) && !firstNote.author.bot) || // If the filter option filters based on the note text then check if it is sytem // and filter based on the text of the system note (firstNote.system && f.noteText?.some((t) => firstNote.note.includes(t))) || // For individual notes we filter if the discussion is a single note and is not a sytem - (f.individualNote === discussion.individual_note && !firstNote.system) + (f.individualNote === discussion.individual_note && !firstNote.system) || + // For bot comments we filter on the authors `bot` boolean attribute + (f.bot && firstNote.author.bot) ) { return true; } diff --git a/app/serializers/note_user_entity.rb b/app/serializers/note_user_entity.rb index c3f14fb0f9e942..f89203d4cf8c61 100644 --- a/app/serializers/note_user_entity.rb +++ b/app/serializers/note_user_entity.rb @@ -2,6 +2,8 @@ class NoteUserEntity < UserEntity unexpose :web_url + + expose :bot?, as: :bot end NoteUserEntity.prepend_mod_with('NoteUserEntity') diff --git a/ee/spec/fixtures/api/schemas/entities/note_user_entity.json b/ee/spec/fixtures/api/schemas/entities/note_user_entity.json index 0642579da22ced..6a6d4518a69120 100644 --- a/ee/spec/fixtures/api/schemas/entities/note_user_entity.json +++ b/ee/spec/fixtures/api/schemas/entities/note_user_entity.json @@ -35,6 +35,9 @@ }, "show_status": { "type": "boolean" + }, + "bot": { + "type": "boolean" } }, "additionalProperties": false, @@ -45,7 +48,8 @@ "avatar_url", "path", "name", - "username" + "username", + "bot" ] } ] diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 7595bc3785bf60..75fa4cc0a2117f 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -8539,6 +8539,9 @@ msgstr "" msgid "Bot" msgstr "" +msgid "Bot comments" +msgstr "" + msgid "Both SSH and HTTP(S)" msgstr "" diff --git a/spec/fixtures/api/schemas/entities/note_user_entity.json b/spec/fixtures/api/schemas/entities/note_user_entity.json index 16d33ada51d819..af5e6fa53a90e1 100644 --- a/spec/fixtures/api/schemas/entities/note_user_entity.json +++ b/spec/fixtures/api/schemas/entities/note_user_entity.json @@ -7,7 +7,8 @@ "avatar_url", "path", "name", - "username" + "username", + "bot" ], "properties": { "id": { @@ -39,6 +40,9 @@ }, "show_status": { "type": "boolean" + }, + "bot": { + "type": "boolean" } } } diff --git a/spec/frontend/notes/components/mr_discussion_filter_spec.js b/spec/frontend/notes/components/mr_discussion_filter_spec.js index 05576d2ccc6b49..73fd6da811dfaf 100644 --- a/spec/frontend/notes/components/mr_discussion_filter_spec.js +++ b/spec/frontend/notes/components/mr_discussion_filter_spec.js @@ -57,7 +57,7 @@ describe('Merge request discussion filter component', () => { describe('local sync sort filters', () => { it('calls setDiscussionSortDirection when mounted', () => { - localStorage.setItem('mr_activity_filters', '["comments"]'); + localStorage.setItem('mr_activity_filters_2', '["comments"]'); createComponent(); @@ -82,6 +82,7 @@ describe('Merge request discussion filter component', () => { expect(updateMergeRequestFilters).toHaveBeenCalledWith(expect.anything(), [ 'assignees_reviewers', + 'bot_comments', 'comments', 'commit_branches', 'edits', @@ -126,12 +127,12 @@ describe('Merge request discussion filter component', () => { await nextTick(); - expect(wrapper.findAll('[aria-selected="true"]')).toHaveLength(9); + expect(wrapper.findAll('[aria-selected="true"]')).toHaveLength(10); wrapper.find('[data-testid="listbox-select-all-button"]').vm.$emit('click'); await nextTick(); - expect(wrapper.findAll('[aria-selected="true"]')).toHaveLength(10); + expect(wrapper.findAll('[aria-selected="true"]')).toHaveLength(11); }); }); diff --git a/spec/frontend/notes/stores/getters_spec.js b/spec/frontend/notes/stores/getters_spec.js index 1514602d424e53..8eebfeff553b8a 100644 --- a/spec/frontend/notes/stores/getters_spec.js +++ b/spec/frontend/notes/stores/getters_spec.js @@ -87,6 +87,19 @@ describe('Getters Notes Store', () => { const getDiscussions = () => getters.discussions(state, {}, { batchComments }); + describe('merge request filters', () => { + it('returns only bot comments', () => { + const discussion = JSON.parse(JSON.stringify(discussionMock)); + discussion.notes[0].author.bot = true; + + state.noteableData = { targetType: 'merge_request' }; + state.discussions = [discussion]; + state.mergeRequestFilters = ['bot_comments']; + + expect(getDiscussions()).toContain(discussion); + }); + }); + describe('without batchComments module', () => { it('should return all discussions in the store', () => { expect(getDiscussions()).toEqual([individualNote]); -- GitLab