Skip to content

Instantly share code, notes, and snippets.

@wyattisimo
Last active July 26, 2023 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyattisimo/6391548fe5624bd8f2299906dfb41d63 to your computer and use it in GitHub Desktop.
Save wyattisimo/6391548fe5624bd8f2299906dfb41d63 to your computer and use it in GitHub Desktop.
shell script to output list of Jira tickets based on git commit history
#!/usr/bin/env bash
# Git Jira Tickets
# Outputs a list of Jira ticket numbers from a git log
# Usage: gjt <since_commit>
commit_messages=$(git log --merges --pretty=format:'%h %s' $1^..HEAD | sed "s/ /SPACE_DELIMITER/g")
lines=()
i=0
for msg in $commit_messages;
do
hash=$(echo $msg | egrep -o "^[a-f0-9]+")
branch=$(echo $msg | egrep -o "(branch|from)SPACE_DELIMITER'?[a-zA-Z0-9/_-]+'?" | sed -E "s/branch|from|SPACE_DELIMITER|'//g")
ticket=$(echo $msg | egrep -o "\[?[a-zA-Z]{2}-[0-9]+\]?" | sed 's/[][]//g' | tr [a-z] [A-Z])
lines[$i]="- [[$ticket](https://salido.atlassian.net/browse/$ticket)] $hash $branch"
((i++))
done
printf "%s\n" "${lines[@]}" | sort -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment