Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 feature/semantic-branch-names
Browse files Browse the repository at this point in the history
`createBranch` to run inquirier to create custom branch names follow
gitflow format where possible

refactor: 💡 branchIssues, branchType(s), hasAlphaSpecialChar

feat: 🎸 semantic-branch-names branchName should ask question

Now this is getting needlessly complicated, haha.

We should pass `branchName` in the `format` and if it is present,
 then and only then should we ask the question for an override.

refactor: 💡 semantic-branch-names remove test values

refactor: 💡 should we populate via branchName by branchPrefix

refactor: 💡 suppress husky on --no-verify

perf: ⚡️ remove node@10 support

refactor: 💡 lint to match repo standards

refactor: 💡 more lint fixes

chore: 🤖 noo

refactor: 💡 --branch attempt

refactor: 💡 ---branch take deux

refactor: 💡 break out of commitizen prompter for branch names

refactor: 💡 allow husky pass for --continue

BREAKING CHANGE: ⚡️ remove node@10 support

refactor: 💡 remove --branch console

refactor: 💡 lift up branchName

refactor: 💡 attempt again at lift

refactor: 💡 wait what commenting this out works

test: 💍 kind of, is rev-parse the prblem here

refactor: 💡 run.js is not even a thing

refactor: 💡 yup check against dryRun() for stsaged fileds

refactor: 💡 wut

refactor: 💡 how many checks do you want you moron

refactor: 💡 one more time

refactor: 💡 here i am

refactor: 💡 just needed to pass --allow-empty

refactor: 💡 update snapshots

refactor: 💡 prep for merge update README hack hack hack
  • Loading branch information
JeromeFitz authored and kodiakhq[bot] committed Apr 4, 2021
1 parent 428f1aa commit 4e0289e
Show file tree
Hide file tree
Showing 19 changed files with 520 additions and 89 deletions.
8 changes: 7 additions & 1 deletion .git-cz.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"disableEmoji": false,
"format": "{type}{scope}: {emoji}{subject}"
"format": "{type}{scope}: {emoji}{branchName}{subject}",
"branch": {
"format": "{branchType}{branchName}",
"projectCode": "ABC-",
"questions": ["branchName", "branchPrefix", "branchType"]
},
"questions": ["branchPrefix", "type", "subject"]
}
7 changes: 6 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
if ps -o args= $PPID | grep -E -q ' --no-verify| -n | -n$' ; then
:
else
:
yarn lint-staged
fi
15 changes: 12 additions & 3 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[ -n "$CI" ] && exit 0

yarn pretty-quick --staged
exec < /dev/tty
node ./lib/cli.js --hook || true

if ps -o args= $PPID | grep -E -q ' --no-verify| -n | -n$' ; then
:
elif ps -o args= $PPID | grep -E -q ' --continue| -c | -c$' ; then
:
else
:
yarn pretty-quick --staged
exec < /dev/tty
node ./lib/cli.js --hook || true
fi

72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ Have fun in your console if you can't in your codebase. 🤣️

Themes are an opt-in feature. If nothing is provided for `theme` it will fallback to `default`.

### Default
#### Default

No customizations needed. These are the emojis you know and love from `git-cz`

- 🎸️ feat
- 💡 refactor
- etc.

### Gitmoji
#### Gitmoji

A theme for [gitmoji](https://gitmoji.dev/) is available as an **override**.

Expand Down Expand Up @@ -323,3 +323,71 @@ yarn git-cz --hook || true
```

- ref: https://typicode.github.io/husky/#/?id=locally-installed-binaries

## Gitflow Branching

Eject from commit message and create a branch via:

```bash
git-cz --branch
```

There are new configs that you can override:

```js
module.exports = {
branch: {
format: '{branchName}',
projectCode: '',
questions: ['branchName'],
},
branchTypes: {
feature: {
description: 'A new feature',
emoji: '🎸',
value: 'feature',
},
hotfix: {
description: 'A hotfix',
emoji: '🚑️',
value: 'hotfix',
},
release: {
description: 'A release branch',
emoji: '🏹',
value: 'release',
},
},
format: '{type}{scope}: {emoji}{branchName}{subject}',
};
```

The only `branch.questions` required is `branchName`. So should probably make that rqeuired.

If you pass `{branchName}` in `format` currently it _needs_ to have the `questions` `'branchPrefix'` set so it can "find" it.

This is really only useful if you are using an issue tracker like Jira.

```bash
▲ git-cz [ABC-1234] git-cz
```

Would pull `ABC-1234` in for `{branchName}`

If you were doing something like:

```bash
▲ git-cz [feature/gitflow-branch-names]
```

You would not want to pass `branchPrefix` as that would be a long commit message.

Also most likely if you are doing feature branches you are doing `ABC-1234`'s into it.

### Roadmap

This is not going to be great to type, but may be good to move to:

- `https://github.com/commitizen/cz-cli` and create adapter/plugins.
- ⭐️ 11.k to 500
- ⬇️ 373k to 23.9k
136 changes: 79 additions & 57 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const formatCommitMessage = require('./formatCommitMessage');
const optionsSet = require('./optionsSet');
const isDryRun = require('./isDryRun');
const getGitRootDir = require('./util/getGitRootDir');
const {createBranch} = require('./createBranch');

// eslint-disable-next-line no-process-env
const executeCommand = (command, env = process.env) => {
Expand All @@ -26,72 +27,93 @@ const executeCommand = (command, env = process.env) => {
});
};

// eslint-disable-next-line complexity
const main = async () => {
try {
const {cliAnswers, cliOptions, passThroughParams} = parseArgs();
const state = createState(optionsSet(cliOptions));
isDryRun();
const gitflowBranch = async (options) => {
await createBranch(options);
};

if (cliOptions.nonInteractive) {
await runNonInteractiveMode(state, cliAnswers);
} else {
await runInteractiveQuestions(state, cliAnswers);
}
const commitMessage = async ({cliAnswers, cliOptions, passThroughParams, state}) => {
isDryRun();

if (cliOptions.nonInteractive) {
await runNonInteractiveMode(state, cliAnswers);
} else {
await runInteractiveQuestions(state, cliAnswers);
}

const message = formatCommitMessage(state);

const message = formatCommitMessage(state);
const appendedArgs = [];

const appendedArgs = [];
// eslint-disable-next-line guard-for-in
for (const key in passThroughParams) {
const value = passThroughParams[key];

// eslint-disable-next-line guard-for-in
for (const key in passThroughParams) {
const value = passThroughParams[key];
if (key.length === 1) {
appendedArgs.push('-' + key);
} else {
appendedArgs.push('--' + key);
}

if (key.length === 1) {
appendedArgs.push('-' + key);
} else {
appendedArgs.push('--' + key);
}
if (value !== true) {
appendedArgs.push(value);
}
}

if (value !== true) {
appendedArgs.push(value);
}
const commitMsgFile = join(getGitRootDir(), '.git', 'COMMIT_EDITMSG');

const command = shellescape([
'git',
'commit',
'--file',
commitMsgFile,
...appendedArgs,
]);

if (cliOptions.dryRun) {
// eslint-disable-next-line no-console
console.log('Will execute command:');

// The full path is replaced with a relative path to make the test pass on every machine
// eslint-disable-next-line no-console
console.log(command.replace(commitMsgFile, '.git/COMMIT_EDITMSG'));
// eslint-disable-next-line no-console
console.log('Message:');
// eslint-disable-next-line no-console
console.log(message);
} else if (cliOptions.branch) {
executeCommand(command);
} else {
fs.writeFileSync(commitMsgFile, message);

/**
* @author https://github.com/oxyii
* @see https://github.com/streamich/git-cz/issues/79
*/
if (cliOptions.hook) {
// eslint-disable-next-line no-process-exit
process.exit(0);
}
executeCommand(command);
}
};

// eslint-disable-next-line complexity
const main = async () => {
try {
const {cliAnswers, cliOptions, passThroughParams} = parseArgs();
const state = createState(optionsSet(cliOptions));

const options = {
cliAnswers,
cliOptions,
passThroughParams,
state,
};

const commitMsgFile = join(getGitRootDir(), '.git', 'COMMIT_EDITMSG');

const command = shellescape([
'git',
'commit',
'--file',
commitMsgFile,
...appendedArgs,
]);

if (cliOptions.dryRun) {
// eslint-disable-next-line no-console
console.log('Will execute command:');

// The full path is replaced with a relative path to make the test pass on every machine
// eslint-disable-next-line no-console
console.log(command.replace(commitMsgFile, '.git/COMMIT_EDITMSG'));
// eslint-disable-next-line no-console
console.log('Message:');
// eslint-disable-next-line no-console
console.log(message);
if (cliOptions.branch) {
await gitflowBranch(options);
} else {
fs.writeFileSync(commitMsgFile, message);

/**
* @author https://github.com/oxyii
* @see https://github.com/streamich/git-cz/issues/79
*/
if (cliOptions.hook) {
// eslint-disable-next-line no-process-exit
process.exit(0);
}

executeCommand(command);
await commitMessage(options);
}
} catch (error) {
signale.fatal(error);
Expand Down
Loading

0 comments on commit 4e0289e

Please sign in to comment.