Skip to content

Instantly share code, notes, and snippets.

@leoxlin
Last active Apr 12, 2021
Embed
What would you like to do?

Git Branch - JIRA Summary Resolver

  1. Install the JIRA CLI

    brew install go-jira
    

    If you cannot install this via brew or is on another OS than MacOS. Look at the install instructions on https://github.com/go-jira/jira

  2. You will need to add the following to your ~/.jira.d/config.yml

    endpoint: https://companyname.atlassian.net/
    user: user@example.com
    password-source: keyring
    

    This turn on API token authentication and you will need to create one here:

    https://id.atlassian.com/manage-profile/security/api-tokens

  3. Create the summary folder under ~/.jira.d/

    mkdir -p ~/.jira.d/summary
    
  4. Install git_show_jira_summary.sh

    curl https://gist.githubusercontent.com/leoxlin/ac0bc7a7b4427365b9eb6334c1c43f73/raw/74e06c3dc5f564984eacc4b00a1bae84a4eb4d5f/git_show_jira_summary.sh > ~/.git_show_jira_summary.sh
    chmod +x ~/.git_show_jira_summary.sh
    
  5. Add a new alias branch jira which requires a PROJECTKEY for the project you want to resolve summaries for

    git config --global alias.branchjira "! git branch | ~/.git_show_jira_summary.sh PROJECTKEY"
    
  6. For multiple project key support, just chain the pipe

    git branch | ~/.git_show_jira_summary.sh KEYONE | ~/.git_show_jira_summary.sh KEYTWO
    
#!/bin/bash
PROJECT_NAME=$1
while read line
do
export issue=$(echo $line | perl -n -e "/.*($PROJECT_NAME-\d+).*/ && print \"\$1\n\"")
export branch=$(git branch --show-current)
if [[ "$line" = \** ]]; then
export prefix="* "
export line="\033[0;32m${branch}\033[0m"
else
export prefix=" "
fi
if [ -n "$issue" ]; then
if [ -f ~/.jira.d/summary/$issue ]; then
export summary=$(cat ~/.jira.d/summary/$issue)
else
export summary=$(jira view $issue --field summary --gjq='fields.summary')
echo $summary > ~/.jira.d/summary/$issue
fi
echo -e "${prefix}${line} ${summary}"
else
echo -e "${prefix}${line}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment