github-merge-pr: add option to use SSH key for github auth
authorChristian Marangi <ansuelsmth@gmail.com>
Thu, 15 Feb 2024 20:53:55 +0000 (21:53 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Thu, 15 Feb 2024 21:02:07 +0000 (22:02 +0100)
Add option to use SSH key for github auth.

To enable this, edit the script and uncomment the USE_SSH=1 line.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
github-merge-pr.sh

index 863d3b753aa0d5bd0c15156ba4e8171f7b320143..b30b519193870a68290d9a7637e77513e9b8e35b 100755 (executable)
@@ -9,6 +9,9 @@ REPO="openwrt/openwrt"
 # - Enter a description, e.g. "pr.sh" and pick the "repo" scope
 # - Hit "Generate token"
 #TOKEN="d41d8cd98f00b204e9800998ecf8427e"
+#
+# Uncomment this line to use SSH key to rebase PR branch
+# USE_SSH=1
 
 PRID="$1"
 BRANCH="${2:-master}"
@@ -75,7 +78,11 @@ fi
 PR_USER="$(echo "$PR_INFO" | jq -r ".head.user.login")"
 PR_BRANCH="$(echo "$PR_INFO" | jq -r ".head.ref")"
 LOCAL_PR_BRANCH="$PR_BRANCH"-"$PR_USER"
-PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.html_url")"
+if [ "$USE_SSH" = "1" ]; then
+       PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.ssh_url")"
+else
+       PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.html_url")"
+fi
 
 if ! $GIT remote get-url $PR_USER &> /dev/null || [ -n "$DRY_RUN" ]; then
        echo "Adding $PR_USER with repo $PR_REPO to remote"