JIRA CLI Tooling

I love tooling. I am too lazy to do things manually and whenever a process has impedance I have two choices, either don’t do it, or make it better. I usually try and choose the latter.

JIRA is the beast everyone loves to hate. Rightfully so frankly, it’s slow, it’s tedious, it’s repetitive. But issue and project trackers like JIRA have value. As you become a more seasoned professional you realize that being able to see what you are working, what others are working on, and the state of the team in general is huge. It means you can plan projects in advance, share status with stakeholders, allow people to see what you’re doing and keep you from forgetting the things that are in play.

While other trackers exist (fogbugz, trello, etc) JIRA is by far the most widely used. For the longest time I hated using JIRA, because it didn’t map to my developer workflow. But lately I’ve been using a collection of ruby scripts that wrap the go-jira CLI that makes my life a whole lot easier.

For example, making a new ticket to track a random idea should be easy:

This fires off a ticket into my teams backlog and gives me a link. Now whenever I think to myself “it’d be great to do xyz” I can just pop open the shell and fire that idea off.

But we can take this so much further! I really like tying my commits to JIRA so I can see in the JIRA opened PR’s, merged PR’s, commits etc. To do that JIRA needs to integrate with github and know about your commits via (usually) a regex that looks for the jira ticket number in branch, commit, or PR titles.

Since I’m too lazy to ever remember doing that, I wanted to have my branches auto named with the current JIRA I’m on. If we have the ticket in the branch name, we can use git commit hooks to auto format commit messages that are prefixed with the JIRA.

# file: .git/hooks/prepare-commit-message-std



function detect_branch_name() {
  # of the format username-JIRA-3586/description
  # get the branch, remove the username, 
  #    split by / and take first segment, 
  #    split by - and take second 2 segments
  git branch | grep \* | cut -d ' ' -f2 | sed 's/$USER-//' | cut -d '/' -f1 | cut -d '-' -f2,3


if [[ "$branch_name" =~ "TRAFFIC-" ]]; then
  data=`cat $COMMIT_MSG_FILE`

  echo "$branch_name - $data" > $COMMIT_MSG_FILE

Now if I make a commit like:

~/src (akropp-JIRA-123/title)
$ git commit -am "foo"

My git log would look something like

JIRA-123 - foo

What if we could automatically create a JIRA and set it to in progress and add it to my sprint when I make a branch?

Well we can! For example, we can make a new branch that

  1. Creates a JIRA
  2. Adds it to my sprint
  3. Marks it in progress
  4. Git checkouts with a standardized branch name scheme that works with my commit hooks

All in a single one liner! On top of that making a new branch can pull down the open JIRA’s I have and prompt me to start working on it if some exist! This way anytime I start a branch it’s automatically tracked. All the random one-offs I do at work now get visibility and I can see at the end of the sprint how much work I really did vs how much work we planned.

On top of that, imagine I have open JIRAs and my branch names have the JIRA name in them. I can then switch between working tickets easily by resuming work on a ticket

My code even works when I have multiple branches for the same JIRA, so if I have multiple logical flows for the same JIRA I can resume different subsections easily (great for large migrations!)

As always source code on my github