DEV Community

Kelly Stannard
Kelly Stannard

Posted on

Automatically link to your tickets

If you are like me, you grudgingly try to include links to the agile board even though git is the most logical place to put what you are doing and why.

To force myself to do this with the least effort possible, I came up with some automations. Maybe they will help you and your team.

Decorating your branch

First, I tie my branches to specific tickets with this alias:

# create the alias
git config [-g] alias.story "! git config branch.$(git branch --show-current).story"

# set the branch story
git story [ id of the story ]

# get the branch story
git story
# > id of the story
Enter fullscreen mode Exit fullscreen mode

Forcing yourself to add the story

Next create the following pre-commit githook and make it executable:

#!/usr/bin/env bash

if [ -n "$SKIP_STORY" ]; then
  exit 0
fi

if [ -z "$(git story)" ]; then
  echo No story is set
  echo '$ git story AA-1234'
  exit 1
fi

echo "Story is $(git story)"
Enter fullscreen mode Exit fullscreen mode

Anytime you try to commit without a story, git will not let you.

Automatically decorate your commit messages

Next, create the following prepare-commit-msg hook and make it executable:

#!/usr/bin/env ruby

exit 0 if ENV['SKIP_STORY']

story=`git story`.strip

tmp=File.read(ARGV[0])
  .gsub(/\n+### Story.*/, "").tap{ |m| puts m }
    .+ "\n### Story [#{story}](#{ENV["STORY_BASE_URL"]}#{story})\n"
File.write(ARGV[0], tmp)
Enter fullscreen mode Exit fullscreen mode

This hook will automatically add and change a markdown link to your story.

Set the base URL

Finally, set the STORY_BASE_URL env variable such that the link will correctly point to your story. Here is an example for JIRA:

https://[my-company].atlassian.net/browse/

With that final part, I now look like I am being a great team player with a minimal amount of effort.

Top comments (0)