Created
January 27, 2020 18:47
-
-
Save alombarte/508b0289020415d93340c2cd26ba6ab7 to your computer and use it in GitHub Desktop.
Retrieve all the JIRA issues between the tag and the previous tag. Optionally surround the issues with the JIRA url to the issues.
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
#!/bin/bash | |
# Finds all the strings looking as issues (e.g: ISSUE-123) in the commit log and returns its links | |
# The issues can optionally be surrounded with a prefix or a suffix to print issue tracker URLS. | |
# Issues ARE NOT expected to be found in the first position of the commit log (e.g: Merge feature branch 'feature/ISS-123') | |
# | |
# Example (extract issues between v1.2.3 and v1.2.2 | |
# -------- | |
# Input: | |
# extractIssuesFromJira.sh v1.2.3 'http://jira.url/browse/' | |
# | |
# Output: | |
# http://jira.url/browse/ISSUE-234 | |
# http://jira.url/browse/ISSUE-233 | |
if [ -z "$1" ]; then | |
echo "ERROR: Reference tag not passed" | |
echo "" | |
echo "Usage example: " | |
echo "bash $0 v069 'http://jira.url/browse/' '?source=bash'" | |
exit 1 | |
fi | |
TAG=$1 | |
PREFIX=$2 | |
SUFFIX=$3 | |
PREV_TAG=$(git describe --tags --abbrev=0 "$TAG"^) | |
COMMITS=$(git --no-pager log --pretty=oneline "$TAG"..."$PREV_TAG" | grep -o -P '([A-Z]{1,6}-[0-9]+)') | |
# Construct the JIRA urls (or any other issue tracker) | |
if [ "$COMMITS" ]; then | |
while IFS= read -r issue; do | |
echo "${PREFIX}${issue}${SUFFIX}" | |
done <<< "$COMMITS" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment