github-merge-pr: Use GITHUB_TOKEN for API access
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 6 Jul 2024 16:07:22 +0000 (18:07 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 16 Jul 2024 17:09:37 +0000 (19:09 +0200)
Use the GITHUB_TOKEN also for the public https://api.github.com
accesses. Over some networks like public hotspots github is blocking
unauthenticated access.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
github-merge-pr.sh

index dd08a89019cf78f41c9dc0a9a81fd45783a0b007..db49c92860e1f189f4e305118d1aafd0ed423a0a 100755 (executable)
@@ -77,7 +77,13 @@ if [ -z "$(git branch --list "$BRANCH")" ]; then
        exit 2
 fi
 
-if ! PR_INFO="$(curl -f -s "https://api.github.com/repos/$REPO/pulls/$PRID")"; then
+if [ -n "$GITHUB_TOKEN" ]; then
+       CURL_CMD=" --user \"$GITHUB_TOKEN:x-oauth-basic\" "
+else
+       CURL_CMD=" "
+fi
+
+if ! PR_INFO="$(curl $CURL_CMD -f -s "https://api.github.com/repos/$REPO/pulls/$PRID")"; then
        echo "Failed fetch PR #$PRID info" >&2
        exit 3
 fi