jira-committer

1.2.2-presentation-test.0 • Public • Published

jira-committer

Conventional Commits Commitizen friendly

A Husky plugin that prepends commit messages with a Jira Issue found in your project's git branch name.

Table of Contents

Installation

⚠️ Remove jira-precommit-hook

Because the old jira-precommit-hook doesn't uninstall it's raw-hook, it needs to be removed manually before Husky can be completely installed (Husky won't overwrite existing hooks). This can be done a few ways...

  • Delete the raw git hook(s) directory, ./.git/hooks/
  • Or, recloning the repo

(You may also need to delete /node_modules/ if you already attempted to install Husky before doing the above^. This allows Husky to attempt to reinstall it's hooks again.)

Once the above is done, you may then... npm install.

Install Husky

npm install --save-dev husky@1.x

... then this package

npm install --save-dev git://github.mktp.io/extend-health/jira-committer#v1.2.1

or

npm install --save-dev https://github.mktp.io/extend-health/jira-committer/tarball/v1.2.1

Lastly, configure Husky

package.json

{
  "husky": {
    "hooks": {
      "commit-msg": "jira-committer || exit 0"
    }
  }
}

Configuration

jira-committer uses cosmiconfig for configuration file support. This means you can configure jira-committer via:

  • A .jira-committerrc file, written in YAML or JSON, with optional extensions: .yaml/.yml/.json.
  • A .jira-committerrc.toml file, written in TOML (the .toml extension is required).
  • A jira-committer.config.js or .jira-committerrc.js file that exports an object.
  • A "jira-committer" key in your package.json file.

The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found.

Options

interface IConfiguration {
  JIRA_ISSUE_PATTERN: RegExp;
}

Committing Code

Must each of your commit messages be prepended with a Jira issue (AB-1234)?

Is this currently a manual process?

To aid with this common task, this repository installs a git hook that automatically prepends messages with the Jira Issue found in the current branch name (AB-1234-add-feature).

For example...

> git checkout -b AB-1234-add-new-feature
> touch newfeature.txt
> git add .
> git commit -m "Add new feature"

... results in the following commit message...

AB-1234 Add new feature

Note: These issues are not validated with the server.

Examples

No Issue Found

$ git commit -m "formatting correction"
husky > commit-msg (node v11.12.0)
Checking branch name and commit message for Jira issue...
Jira issue NOT found in commit message nor branch name. Commit message remains unmodified.
[NOTE: These issues are not validated with the server.]
[branch-issue-precommit-helper 87cfaed] formatting correction
 1 file changed, 1 insertion(+), 1 deletion(-)

Issue in Commit, not Branch

$ git commit --amend
husky > commit-msg (node v11.12.0)
Checking branch name and commit message for Jira issue...
Commit message already specifies issue, CRMP-129.
Commit message remains unmodified. Consider using just the branch name next time.
[NOTE: These issues are not validated with the server.]
[branch-issue-precommit-helper e7523e6] CRMP-129 formatting correction
 Date: Fri Apr 5 19:04:46 2019 -0700
 1 file changed, 1 insertion(+), 1 deletion(-)

Issue in Branch, not Commit

$ git commit --amend
husky > commit-msg (node v11.12.0)
Checking branch name and commit message for Jira issue...
Prepending branch issue, CRMP-129, to commit message.
[NOTE: These issues are not validated with the server.]
[CRMP-129-test-branch 49d1d15] CRMP-129 <- is the ticket here?
 Date: Fri Apr 5 19:04:46 2019 -0700
 1 file changed, 1 insertion(+), 1 deletion(-)

Issue in Branch and Commit

$ git commit --amend
husky > commit-msg (node v11.12.0)
Checking branch name and commit message for Jira issue...
Commit message already specifies issue, CRMP-129.
Commit message remains unmodified. Consider using just the branch name next time.
[NOTE: These issues are not validated with the server.]
[CRMP-129-testttt d557660] CRMP-129 corrected 1+ regex search bugs Updated Husky script to always allow the commit to continue
 Date: Fri Apr 12 12:30:57 2019 -0700
 2 files changed, 6 insertions(+), 3 deletions(-)

Development

git clone https://github.mktp.io/extend-health/jira-committer.git
cd jira-committer
yarn install
npm run build
npm run watch
npm run tasks

Gulp

All NPM build scripts defer to Gulp underneath. If you have Gulp installed globally, feel free to use Gulp normally instead.

Otherwise, run any Gulp command via... npm run gulp -- <gulp args>.

Committing Changes

Commits are expected to follow the Conventional Commit format.

Use either of these to assist in writing correctly formatted commits...

  • git cz
  • npm run cm

Package Sidebar

Install

npm i jira-committer

Weekly Downloads

1

Version

1.2.2-presentation-test.0

License

ISC

Unpacked Size

51.6 kB

Total Files

40

Last publish

Collaborators

  • dperez3