File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,28 @@ upstream_hash=$(
8585
8686rm -f " $temp_file "
8787
88+ # If HTML parsing fails, fallback to using GitHub REST API
89+ if [ -z " $upstream_hash " ]; then
90+ API_URL=" https://api.github.com/repos/${REPO_OWNER} /${REPO_NAME} /commits"
91+
92+ # Try to use cached GitHub credentials from GitHub CLI
93+ # https://docs.github.com/en/get-started/git-basics/caching-your-github-credentials-in-git
94+ if command -v gh > /dev/null 2>&1 ; then
95+ TOKEN=$( gh auth token 2> /dev/null)
96+ if [ -n " $TOKEN " ]; then
97+ response=$( curl -sSL -H " Authorization: token $TOKEN " " $API_URL " )
98+ fi
99+ fi
100+
101+ # If response is empty (i.e. token not available or failed), use unauthenticated request.
102+ if [ -z " $response " ]; then
103+ response=$( curl -sSL " $API_URL " )
104+ fi
105+
106+ # Extract the latest commit SHA from the JSON response
107+ upstream_hash=$( echo " $response " | grep -m 1 ' "sha":' | sed -E ' s/.*"sha": "([^"]+)".*/\1/' )
108+ fi
109+
88110if [ -z " $upstream_hash " ]; then
89111 throw " Failed to retrieve upstream commit hash from GitHub.\n"
90112fi
You can’t perform that action at this time.
0 commit comments