Commit 44484cfc authored by Phil Hughes's avatar Phil Hughes

use a pre-built commit message for when no user specified message exists

parent e08ce52a
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
...mapState(['changedFiles', 'stagedFiles', 'currentActivityView', 'lastCommitMsg']), ...mapState(['changedFiles', 'stagedFiles', 'currentActivityView', 'lastCommitMsg']),
...mapState('commit', ['commitMessage', 'submitCommitLoading']), ...mapState('commit', ['commitMessage', 'submitCommitLoading']),
...mapGetters(['hasChanges']), ...mapGetters(['hasChanges']),
...mapGetters('commit', ['discardDraftButtonDisabled']), ...mapGetters('commit', ['discardDraftButtonDisabled', 'preBuiltCommitMessage']),
overviewText() { overviewText() {
return sprintf( return sprintf(
__( __(
...@@ -139,6 +139,7 @@ export default { ...@@ -139,6 +139,7 @@ export default {
</transition> </transition>
<commit-message-field <commit-message-field
:text="commitMessage" :text="commitMessage"
:placeholder="preBuiltCommitMessage"
@input="updateCommitMessage" @input="updateCommitMessage"
/> />
<div class="clearfix prepend-top-15"> <div class="clearfix prepend-top-15">
......
...@@ -16,6 +16,10 @@ export default { ...@@ -16,6 +16,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
placeholder: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -114,7 +118,7 @@ export default { ...@@ -114,7 +118,7 @@ export default {
</div> </div>
<textarea <textarea
ref="textarea" ref="textarea"
:placeholder="__('Write a commit message...')" :placeholder="placeholder"
:value="text" :value="text"
class="note-textarea ide-commit-message-textarea" class="note-textarea ide-commit-message-textarea"
name="commit-message" name="commit-message"
......
...@@ -103,12 +103,6 @@ export const updateFilesAfterCommit = ({ commit, dispatch, rootState }, { data } ...@@ -103,12 +103,6 @@ export const updateFilesAfterCommit = ({ commit, dispatch, rootState }, { data }
export const commitChanges = ({ commit, state, getters, dispatch, rootState, rootGetters }) => { export const commitChanges = ({ commit, state, getters, dispatch, rootState, rootGetters }) => {
const newBranch = state.commitAction !== consts.COMMIT_TO_CURRENT_BRANCH; const newBranch = state.commitAction !== consts.COMMIT_TO_CURRENT_BRANCH;
const payload = createCommitPayload({
branch: getters.branchName,
newBranch,
state,
rootState,
});
const stageFilesPromise = rootState.stagedFiles.length const stageFilesPromise = rootState.stagedFiles.length
? Promise.resolve() ? Promise.resolve()
: dispatch('stageAllChanges', null, { root: true }); : dispatch('stageAllChanges', null, { root: true });
...@@ -116,7 +110,17 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -116,7 +110,17 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
commit(types.UPDATE_LOADING, true); commit(types.UPDATE_LOADING, true);
return stageFilesPromise return stageFilesPromise
.then(() => service.commit(rootState.currentProjectId, payload)) .then(() => {
const payload = createCommitPayload({
branch: getters.branchName,
newBranch,
getters,
state,
rootState,
});
return service.commit(rootState.currentProjectId, payload);
})
.then(({ data }) => { .then(({ data }) => {
commit(types.UPDATE_LOADING, false); commit(types.UPDATE_LOADING, false);
......
import { sprintf, n__ } from '../../../../locale';
import * as consts from './constants'; import * as consts from './constants';
const BRANCH_SUFFIX_COUNT = 5; const BRANCH_SUFFIX_COUNT = 5;
...@@ -25,5 +26,18 @@ export const branchName = (state, getters, rootState) => { ...@@ -25,5 +26,18 @@ export const branchName = (state, getters, rootState) => {
return rootState.currentBranchId; return rootState.currentBranchId;
}; };
export const preBuiltCommitMessage = (state, _, rootState) => {
if (state.commitMessage) return state.commitMessage;
const files = (rootState.stagedFiles.length
? rootState.stagedFiles
: rootState.changedFiles
).reduce((acc, val) => acc.concat(val.path), []);
return sprintf(n__('Update %{files}', 'Update %{files} files', files.length), {
files: files.join(', '),
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -105,9 +105,9 @@ export const setPageTitle = title => { ...@@ -105,9 +105,9 @@ export const setPageTitle = title => {
document.title = title; document.title = title;
}; };
export const createCommitPayload = ({ branch, newBranch, state, rootState }) => ({ export const createCommitPayload = ({ branch, getters, newBranch, state, rootState }) => ({
branch, branch,
commit_message: state.commitMessage, commit_message: state.commitMessage || getters.preBuiltCommitMessage,
actions: rootState.stagedFiles.map(f => ({ actions: rootState.stagedFiles.map(f => ({
action: f.tempFile ? 'create' : 'update', action: f.tempFile ? 'create' : 'update',
file_path: f.path, file_path: f.path,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment