Created
August 8, 2019 20:15
-
-
Save joehoyle/2ea7bda4670e4e666ccc8062ca5aa60a to your computer and use it in GitHub Desktop.
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 | |
SINCE_BRANCH=$1 | |
TO_BRANCH=${2:-master} | |
if [[ -z $SINCE_BRANCH ]]; then | |
echo "usage: changelog <since-branch> [<to-branch>]" | |
exit 1 | |
fi | |
CURRENT_DIR=$(PWD) | |
ISSUE_REGEX="#([0-9]+)" | |
MERGE_REGEX="Merge pull request $ISSUE_REGEX from ([^/]+)/" | |
ISSUES=() | |
shopt -s extglob | |
PACKAGE_PATH=$CURRENT_DIR | |
PACKAGE="$(basename "${PACKAGE_PATH}")" | |
# Checkout current tracking branch | |
git checkout $TO_BRANCH --quiet | |
# Get commits since HEAD | |
SINCE=$(git log --reverse $SINCE_BRANCH... | head -n 1 | awk '{print $2;}') | |
# Get repo name | |
REPO=$(basename -s .git `git config --get remote.origin.url`) | |
# Output heading, space separated and capitalised | |
NAME="${PACKAGE//-/ }" | |
while true; do | |
# Grab the commit (this is the PR) | |
IFS= read -r -d '' COMMIT; | |
if [[ -z $COMMIT ]]; then | |
break; | |
fi | |
# echo $COMMIT | |
# Run the matcher | |
if [[ ! $COMMIT =~ $MERGE_REGEX ]]; then | |
continue | |
fi | |
# Grab the main PR | |
PR="${BASH_REMATCH[1]}" | |
# 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 humanmade/${REPO}#$PR" | |
done < <(git log $SINCE... --merges --reverse -z --raw --format="format:- %w(80,0,4)%B%n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment