Skip to content

Instantly share code, notes, and snippets.

@rmccue
Created March 13, 2015 03:03
Show Gist options
  • Save rmccue/c95769c01aff2b486073 to your computer and use it in GitHub Desktop.
Save rmccue/c95769c01aff2b486073 to your computer and use it in GitHub Desktop.
SINCE=$1
if [[ -z $SINCE ]]; then
echo "usage: changelog <since>"
exit 1
fi
shopt -s extglob
ISSUE_REGEX="#([0-9]+)"
MERGE_REGEX="Merge pull request $ISSUE_REGEX from ([^/]+)/"
ISSUES=()
OUTPUT=$(git log $SINCE... --merges --reverse -z --raw --format="format:- %w(80,0,4)%B")
while IFS= read -r -d '' COMMIT; do
# Run the matcher
if [[ ! $COMMIT =~ $MERGE_REGEX ]]; then
continue
fi
# Grab the main PR and author
PR="${BASH_REMATCH[1]}"
AUTHOR="${BASH_REMATCH[2]}"
# Strip the merge line
DESCRIPTION=$(tail -n +2 <<<"$COMMIT" | grep -v "^$" | sed 's/^[ \t]*//')
# Parse issues out
COMMIT_ISSUES=("$PR")
[[ $DESCRIPTION =~ $ISSUE_REGEX ]]
COMMIT_ISSUES=($COMMIT_ISSUES ${BASH_REMATCH[@]:1})
echo "- $DESCRIPTION"
echo
echo -n " (props @$AUTHOR"
for (( i = 0; i < ${#COMMIT_ISSUES[@]}; i++ )); do
ISSUE=${COMMIT_ISSUES[$i]}
ISSUES+=("$ISSUE")
echo -n ", [#$ISSUE][gh-$ISSUE]"
done
echo ")"
echo
done < <(git log $SINCE... --merges --reverse -z --raw --format="format:- %w(80,0,4)%B")
echo
for (( i = 0; i < ${#ISSUES[@]}; i++ )); do
ISSUE=${ISSUES[$i]}
echo "[gh-$ISSUE]: https://github.com/WP-API/WP-API/issues/$ISSUE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment