Skip to content

Instantly share code, notes, and snippets.

@phillpafford
Last active October 7, 2023 01:40
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 phillpafford/6081ee928762b1200722af499dab0418 to your computer and use it in GitHub Desktop.
Save phillpafford/6081ee928762b1200722af499dab0418 to your computer and use it in GitHub Desktop.
find all jira tickets between 2 git tags
#!/usr/bin/env bash
set -e
## https://confluence.atlassian.com/adminjiraserver/configuring-jira-application-options-938847824.html
## Project Key Length: Default: 10
JIRA_REGEX='[A-Z]{2,10}-[0-9]{1,7}'
JIRA_TICKET=()
# Set the tags
TAG_LATEST=$(git tag --sort=taggerdate | tail -1)
TAG_PREVIOUS=$(git tag --sort=taggerdate | tail -2 | head -n 1)
echo "TAG_LATEST: $TAG_LATEST"
echo "TAG_PREVIOUS: $TAG_PREVIOUS"
# Print the commits between the two tags
GIT_LOG=$(git log --pretty=format:%s $TAG_LATEST...$TAG_PREVIOUS)
while IFS= read -r line; do
## check for jira ticket regex in comment message
if [[ "$line" =~ $JIRA_REGEX ]]; then
## match found
if [[ ${BASH_REMATCH[0]} ]]; then
## push to array
JIRA_MATCH="${BASH_REMATCH[0]}"
JIRA_TICKET+=($JIRA_MATCH)
fi
fi
done <<< "$GIT_LOG"
## unique JIRA_TICKET
JIRA_TICKET=($(for jt in "${JIRA_TICKET[@]}"; do echo "${jt}"; done | sort -u))
FOUND_JIRA_TICKET=${#JIRA_TICKET[@]}
echo "FOUND_JIRA_TICKET: $FOUND_JIRA_TICKET"
if [ $FOUND_JIRA_TICKET -gt 0 ]; then
echo "Jira Tickets"
printf '%s\n' "${JIRA_TICKET[@]}"
fi
## end
###################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment