Coder Social home page Coder Social logo

janniks / prepare-commit-msg Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 5.0 6.46 MB

Automatically prefix commit messages with the current branch issue number

License: GNU General Public License v3.0

Shell 74.85% Ruby 25.15%
git-hooks git issues issue-tracker issue-management issue-tracking-system issue issue-mgt jira atlassian

prepare-commit-msg's Introduction

Prefix Issue Number - Git Hook

This is a git hook for lazy people. ๐Ÿ˜ด

Description ๐Ÿ“š

This git hook automatically prepends a parsed issue number (from the current branch) to your commit messages on every commit. (See Usage for examples and details)

Example usage

This git hook requires ruby to be installed (already pre-installed by default on macOS).

Install ๐Ÿš€

Install Script

To install simply run the following command. This requires curl to be installed.

sh <(curl -s https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/install.sh)

If you choose the option to install globally, you will have to reinitialize all your git repositories. The following helpful command reinitializes all repositories found in sub-directories of the current directory.

find . -name .git -type d -prune -exec sh -c 'git --git-dir "{}" init' \;

Install Manually

If you prefer to install manually you can walk through the following steps:

  1. Copy the scripts/prepare-commit-msg script into your local git repository inside .git/hooks
  2. Edit the placeholders at the beginning of the script
  3. Make sure the is script executable by running chmod +x prepare-commit-msg
  4. Enjoy! Test it by committing anything!

Usage ๐Ÿ”ง

Simply commit as you always would! This git hook also works with tools like Tower that use native git bindings.

This git hooks will look at the current branch (e.g. type/ABC-123-branch-name) and parse the issue number and project key (e.g. ABC 123) to use for prefixing commit messages. This can be useful in connection with tools like Jira.

  • If no issue number is found in the branch name, the commit message will not be modified.
  • If the commit message already contains an issue number, the commit message will not be modified.

Examples

Branch name Entered commit message Updated commit message
bugfix/ABC-012-add-initial-repo Set up repo [ABC-012] Set up repo
improvement/ABC-123-great-things Add files [ABC-123] Add files
feature/ABC-123-something-normal [XYZ-321] Something different not modified

Default Regular Expressions

These are the default regular expressions that are used by the script on install. They can easily be changed during install using the provided script or manually tweaked.

Parsing issue numbers from current branch name

/[.]*\/([\-\w]*?\-\d+)/

Detects issue number Does not detect issue number
feature/ABC-123-test-message abc-123-do-it
Improvement/XYZ-ABC-321-Crazy-Name simple-branch-name

Checking commit messages for existing issue numbers

/^\s*\[[\-\w]*\d\]/

Detects issue number Does not detect issue number
[ABC-123] Test message Test message
[XYZ-312] Message test [ABC] Testing stuff
[XYZ-ABCD-321] Awesome sauce [Add ABC-123 files]

Detecting automated commits by git

/(Merge\sbranch\s\'|\#\sRebase\s|This\sreverts\scommit\s)/

Ignores following commits
Merge branch 'testing' into master
# Rebase commit 9f3bc7b
This reverts commit 28da9f6

You can use tools like Regex101 to tweak and test these regular expressions.

FAQ & Problems

I already have a global git-template! Install manually and add the git hook file to your hooks directory in your existing git-template.

Uninstall ๐Ÿ˜–

If you're unhappy with this git hook:

  • Simply run rm -rf .git/hooks/prepare-commit-msg to uninstall locally
  • Or run rm -rf ~/.git-template/hooks/prepare-commit-msg to uninstall globally

Please let me know what you didn't like!

prepare-commit-msg's People

Contributors

janniks avatar otherguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prepare-commit-msg's Issues

Auto-uppercase project identifier

Would be cool if the script could auto-uppercase the project identifier when it is lowercased in the branch name, e.g abc-123 results in [ABC-123] commit message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.