2021-04-28 15:55:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script will filter the git history for a given revision range
|
|
|
|
# and report which PRs got landed in that range.
|
|
|
|
#
|
|
|
|
# It knows about our good and bad habits and deals with both merge
|
|
|
|
# commits, and stash/rebase merges.
|
|
|
|
#
|
|
|
|
# Example usage:
|
|
|
|
#
|
|
|
|
# ./scripts/git-log-prs HEAD~10..main
|
|
|
|
# ./scripts/git-log-prs 8376983..main --titles
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
2021-04-29 10:22:36 +00:00
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
|
2021-04-28 15:55:17 +00:00
|
|
|
usage() {
|
|
|
|
echo "$0 [ --titles ] <rev_range>"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_command_gh() {
|
|
|
|
type -P "gh" &> /dev/null || {
|
|
|
|
echo "Command 'gh' not found"
|
|
|
|
echo
|
|
|
|
echo "Macos:"
|
|
|
|
echo " brew install gh"
|
|
|
|
echo
|
|
|
|
echo "Other OS:"
|
|
|
|
echo " see https://github.com/cli/cli"
|
|
|
|
exit 1
|
2021-06-21 16:18:50 +00:00
|
|
|
} >&2
|
2021-04-28 15:55:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 10:22:36 +00:00
|
|
|
get_title() {
|
|
|
|
local sha="$1"
|
|
|
|
local pr="$2"
|
|
|
|
|
|
|
|
if [ "$(git show "${sha}" --pretty=format:%b | wc -l | awk '{print $1}')" == 1 ]; then
|
|
|
|
git show "${sha}" --pretty=format:%b
|
|
|
|
else
|
|
|
|
ensure_command_gh
|
|
|
|
gh pr view "${pr}" --json title --jq '.title'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-28 15:55:17 +00:00
|
|
|
main() {
|
|
|
|
local positionals=()
|
2021-04-29 10:22:36 +00:00
|
|
|
local commits=""
|
2021-04-28 15:55:17 +00:00
|
|
|
local titles=""
|
2021-04-29 10:22:36 +00:00
|
|
|
local git_dir="${SCRIPT_DIR}/.."
|
2021-04-28 15:55:17 +00:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
local key="$1"
|
|
|
|
|
|
|
|
case "${key}" in
|
2021-04-29 10:22:36 +00:00
|
|
|
# print titles
|
2021-04-28 15:55:17 +00:00
|
|
|
--titles)
|
|
|
|
titles=true
|
|
|
|
shift
|
|
|
|
;;
|
2021-04-29 10:22:36 +00:00
|
|
|
|
|
|
|
# print commit shas
|
|
|
|
--commits)
|
|
|
|
commits=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
|
|
|
# git directory; defaults to the repo where this script lives
|
|
|
|
-C)
|
|
|
|
git_dir="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
|
2021-04-28 15:55:17 +00:00
|
|
|
*)
|
|
|
|
positionals+=("$1")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${#positionals[@]} -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
local rev_range="${positionals[0]}"
|
2021-04-29 10:22:36 +00:00
|
|
|
cd "${git_dir}"
|
2021-04-28 15:55:17 +00:00
|
|
|
|
|
|
|
git log \
|
|
|
|
--committer='GitHub <noreply@github.com>' \
|
2021-04-29 10:22:36 +00:00
|
|
|
--pretty=format:'%h: %s' \
|
2021-04-28 15:55:17 +00:00
|
|
|
"${rev_range}" \
|
2021-04-29 10:22:36 +00:00
|
|
|
| sed 's/\([^:]*\): Merge pull request #\([0-9]*\).*/\1: \2/' \
|
|
|
|
| sed 's/\([^:]*\): .*(#\([0-9]*\))$/\1: \2/' \
|
|
|
|
| grep -E '^[a-f0-9]*: [0-9]*$' \
|
|
|
|
| while read -r line; do
|
|
|
|
read -r -a line_arr <<< "${line}"
|
|
|
|
|
|
|
|
local sha="${line_arr[0]%:}"
|
|
|
|
local pr=${line_arr[1]}
|
|
|
|
|
|
|
|
local title=""
|
|
|
|
if [ -n "${titles}" ]; then
|
2021-06-30 13:35:34 +00:00
|
|
|
title=$(get_title "${sha}" "${pr}" | sed 's;(#\([0-9]\+\));(influxdata/influxdb_iox#\1);g')
|
2021-04-29 10:22:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local commit=""
|
|
|
|
if [ -n "${commits}" ]; then
|
|
|
|
commit="${sha} "
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${commit}${pr} ${title}"
|
2021-04-28 15:55:17 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|