Skip to content

Introduce REST API fallback #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/check-repo.sh
Original file line number Diff line number Diff line change
@@ -85,6 +85,28 @@ upstream_hash=$(

rm -f "$temp_file"

# If HTML parsing fails, fallback to using GitHub REST API
if [ -z "$upstream_hash" ]; then
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/commits"

# Try to use cached GitHub credentials from GitHub CLI
# https://docs.github.com/en/get-started/git-basics/caching-your-github-credentials-in-git
if command -v gh >/dev/null 2>&1; then
TOKEN=$(gh auth token 2>/dev/null)
if [ -n "$TOKEN" ]; then
response=$(curl -sSL -H "Authorization: token $TOKEN" "$API_URL")
fi
fi

# If response is empty (i.e. token not available or failed), use unauthenticated request.
if [ -z "$response" ]; then
response=$(curl -sSL "$API_URL")
fi

# Extract the latest commit SHA from the JSON response
upstream_hash=$(echo "$response" | grep -m 1 '"sha":' | sed -E 's/.*"sha": "([^"]+)".*/\1/')
fi

if [ -z "$upstream_hash" ]; then
throw "Failed to retrieve upstream commit hash from GitHub.\n"
fi
Loading