/git-commit-msg

Git hook which would add emoji and infer commit context (conventional commits)

Primary LanguageJavaScript

git-commit-msg

Adds emojis and infers commit context for people who use conventional commits

  1. install it as git hooks: prepare-commit-msg and commit-msg
  2. follow git conventional commits: https://www.conventionalcommits.org/en/v1.0.0-beta.2/
  3. ???
  4. PROFIT

demo

Open GIF spoiler

demo on streamable: https://streamable.com/n0u5p webm: https://github.com/ColCh/git-commit-msg/blob/master/demo/demo.webm

more info

This hook currently does that:

  1. Prepend emoji before git commit type. Predefined types are here:

    git-commit-msg/index.js

    Lines 13 to 24 in 24ee7be

    const commitTypeToEmoji = {
    chore: '😒',
    docs: '📝',
    feat: '⭐',
    fix: '🛠',
    refactor: '♻',
    style: '💄',
    test: '🔍',
    type: '🏷',
    perf: '⚡',
    ci: '🤖',
    };
  2. Mark words with predefined emoji defined here:

    git-commit-msg/index.js

    Lines 26 to 43 in 24ee7be

    const markWordsWithEmoji = {
    update: '⬆ ',
    add: '➕',
    remove: '➖',
    change: '🔁',
    rename: '🔁',
    package: '📦',
    deploy: '📦',
    fix: '🛠',
    webpack: ' 🎁',
    increase: '📈 ',
    decrease: ' 📉',
    copy: ' 📋',
    config: '⚙️',
    configure: '⚙️',
    optimize: ' 🚀',
    typo: ' 📝',
    };
    . Example:
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "add" should match snapshot 1`] = `"some msg ➕ add some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "change" should match snapshot 1`] = `"some msg 🔁 change some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "config" should match snapshot 1`] = `"some msg ⚙️ config some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "configure" should match snapshot 1`] = `"some msg ⚙️ configure some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "copy" should match snapshot 1`] = `"some msg 📋 copy some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "decrease" should match snapshot 1`] = `"some msg 📉 decrease some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "deploy" should match snapshot 1`] = `"some msg 📦 deploy some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "fix" should match snapshot 1`] = `"some msg 🛠 fix some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "increase" should match snapshot 1`] = `"some msg 📈 increase some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "optimize" should match snapshot 1`] = `"some msg 🚀 optimize some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "package" should match snapshot 1`] = `"some msg 📦 package some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "remove" should match snapshot 1`] = `"some msg ➖ remove some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "rename" should match snapshot 1`] = `"some msg 🔁 rename some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "typo" should match snapshot 1`] = `"some msg 📝 typo some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "update" should match snapshot 1`] = `"some msg ⬆ update some msg"`;
    exports[`main test for git-commit-msg mark words with emoji per-word tests given word "webpack" should match snapshot 1`] = `"some msg 🎁 webpack some msg"`;
  3. Try to infer git commit context. Example:
    # Found 3 contexts
    # * modified-file
    # * deleted-file
    # * new-file

install

yarn global add @colch/git-commit-msg

add git-commit-msg into prepare-commit-msg and commit-msg hooks:

git-commit-msg $1

to appear like that:

options

pass it like env variables

  • GIT_COMMIT_MSG_HOOK_SKIP_ADDING_EMOJIS - completely disable emojis

  • GIT_COMMIT_MSG_HOOK_SKIP_AUTO_SUGGEST - disable emoji auto suggest