2019-07-11 16:08:23 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
readonly URL='https://github.com/MetaMask/metamask-extension'
|
|
|
|
|
2018-11-08 03:02:12 +01:00
|
|
|
git fetch --tags
|
2019-07-11 16:08:23 +02:00
|
|
|
|
|
|
|
most_recent_tag="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
|
|
|
|
|
|
|
|
git rev-list "${most_recent_tag}"..HEAD | while read commit
|
|
|
|
do
|
|
|
|
subject="$(git show -s --format="%s" "$commit")"
|
|
|
|
|
|
|
|
# Squash & Merge: the commit subject is parsed as `<description> (#<PR ID>)`
|
|
|
|
if grep -E -q '\(#[[:digit:]]+\)' <<< "$subject"
|
|
|
|
then
|
|
|
|
pr="$(awk '{print $NF}' <<< "$subject" | tr -d '()')"
|
|
|
|
prefix="[$pr]($URL/pull/${pr###}): "
|
|
|
|
description="$(awk '{NF--; print $0}' <<< "$subject")"
|
|
|
|
|
|
|
|
# Merge: the PR ID is parsed from the git subject (which is of the form `Merge pull request
|
|
|
|
# #<PR ID> from <branch>`, and the description is assumed to be the first line of the body.
|
|
|
|
# If no body is found, the description is set to the commit subject
|
|
|
|
elif grep -E -q '#[[:digit:]]+\sfrom' <<< "$subject"
|
|
|
|
then
|
|
|
|
pr="$(awk '{print $4}' <<< "$subject")"
|
|
|
|
prefix="[$pr]($URL/pull/${pr###}): "
|
|
|
|
|
|
|
|
first_line_of_body="$(git show -s --format="%b" "$commit" | head -n 1 | tr -d '\r')"
|
|
|
|
if [[ -z "$first_line_of_body" ]]
|
|
|
|
then
|
|
|
|
description="$subject"
|
|
|
|
else
|
|
|
|
description="$first_line_of_body"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Normal commits: The commit subject is the description, and the PR ID is omitted.
|
|
|
|
else
|
|
|
|
pr=''
|
|
|
|
prefix=''
|
|
|
|
description="$subject"
|
2018-11-08 03:02:12 +01:00
|
|
|
fi
|
2019-07-11 16:08:23 +02:00
|
|
|
|
2018-11-08 17:54:08 +01:00
|
|
|
# add entry to CHANGELOG
|
2019-07-11 16:08:23 +02:00
|
|
|
if [[ "$OSTYPE" == "linux-gnu" ]]
|
|
|
|
then
|
|
|
|
# shellcheck disable=SC1004
|
2018-11-08 23:04:38 +01:00
|
|
|
sed -i'' '/## Current Develop Branch/a\
|
2019-07-11 16:08:23 +02:00
|
|
|
- '"$prefix$description"''$'\n' CHANGELOG.md
|
|
|
|
else
|
|
|
|
# shellcheck disable=SC1004
|
2018-11-08 23:04:38 +01:00
|
|
|
sed -i '' '/## Current Develop Branch/a\
|
2019-07-11 16:08:23 +02:00
|
|
|
- '"$prefix$description"''$'\n' CHANGELOG.md
|
2018-11-08 23:04:38 +01:00
|
|
|
fi
|
2019-07-11 16:08:23 +02:00
|
|
|
done
|
|
|
|
|
2018-11-08 18:51:07 +01:00
|
|
|
echo 'CHANGELOG updated'
|