From eae02da0742fe9bfa310e6952cc14e66311b8d15 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 17:48:19 +0000 Subject: [PATCH 1/2] gitea-github-sync: show the actual HTTP response on a failed user check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Failed to reach GitHub API. Check GITHUB_TOKEN." (and the equivalent Gitea message) pointed at the token every time, even when the real cause was something else entirely — confirmed live twice in one debugging session: once a GitHub-side 503 outage, once a Gitea account locked behind a must-change-password 403. Both times the fix was to run the same curl by hand to see the actual status/response. Fold that same probe into the script itself: on failure, re-request with -i and print the HTTP status and response body directly, so the failure mode (bad token vs. remote outage vs. account lock vs. network/DNS) is visible immediately instead of requiring a manual curl round-trip. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YEQNc4NfBST1m9NtCZVYa8 --- vendor/ai-stack/gitea-github-sync.sh | 34 ++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/vendor/ai-stack/gitea-github-sync.sh b/vendor/ai-stack/gitea-github-sync.sh index 2624cdb..da9084f 100755 --- a/vendor/ai-stack/gitea-github-sync.sh +++ b/vendor/ai-stack/gitea-github-sync.sh @@ -87,6 +87,26 @@ _github_api() { _log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> "$LOG_FILE"; } +# On a failed API call, "check your token" is often wrong — it could just as +# easily be the remote service down, an account locked behind a +# must-change-password wall, or a network/DNS problem. Re-probe with -i so +# the actual HTTP status and response body are visible, instead of leaving +# the user to run curl by hand to find out which one it actually was. +_probe_and_report() { + local _what="$1" _url="$2"; shift 2 + local _tmp _code _body + _tmp="$(mktemp)" + _code="$(curl -sS -o "$_tmp" -w '%{http_code}' "$@" "$_url" 2>/dev/null)" + _body="$(cat "$_tmp" 2>/dev/null)" + rm -f "$_tmp" + if [[ -z "$_code" || "$_code" == "000" ]]; then + warn " $_what: no HTTP response at all — network/DNS problem reaching $_url, not a credentials problem." + else + warn " $_what responded: HTTP $_code" + [[ -n "$_body" ]] && warn " ${_body:0:300}" + fi +} + # ── config management ────────────────────────────────────────────────────── load_config() { mkdir -p "$CONFIG_DIR" "$WORK_DIR" @@ -155,12 +175,22 @@ do_init() { # Discover usernames info "Detecting GitHub user..." GITHUB_USER=$(_github_api GET /user | python3 -c "import sys,json; print(json.load(sys.stdin)['login'])" 2>/dev/null) \ - || { err "Failed to reach GitHub API. Check GITHUB_TOKEN."; exit 1; } + || { + err "Failed to reach GitHub API. Check GITHUB_TOKEN." + _probe_and_report "GitHub" "https://api.github.com/user" \ + -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" + exit 1 + } ok "GitHub user: $GITHUB_USER" info "Detecting Gitea user..." GITEA_USER=$(_gitea_api GET /user | python3 -c "import sys,json; print(json.load(sys.stdin)['login'])" 2>/dev/null) \ - || { err "Failed to reach Gitea API. Check GITEA_TOKEN and GITEA_URL ($GITEA_URL)."; exit 1; } + || { + err "Failed to reach Gitea API. Check GITEA_TOKEN and GITEA_URL ($GITEA_URL)." + _probe_and_report "Gitea" "$GITEA_URL/api/v1/user" \ + -H "Authorization: token $GITEA_TOKEN" + exit 1 + } ok "Gitea user: $GITEA_USER" # Ask about sync scope From bd6c5d445ac98e4d95fbd7296cc84b99b49107a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 17:52:13 +0000 Subject: [PATCH 2/2] gitea-github-sync: fix set -e aborting do_sync on the first successful repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ((pull_count++)) evaluates to the PRE-increment value — 0 on the very first successful pull/push — and under this script's `set -euo pipefail`, an arithmetic command evaluating to 0 counts as a failing command and kills the script immediately. Confirmed live: a real, fully successful GitHub -> Gitea pull (visible in sync.log as "PULL ... OK") still made the whole run exit non-zero and get reported as "Sync run failed", purely because it was the first repo to sync (0 -> 1). Any subsequent repo in the same run would have been fine, but most real installs only have a handful of repos, so this could look like sync is just broken. Switched all three counters (pull_count, push_count, fail_count) to assignment form (`count=$((count + 1))`), which always exits 0 regardless of the resulting value. page++ elsewhere in the file starts at 1, not 0, so it isn't affected by this and was left as-is. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YEQNc4NfBST1m9NtCZVYa8 --- vendor/ai-stack/gitea-github-sync.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/ai-stack/gitea-github-sync.sh b/vendor/ai-stack/gitea-github-sync.sh index da9084f..2afd857 100755 --- a/vendor/ai-stack/gitea-github-sync.sh +++ b/vendor/ai-stack/gitea-github-sync.sh @@ -381,9 +381,9 @@ do_sync() { [[ -n "$SINGLE_REPO" && "$name" != "$SINGLE_REPO" ]] && continue is_excluded "$name" && continue if sync_github_to_gitea "$name" "$url" "$priv"; then - ((pull_count++)) + pull_count=$((pull_count + 1)) else - ((fail_count++)) + fail_count=$((fail_count + 1)) fi done < <(get_github_repos) fi @@ -402,9 +402,9 @@ do_sync() { continue fi if sync_gitea_to_github "$name" "$url" "$priv"; then - ((push_count++)) + push_count=$((push_count + 1)) else - ((fail_count++)) + fail_count=$((fail_count + 1)) fi done < <(get_gitea_repos) fi