From 3fec26593cf2c0fd7f7b023a27f0d116adf5ba67 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 24 Mar 2021 19:56:38 -0600 Subject: [PATCH 1/2] Switch diffs to use the mrNotes store ... when getting the default suggestion commit message --- app/assets/javascripts/diffs/store/getters.js | 12 ++--- spec/frontend/diffs/store/getters_spec.js | 44 ++++++++++++------- .../notes/components/note_body_spec.js | 17 ++++--- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js index 1fc2a684e951b1..dec3f87b03ef57 100644 --- a/app/assets/javascripts/diffs/store/getters.js +++ b/app/assets/javascripts/diffs/store/getters.js @@ -156,16 +156,16 @@ export const diffLines = (state) => (file, unifiedDiffComponents) => { ); }; -export function suggestionCommitMessage(state) { +export function suggestionCommitMessage(state, _, rootState) { return (values = {}) => computeSuggestionCommitMessage({ message: state.defaultSuggestionCommitMessage, values: { - branch_name: state.branchName, - project_path: state.projectPath, - project_name: state.projectName, - username: state.username, - user_full_name: state.userFullName, + branch_name: rootState.page.mrMetadata.branch_name, + project_path: rootState.page.mrMetadata.project_path, + project_name: rootState.page.mrMetadata.project_name, + username: rootState.page.mrMetadata.username, + user_full_name: rootState.page.mrMetadata.user_full_name, ...values, }, }); diff --git a/spec/frontend/diffs/store/getters_spec.js b/spec/frontend/diffs/store/getters_spec.js index 04606b48662290..2e3a66d5b012bf 100644 --- a/spec/frontend/diffs/store/getters_spec.js +++ b/spec/frontend/diffs/store/getters_spec.js @@ -377,32 +377,40 @@ describe('Diffs Module Getters', () => { }); describe('suggestionCommitMessage', () => { + let rootState; + beforeEach(() => { Object.assign(localState, { defaultSuggestionCommitMessage: '%{branch_name}%{project_path}%{project_name}%{username}%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}', - branchName: 'branch', - projectPath: '/path', - projectName: 'name', - username: 'user', - userFullName: 'user userton', }); + rootState = { + page: { + mrMetadata: { + branch_name: 'branch', + project_path: '/path', + project_name: 'name', + username: 'user', + user_full_name: 'user userton', + }, + }, + }; }); it.each` - specialState | output - ${{}} | ${'branch/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ userFullName: null }} | ${'branch/pathnameuser%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}'} - ${{ username: null }} | ${'branch/pathname%{username}user userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ projectName: null }} | ${'branch/path%{project_name}useruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ projectPath: null }} | ${'branch%{project_path}nameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ branchName: null }} | ${'%{branch_name}/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + specialState | output + ${{}} | ${'branch/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ user_full_name: null }} | ${'branch/pathnameuser%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}'} + ${{ username: null }} | ${'branch/pathname%{username}user userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ project_name: null }} | ${'branch/path%{project_name}useruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ project_path: null }} | ${'branch%{project_path}nameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ branch_name: null }} | ${'%{branch_name}/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} `( 'provides the correct "base" default commit message based on state ($specialState)', ({ specialState, output }) => { - Object.assign(localState, specialState); + Object.assign(rootState.page.mrMetadata, specialState); - expect(getters.suggestionCommitMessage(localState)()).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)()).toBe(output); }, ); @@ -417,7 +425,9 @@ describe('Diffs Module Getters', () => { `( "properly overrides state values ($stateOverrides) if they're provided", ({ stateOverrides, output }) => { - expect(getters.suggestionCommitMessage(localState)(stateOverrides)).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)(stateOverrides)).toBe( + output, + ); }, ); @@ -431,7 +441,9 @@ describe('Diffs Module Getters', () => { `( "fills in any missing interpolations ($providedValues) when they're provided at the getter callsite", ({ providedValues, output }) => { - expect(getters.suggestionCommitMessage(localState)(providedValues)).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)(providedValues)).toBe( + output, + ); }, ); }); diff --git a/spec/frontend/notes/components/note_body_spec.js b/spec/frontend/notes/components/note_body_spec.js index 4922de987fa8a3..40251244423bff 100644 --- a/spec/frontend/notes/components/note_body_spec.js +++ b/spec/frontend/notes/components/note_body_spec.js @@ -81,14 +81,21 @@ describe('issue_note_body component', () => { state: { defaultSuggestionCommitMessage: '%{branch_name}%{project_path}%{project_name}%{username}%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}', - branchName: 'branch', - projectPath: '/path', - projectName: 'name', - username: 'user', - userFullName: 'user userton', }, getters: { suggestionCommitMessage }, }, + page: { + namespaced: true, + state: { + mrMetadata: { + branch_name: 'branch', + project_path: '/path', + project_name: 'name', + username: 'user', + user_full_name: 'user userton', + }, + }, + }, }, }); -- GitLab From ef5176133f142e173361622a563077440ab4dfaa Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 24 Mar 2021 19:45:27 -0600 Subject: [PATCH 2/2] Add changelog for suggestion commit placeholder change --- ...t-overview-placeholder-message-diffs-new-data-source.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelogs/unreleased/tor-defect-overview-placeholder-message-diffs-new-data-source.yml diff --git a/changelogs/unreleased/tor-defect-overview-placeholder-message-diffs-new-data-source.yml b/changelogs/unreleased/tor-defect-overview-placeholder-message-diffs-new-data-source.yml new file mode 100644 index 00000000000000..d602bad9d4e9f5 --- /dev/null +++ b/changelogs/unreleased/tor-defect-overview-placeholder-message-diffs-new-data-source.yml @@ -0,0 +1,6 @@ +--- +title: Hydrate some of the variables in the Overview tab suggestion commit placeholder + by switching the Diffs data source for it +merge_request: 57419 +author: +type: changed -- GitLab