forked from WASION1/reserve-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_diff.sh
executable file
·49 lines (44 loc) · 1.03 KB
/
pr_diff.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -euo pipefail
readonly mode="${1:-}"
readonly github_url="https://github.com/KyberNetwork/reserve-data/pull/"
print_usage() {
cat <<EOF
Usage:
./pr_diff commit <commit-id-1> <commit-id-2>
./pr_diff timestamp <timestamp-1> <timestamp-2>
EOF
}
if [[ -z "$mode" ]]; then
print_usage
exit 1
fi
case $mode in
"timestamp")
if [[ $# -ne 3 ]]; then
print_usage
exit 1
fi
after=$2
before=$3
pr_commit_ids=($(git log --oneline --after="$after" --before="$before" \
| awk '/Merge pull request/ {print $1}'))
;;
"commit")
if [[ $# -ne 3 ]]; then
print_usage
exit 1
fi
first_commit=$2
last_commit=$3
pr_commit_ids=($(git log --oneline "$first_commit".."$last_commit" \
| awk '/Merge pull request/ {print $1}'))
;;
"*")
print_usage
exit 1
esac
for commit_id in "${pr_commit_ids[@]}"; do
git show --format="%B" "$commit_id" |\
awk -v github_url="$github_url" 'NR == 1 {$4="["$4"]("github_url substr($4,2)")"; print "* "$0; next}; /^diff --/{exit}; {print " "$0}'
done