Last active
October 7, 2023 01:40
-
-
Save phillpafford/6081ee928762b1200722af499dab0418 to your computer and use it in GitHub Desktop.
find all jira tickets between 2 git tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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