|
1 | | -# pre_ticket |
2 | | -pre-commit hook for adding issue ticket number to your git commit messages |
| 1 | +# pre_ticket pre-commit plugin |
| 2 | + |
| 3 | +**pre_ticket** is a tool written for [pre-commit](https://pre-commit.com/). This hook will automatically add the issue ticket number to your git commit message based on the current branch name. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +In order to use **pre_ticket** hook, you need to have [pre-commit installed](https://pre-commit.com/#install). |
| 8 | + |
| 9 | +Next, add config file: `.pre-commit-config.yaml` to your project directory if you don't have it setup yet. A ready-to-use example can be found in our repository: |
| 10 | + |
| 11 | +```yaml |
| 12 | +repos: |
| 13 | +- repo: git@github.com:deployed/pre_ticket.git |
| 14 | + rev: v1.0.0 |
| 15 | + hooks: |
| 16 | + - id: pre_ticket |
| 17 | + language_version: python3.6 |
| 18 | + stages: [commit-msg] |
| 19 | +``` |
| 20 | +
|
| 21 | +In your project dir run `$ pre-commit install` and that's it. You are good to go. |
| 22 | + |
| 23 | +## Default settings and options |
| 24 | + |
| 25 | +By default **pre_ticket** checks against the pattern for branch names like: `feature/123456-some_new_feature` or `chore/123456-do_something`. |
| 26 | + |
| 27 | +The exact regex pattern is: `(feature|bug|chore)/(?P<ticket>[0-9]+)-.*`. |
| 28 | +Based on that the ticket number (i.e. `123456` in the above example) is picked and added to the commit message. |
| 29 | + |
| 30 | +You can change the regex pattern, by adding the args param to the pre-commit config file. For example: |
| 31 | + |
| 32 | +```yaml |
| 33 | +repos: |
| 34 | +- repo: git@github.com:deployed/pre_ticket.git |
| 35 | + rev: v1.0.0 |
| 36 | + hooks: |
| 37 | + - id: pre_ticket |
| 38 | + language_version: python3.6 |
| 39 | + stages: [commit-msg] |
| 40 | + args: ['--regex=(feature|bug|chore)/(?P<ticket>[0-9]+)-.*'] |
| 41 | +``` |
| 42 | + |
| 43 | +By default the ticket number is added under the commit message as `Ref: #123456`. You can change this also in the config file: |
| 44 | + |
| 45 | +```yaml |
| 46 | +repos: |
| 47 | +- repo: git@github.com:deployed/pre_ticket.git |
| 48 | + rev: v1.0.0 |
| 49 | + hooks: |
| 50 | + - id: pre_ticket |
| 51 | + language_version: python3.6 |
| 52 | + stages: [commit-msg] |
| 53 | + args: ['--format={ticket} - {message}'] |
| 54 | +``` |
| 55 | + |
| 56 | +Above example will put the ticket in the beginning of the commit message and separate it with a dash symbol. |
| 57 | + |
| 58 | +*Note*: You do not need to reinstall the pre-commit hook every time you change the config. It is always used by pre-commit on git commit actions. |
| 59 | + |
| 60 | +# Credits |
| 61 | + |
| 62 | +This project was based on some code primarily provided by [@Overfl0](http://github.com/overfl0) and also in many ways inspired by another pre-commit ticket plugin: [giticket](https://github.com/milin/giticket). |
0 commit comments