-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically add JIRA ticket number to commit messages #3285
Automatically add JIRA ticket number to commit messages #3285
Conversation
4aec15b
to
db6ed3f
Compare
Hey @navDhammu ! That is pretty neat! It works for me if I use the message flag on Is that expected? |
@Duncan-Brain Thank you for having a look at this Do you mean when making a commit inside an editor like vim? I don't usually use that so didn't take that into consideration. But I think what may be happening is that it's matching the ticket number inside the comments that are autogenerated in the editor.
|
Yes plain old It is handy that the branch number is previewed in the vim commit comments. But I still need to manually enter it for it to be added to my commit message. I think what I was expecting is that a message using base command |
@Duncan-Brain I made some changes to work with the editor. Please let me know if it's working for you now.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great! I learned some stuff reading this (didn't know there was a Node test runner!) and the test cases cover all the variants I can think of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Duncan-Brain Thats weird, its working for me when I do the exact same steps you described... did you forget to pull latest changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navDhammu Your right I must not have had recent changes -- I remember both rebasing, because it was rebased and deleting because I suck at rebasing others branches.
But it works now!
Description
This is a little feature I worked on for myself to automate the process of adding a JIRA ticket number to commit messages. I was getting a bit tired of having to remember to add it everytime I make a commit, so I experimented and came up with this solution. I just wanted to share it here in case others may benefit from it as well and potentially merge it in the repository.
What it does
Automatically adds the JIRA ticket number to the commit message on each commit.
How it works
Git natively provides several hooks that allow you to do something on certain actions. Like the pre-commit hook allows you to run some code before committing, there are several others documented here.
For this case I used the prepare-commit-msg hook that allows you to modify commit messages before a commit. Since LiteFarm is using husky, I set up the hook under .husky as mentioned in their docs. I used node.js because that's what I'm most familiar with but it can be done in other ways like using bash scripting.
What the script does is checks for the presence of a Jira ticket number in the branch name, and if it exists, reads the commit message and adds it to the front.
Tests
I added tests for automatically testing a few different scenarios and edge cases. Initially I set it up without mocking - by creating a test branch, making test commits on that branch, then checking for the presence of ticket number in the commit message. But I found that it was slow (500ms - 1s) and prone to inconsistencies, so I ended up refactoring to use mocks.
Note:
node --test /pathToTestFile
How to test manually:
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: