2022-03-01 09:06:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-09-05 12:45:46 +00:00
|
|
|
set -eo pipefail
|
2022-03-01 09:06:05 +00:00
|
|
|
|
|
|
|
if [[ -z $(git diff --cached --name-only -r | grep status-go-version.json) ]]; then
|
|
|
|
exit 0 # No status-go-version.json changes found.
|
|
|
|
fi
|
|
|
|
|
2022-09-05 12:45:46 +00:00
|
|
|
# MacOS sed is garbage and interprets newlines differently.
|
|
|
|
[[ "$(uname)" -eq "Darwin" ]] && NL=$'\\\n' || NL="\n"
|
|
|
|
|
2022-03-01 09:06:05 +00:00
|
|
|
MERGE_BASE=$(git merge-base -a develop "$(git rev-parse --abbrev-ref HEAD)" develop)
|
2022-09-05 10:51:26 +00:00
|
|
|
GO_COMMIT_MERGE_BASE=$(git show "${MERGE_BASE}":status-go-version.json | awk -F'"' '/commit-sha1/{print $4}')
|
|
|
|
GO_COMMIT_CURRENT=$(awk -F'"' '/commit-sha1/{print $4}' status-go-version.json)
|
2022-03-01 09:06:05 +00:00
|
|
|
GITHUB_LINK_PREFIX="https://github.com/status-im/status-go/compare/"
|
|
|
|
# Link to the current StatusGo changelog being updated.
|
2022-06-02 11:24:10 +00:00
|
|
|
GITHUB_LINK="${GITHUB_LINK_PREFIX}${GO_COMMIT_MERGE_BASE::8}...${GO_COMMIT_CURRENT::8}"
|
2022-03-01 09:06:05 +00:00
|
|
|
|
|
|
|
COMMIT_MSG_FILE=$1
|
|
|
|
# Check if the commit message already contains the link (rebase) and update otherwise insert into line2
|
2022-03-19 13:39:30 +00:00
|
|
|
if ! grep -qF "${GITHUB_LINK_PREFIX}" "${COMMIT_MSG_FILE}" >/dev/null; then
|
|
|
|
sed -in'' -e "2i\\
|
2022-09-05 12:45:46 +00:00
|
|
|
${NL}${GITHUB_LINK}" "${COMMIT_MSG_FILE}"
|
2022-03-19 13:39:30 +00:00
|
|
|
else
|
|
|
|
sed -in'' -e "s;^${GITHUB_LINK_PREFIX}.*$;${GITHUB_LINK};" "${COMMIT_MSG_FILE}"
|
|
|
|
fi
|