[FIX #3573] adding scripts/list-pull-requests.sh and scripts/generate-pull-request-report.sh
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
e77504c26f
commit
7268342ea2
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Github Client Credentials
|
||||||
|
# Required to increase rate limits to a useable level.
|
||||||
|
|
||||||
|
GITHUB_CLIENT_ID=cae8611e191547e163bb
|
||||||
|
GITHUB_CLIENT_SECRET=ebcfe4e78a6bb96933a3e2476a6d1e8efa8d8b07
|
||||||
|
|
||||||
|
# Generates a markdown report for the pull requests given in STDIN
|
||||||
|
# The input format should match the output of list-pull-requests.sh:
|
||||||
|
# [pr #] [tab] [github pr api url] [tab] [comma separated list of commits]
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "DESCRIPTION"
|
||||||
|
echo ""
|
||||||
|
# Generates a markdown report for the pull requests given in STDIN
|
||||||
|
# The input format should match the output of list-pull-requests.sh:
|
||||||
|
# [pr #] [tab] [github pr api url] [tab] [comma separated list of commits]
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
fatal() {
|
||||||
|
echo "FATAL: $@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_json() {
|
||||||
|
local json=$1
|
||||||
|
local path=$2
|
||||||
|
echo -n "$json" | jq -r "$path"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_pr_prereq() {
|
||||||
|
if ! command -v jq >/dev/null; then
|
||||||
|
fatal "jq(1) is not found, PR cannot be queried."
|
||||||
|
fi
|
||||||
|
if ! command -v curl >/dev/null; then
|
||||||
|
fatal "curl(1) is not found, PR cannot be queried."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch() {
|
||||||
|
local url="$1?client_id=$GITHUB_CLIENT_ID&client_secret=$GITHUB_CLIENT_SECRET"
|
||||||
|
fetch_result=$(curl --fail -fsS "$url")
|
||||||
|
if [ $? -ne 0 ]; then fatal "Unable to get fetch from $1"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
process_stdin() {
|
||||||
|
while IFS= read -r line; do
|
||||||
|
local pr_url=`echo "$line" | cut -f 2`
|
||||||
|
echo_pull_request "$pr_url"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_pull_request() {
|
||||||
|
local pr_url=$1
|
||||||
|
fetch "$pr_url"
|
||||||
|
local pr=$fetch_result
|
||||||
|
|
||||||
|
echo "## $(echo_json "$pr" .title) (#$(echo_json "$pr" .number))
|
||||||
|
|
||||||
|
URL: $(echo_json "$pr" .html_url)
|
||||||
|
Creator: $(echo_json "$pr" .user.login)
|
||||||
|
Labels: $(echo_json "$pr" ' [.labels[].name] | join(", ") ' )
|
||||||
|
|
||||||
|
$(echo_json "$pr" .body)
|
||||||
|
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_pr_prereq
|
||||||
|
|
||||||
|
echo "# Pull Request Report
|
||||||
|
|
||||||
|
$( process_stdin )
|
||||||
|
|
||||||
|
"
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Fetches pull request refs and prints commits
|
||||||
|
# for the given range grouped by pull request
|
||||||
|
|
||||||
|
REPOSITORY="status-im/status-react"
|
||||||
|
REPOSITORY_URL="https://github.com/$REPOSITORY.git"
|
||||||
|
PULL_REQUEST_REMOTE="pullRequestRemote"
|
||||||
|
PULL_REQUEST_URL="https://api.github.com/repos/$REPOSITORY/pulls/"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "DESCRIPTION"
|
||||||
|
echo ""
|
||||||
|
echo " Fetches pull request refs and prints commits"
|
||||||
|
echo " for the given range grouped by pull request"
|
||||||
|
echo ""
|
||||||
|
echo "USAGE"
|
||||||
|
echo ""
|
||||||
|
echo " $0 # list all commits"``
|
||||||
|
echo " $0 [ref1(..ref1)] # lists commits within given range"
|
||||||
|
echo " $0 -h # show help"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
git fetch $REPOSITORY_URL +refs/pull/*/head:refs/remotes/$PULL_REQUEST_REMOTE/pull/*
|
||||||
|
|
||||||
|
git log $1 --pretty="%D, %H" |
|
||||||
|
awk -v pull_request_url="$PULL_REQUEST_URL" -v pull_request_remote="$PULL_REQUEST_REMOTE" -F ", " '{
|
||||||
|
for (i = 1; i <= NF; ++i) {
|
||||||
|
if ($i ~ pull_request_remote "/pull/") {
|
||||||
|
split($i, temp, "/")
|
||||||
|
pr = temp[3]
|
||||||
|
pull_requests[pr] = pull_requests[pr] ", " $NF
|
||||||
|
sub(/^, /, "", pull_requests[pr])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
for (pr in pull_requests) {
|
||||||
|
print(pr "\t" pull_request_url pr "\t" pull_requests[pr])
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
exit
|
Loading…
Reference in New Issue