summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/modules/commit/getters.js
blob: d01060201f2ff6eb3d5b4798794b2f4794111e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as consts from './constants';

const BRANCH_SUFFIX_COUNT = 5;

export const discardDraftButtonDisabled = state =>
  state.commitMessage === '' || state.submitCommitLoading;

export const commitButtonDisabled = (state, getters, rootState) =>
  getters.discardDraftButtonDisabled || !rootState.stagedFiles.length;

export const newBranchName = (state, _, rootState) =>
  `${gon.current_username}-${rootState.currentBranchId}-patch-${`${new Date().getTime()}`.substr(
    -BRANCH_SUFFIX_COUNT,
  )}`;

export const branchName = (state, getters, rootState) => {
  if (
    state.commitAction === consts.COMMIT_TO_NEW_BRANCH ||
    state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR
  ) {
    if (state.newBranchName === '') {
      return getters.newBranchName;
    }

    return state.newBranchName;
  }

  return rootState.currentBranchId;
};

// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};