Code Monkey home page Code Monkey logo

add-issue-id-hook's Introduction

Add issue id hook Build Status

Git commit hook for adding related JIRA issue ids to commit messages.

How does it work?

Issue id is parsed from the current branch name and prepended to your commit message.

$ git checkout -b EXAMPLE-123-new-feature
$ git add some_code.py
$ git commit -m "Added some pretty code."
$ git log
    ...
    EXAMPLE-123 Added some pretty code.

Here's the specification generated from spec.py tests:

AddIssueIdHook:

  • prepends issue id from branch name to commit message
  • prepends first matching issue id to commit message if multiple ids in branch name exist
  • prepends issue id to commit message when message contains a different issue id
  • doesnt modify commit message if issue id not in branch name
  • doesnt modify commit message if it already contains this issue id
  • doesnt modify commit message if in detached HEAD state
  • supports aborting a commit by providing an empty message
  • supports aborting a commit by exiting from editor without making changes

Installation

  1. Copy commit-msg file into .git/hooks/ directory of your project's repository.
  2. Make sure the commit-msg file has execution mode flag set (chmod +x commit-msg).

This plugin requires having Python 2.x or Python 3.x installed (comes pre-installed on OS X and Ubuntu). Verified against versions 2.7 and 3.4.

Global installation

It's possible to apply this hook to every newly cloned or initialized repository using git's template directory feature:

  1. Create a directory for your git templates and put this commit-msg script into it, e.g. into ~/.git-templates/hooks/commit-msg.
  2. Configure git to use your template directory when initializing repositories: git config --global init.templatedir ~/.git-templates.

Customizations

Customizations are supported by opening your copy of commit-msg file and adjusting the configuration variables.

Commit message format

Provide your commit message formatting by changing commit_message_format variable.

JIRA project key pattern

By default, issue ids matching the default JIRA project key pattern are discovered. You can customize the project key pattern or explicitly specify the project key to look for by adjusting project_format variable.

Not a JIRA project?

JIRA issue ids are supported by default, but the hook can support any other issue id patterns. Simply change the issue_pattern variable to a regular expression that matches the issue ids from your ticket system.

Known limitations

As this commit hook depends on parsing the current branch name, it won't work when committing in detached HEAD state, e.g. when doing a reword operation during git rebase --interactive.

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.