From 6fbb3cd9a52f0ca829963ee56471ea7701c718a9 Mon Sep 17 00:00:00 2001 From: Honggyu Kim Date: Thu, 15 Aug 2024 00:17:28 +0900 Subject: [PATCH] misc: Add checkout-pr.sh script for easier checkout It usually takes some time to get patches for review but it'd be useful to have a script for that. The 'checkout-pr.sh' script accepts a single parameter to get the pull request ID. It fetches from the source repo and checkouts to the fetched head. The example usage is as follows. $ ./misc/checkout-pr.sh 1974 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 18502 100 18502 0 0 39899 0 --:--:-- --:--:-- --:--:-- 39875 remote: Enumerating objects: 1, done. remote: Counting objects: 100% (1/1), done. remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0) Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done. From https://github.com/GabrielKimm/uftrace * branch fix-tui-non-utf8-locale -> FETCH_HEAD Switched to and reset branch 'pull/1974' Now you're ready to review the pull request 1974 where can be found at https://github.com/namhyung/uftrace/pull/1974. Signed-off-by: Honggyu Kim --- misc/checkout-pr.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 misc/checkout-pr.sh diff --git a/misc/checkout-pr.sh b/misc/checkout-pr.sh new file mode 100755 index 000000000..f2796c43f --- /dev/null +++ b/misc/checkout-pr.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +if [ $# -ne "1" ]; then + echo "usage: $0 " + exit 1 +fi + +if [ ! -x "$(command -v curl)" ]; then + echo "You need curl to run this script." + exit 1 +fi + +pr=$1 +pr_json="pr.json" + +curl -o $pr_json https://api.github.com/repos/namhyung/uftrace/pulls/$pr +repo=$(jq -r '.head.repo.html_url' $pr_json) +refspec=$(jq -r '.head.ref' $pr_json) +git fetch $repo $refspec && git checkout -B pull/$pr FETCH_HEAD +exit 0