Skip to content

fix: authenticate cross-repo git via gh, guard clone failures (readme-refresh) - #1067

Merged
don-petry merged 4 commits into
mainfrom
fix/readme-refresh-clone-auth
Jul 3, 2026
Merged

fix: authenticate cross-repo git via gh, guard clone failures (readme-refresh)#1067
don-petry merged 4 commits into
mainfrom
fix/readme-refresh-clone-auth

Conversation

@don-petry

@don-petry don-petry commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the first live readme-refresh run (triggered post-merge of #1062), which failed to clone the target repos:

fatal: could not read Username for 'https://github.com': No such device or address

Root cause

GitHub's git-over-HTTPS rejects both the https://x-access-token:<PAT>@… URL form and an Authorization: Bearer <PAT> extraHeader when the credential is a classic/fine-grained PAT (DON_PETRY_BOT_GH_PAT) rather than a GitHub App / Actions token. Git then fell back to an interactive username prompt and died. Because the clone was unguarded, the script kept going and ran git -C <dir> diff --cached outside any repository — producing the error: unknown option 'cached' / git diff --no-index noise seen in run 28683616091 — and silently opened no PR while still exiting 0.

Fix

  • Route git's github.com credentials through gh auth setup-git (uses GH_TOKEN; token-type-agnostic — authenticates both the clone and the push).
  • Clone with a plain https:// URL and guard it: on failure, warn and skip that repo instead of generating into an empty directory.

Verification

  • shellcheck --severity=warning -x — clean.
  • Isolated dry-run (throwaway GIT_CONFIG_GLOBAL so the real gitconfig is untouched): clones both repos, generates all four READMEs, and renders correct diff stats (README.md | 34 +++, profile/README.md | 4 +++-) with no git errors.

After merge

Re-run the dry run to confirm the clone/auth path is green end-to-end in CI:

gh workflow run readme-refresh.yml --repo petry-projects/.github-private -f dry_run=true

🤖 Generated with Claude Code

https://claude.ai/code/session_01VAsu1rBxAkMnAqFZaWKV6t

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when refreshing multiple repositories by skipping repos that fail to clone instead of continuing with an empty workspace.
    • Reduced authentication-related clone and push failures by using a more consistent Git login setup.
    • Isolated temporary Git configuration changes so they don’t affect unrelated commands.

The first live run of readme-refresh failed to clone the target repos:
  fatal: could not read Username for 'https://github.com'
GitHub's git-over-HTTPS rejects both the `x-access-token:<PAT>@` URL form and
an `Authorization: Bearer <PAT>` extraHeader for a classic/fine-grained PAT, so
git fell back to an interactive prompt and died. Because the clone failure was
unguarded, the script continued and ran `git -C <dir> diff --cached` outside any
repo (the `unknown option cached` / no-index noise), silently producing no PR.

Fix:
- Configure git's github.com credentials via `gh auth setup-git` (token-type
  agnostic; authenticates both the clone and the push through GH_TOKEN).
- Clone with a plain https URL and GUARD it: on failure, warn and skip the repo
  instead of generating into an empty directory.

Verified: shellcheck --severity=warning -x clean; isolated dry-run (throwaway
GIT_CONFIG_GLOBAL) clones both repos, generates all four READMEs, and renders
correct diff stats with no git errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VAsu1rBxAkMnAqFZaWKV6t
@don-petry
don-petry requested a review from a team as a code owner July 3, 2026 21:26
Copilot AI review requested due to automatic review settings July 3, 2026 21:26
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The script's repo cloning logic was changed to remove inline http.extraHeader Authorization injection, relying instead on gh auth setup-git for credential handling. Clone failures or missing .git directories now trigger a warning and skip. Main flow isolates GIT_CONFIG_GLOBAL and runs gh auth setup-git, warning on failure.

Changes

gh Auth Setup Migration

Layer / File(s) Summary
gh-based authentication and hardened cloning
scripts/aw-readme-refresh.sh
Main flow isolates GIT_CONFIG_GLOBAL to a temp file and runs gh auth setup-git --hostname github.com (warns on failure); process_repo clone step now uses plain git clone with GIT_TERMINAL_PROMPT=0 and fails loudly (warns and returns 1) on clone failure or missing .git directory, instead of injecting an Authorization header.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Script as aw-readme-refresh.sh
  participant GH as gh CLI
  participant Git as git clone

  Script->>Script: isolate GIT_CONFIG_GLOBAL to temp file
  Script->>GH: gh auth setup-git --hostname github.com
  GH-->>Script: success or failure (warn)
  Script->>Git: git clone (GIT_TERMINAL_PROMPT=0)
  Git-->>Script: clone result
  alt clone fails or .git missing
    Script->>Script: warn and skip repo
  else clone succeeds
    Script->>Script: proceed with repo processing
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: GitHub auth via gh and safer clone failure handling in readme-refresh.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/readme-refresh-clone-auth

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates scripts/aw-readme-refresh.sh to route GitHub credentials through gh auth setup-git instead of using an explicit authorization header during git clone. It also adds a guard to skip a repository if the clone fails. The review feedback points out that returning 0 on clone failure masks the error from the caller, which expects a non-zero exit status to log the failure, and suggests returning 1 instead.

Comment thread scripts/aw-readme-refresh.sh Outdated
@don-petry
don-petry enabled auto-merge (squash) July 3, 2026 21:27
@don-petry
don-petry disabled auto-merge July 3, 2026 21:27
@donpetry-bot

Copy link
Copy Markdown
Contributor

Advisory bots were rate-limited; auto-approval is withheld until they recover. pr-review-sweep will re-review this PR after 2026-07-03T22:28:19Z.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes authentication and failure-handling for the readme-refresh automation by switching cross-repo git auth to gh auth setup-git (token-type-agnostic) and guarding clone failures so the script doesn’t proceed in a non-repo directory.

Changes:

  • Replace git-over-HTTPS Authorization: Bearer ... header cloning with plain https:// cloning authenticated via gh’s git credential helper.
  • Guard git clone failures and skip the affected repo instead of continuing and producing misleading git errors.

Comment thread scripts/aw-readme-refresh.sh
Comment thread scripts/aw-readme-refresh.sh Outdated
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (applied)

Changes committed and pushed.

@don-petry
don-petry enabled auto-merge (squash) July 3, 2026 21:33
@donpetry-bot

donpetry-bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Superseded by automated re-review at 1666fc8eeb35b77e3cd0a9d18c165daf1dac42b4 — click to expand prior review.

Review — fix requested (cycle 1/3)

The automated review identified the following issues. Please address each one:

Findings to fix

Automated review — NEEDS HUMAN REVIEW

Risk: MEDIUM
Reviewed commit: 5f70311899db2b27db849200a655dd8b9bd31db1
Review mode: triage-approved (single reviewer)

Summary

Fixes the readme-refresh cross-repo clone failure by routing git credentials through gh auth setup-git (token-type-agnostic) instead of an http.extraHeader Bearer token, and guards the clone so a failure warns and skips the repo (return 1, handled by the caller's if ! guard) instead of silently generating into an empty directory. The change also improves credential hygiene: GH_TOKEN no longer appears on the git clone command line. The prior gemini-code-assist finding (clone guard returned 0, masking the failure) was fixed in 5f70311 and its thread is resolved. Escalating only because two review threads remain unresolved (see Findings).

Linked issue analysis

No linked issues (closingIssuesReferences is empty). The PR addresses a concrete failure in the first live readme-refresh run (actions run 28683616091: fatal: could not read Username for 'https://github.com'). The root-cause analysis in the PR body is sound and the fix matches it; verification included a clean shellcheck --severity=warning -x (independently reproduced during this review) and an isolated local dry-run.

Findings

Unresolved review threads (blocking auto-approval per review policy):

  1. [Copilot, scripts/aw-readme-refresh.sh:211] Prefix the clone with GIT_TERMINAL_PROMPT=0 so that if gh auth setup-git is ever ineffective, git fails fast instead of falling back to an interactive credential prompt. Directly relevant: the original incident was exactly this fallback. Low-cost, worthwhile hardening.
  2. [Copilot, scripts/aw-readme-refresh.sh:358] gh auth setup-git writes to the user's global git config, so running the script locally permanently modifies the developer's ~/.gitconfig. Consider isolating (e.g., a scoped GIT_CONFIG_GLOBAL) — the author already used exactly this technique for local dry-run testing.

Other notes (non-blocking):

  • Secret scan: run_secret_scanning MCP tool unavailable in this environment; CI gitleaks check passed (success). Diff introduces no credentials — it removes an embedded token header.
  • shellcheck of the full modified script at head SHA: clean.

CI status

All code checks green at head SHA 5f70311: Lint, ShellCheck, bats, gh-aw-compile, template-drift, validate-agent-profiles, Compile agentic workflows, Agent Security Scan, Secret scan (gitleaks), CodeQL (actions + python), SonarCloud, unit-tests, AW workflow tests, Test-Deletion Guard, Holdout Guard, AgentShield — success. Dependency-audit sub-jobs skipped (no matching ecosystems). The only cancelled runs are the review agent's own superseded trigger jobs. Branch is BEHIND main but MERGEABLE.


Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.

Additional tasks

  1. Resolve all unresolved review thread comments from other reviewers
  2. Ensure all CI checks pass after your changes
  3. Rebase on the target branch if behind
  4. Do NOT modify files unrelated to the findings above

The review cascade will automatically re-review after new commits are pushed.

@don-petry
don-petry disabled auto-merge July 3, 2026 21:40
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — waiting on PR blockers (intent: review-changes)

PR: #1067
No changes were committed, but the PR still has blocking checks or reviews (failing or cancelled checks, or changes-requested reviews). The retry cron will re-attempt automatically. Next attempt after: 2026-07-03T22:12:08Z

@don-petry

Copy link
Copy Markdown
Collaborator Author

Note

@don-petry I reviewed this PR and no code changes were needed, but it still has blocking checks or reviews (failing or cancelled checks, or changes-requested reviews), so I cannot mark it done yet. I'll re-check automatically.
Next attempt after: 2026-07-03T22:12:08Z

@don-petry
don-petry enabled auto-merge (squash) July 3, 2026 21:42

@donpetry-bot donpetry-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review — APPROVED ✓

Risk: MEDIUM
Reviewed commit: 1666fc8eeb35b77e3cd0a9d18c165daf1dac42b4
Review mode: triage-approved (single reviewer)

Summary

Fixes the readme-refresh cross-repo clone failure by routing git credentials through gh auth setup-git (token-type-agnostic) instead of an http.extraHeader Bearer token, and guards the clone (GIT_TERMINAL_PROMPT=0, warn + skip on failure) so it fails fast instead of silently generating into an empty directory. This is a re-review after the prior fix-requested review at 5f70311: the single follow-up commit (+7/-1) resolves both prior findings — (1) GIT_TERMINAL_PROMPT=0 now prefixes the clone so an ineffective credential helper fails fast rather than falling back to the interactive prompt that caused the original incident, and (2) gh auth setup-git config writes are isolated to a throwaway GIT_CONFIG_GLOBAL temp file when unset, so local runs no longer mutate ~/.gitconfig. No new issues introduced.

Linked issue analysis

No linked issues (closingIssuesReferences is empty). The PR addresses a concrete failure in the first live readme-refresh run (actions run 28683616091: fatal: could not read Username for 'https://github.com'). The root-cause analysis in the PR body is sound, the fix matches it, and verification (clean shellcheck, isolated local dry-run) is documented.

Findings

Prior findings — all resolved:

  1. [Copilot] Prefix clone with GIT_TERMINAL_PROMPT=0 to fail fast if the credential helper is ineffectiveresolved in 1666fc8 (line 211); thread resolved.
  2. [Copilot] gh auth setup-git mutates the developer's ~/.gitconfig on local runsresolved in 1666fc8: script now exports a mktemp-backed GIT_CONFIG_GLOBAL when unset (CI already sets its own); thread resolved.
  3. [gemini-code-assist] Unguarded clone masked failure — resolved earlier in 5f70311; thread resolved.

New issues: none. All three review threads are resolved (and outdated by the fix commits).

Other notes (non-blocking):

  • Secret scan: run_secret_scanning MCP tool unavailable in this environment; CI gitleaks check passed. The diff introduces no credentials — it removes an embedded token header from the git clone command line (credential-hygiene improvement).
  • shellcheck of the full script at head SHA 1666fc8: clean (--severity=warning -x).

CI status

All checks green at head SHA 1666fc8: Lint, ShellCheck (×3), bats, unit-tests, gh-aw-compile, Compile agentic workflows, template-drift, validate-agent-profiles, AW spec/docs validation, issue-triage tests, Agent Security Scan, AgentShield, Secret scan (gitleaks), CodeQL (actions + python), SonarCloud, CodeRabbit, holdout-guard, guard — success. Dependency-audit sub-jobs skipped (no matching ecosystems). The only cancelled entries are superseded review-agent trigger jobs from earlier pushes. Branch is BEHIND main but MERGEABLE.


Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.

@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

@don-petry
don-petry merged commit c8d7fca into main Jul 3, 2026
32 of 33 checks passed
@don-petry
don-petry deleted the fix/readme-refresh-clone-auth branch July 3, 2026 21:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/aw-readme-refresh.sh`:
- Around line 362-364: The current `gh auth setup-git` handling in the
auth/bootstrap flow only warns and continues, which hides a global credential
problem. In the `aw-readme-refresh.sh` logic around the `gh auth setup-git`
check, change it to abort immediately on failure instead of calling `warn`, so
the script fails fast and surfaces the broken auth setup before later clone/push
operations run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7ecd9165-7460-40a4-83bb-b8a3335c8dc3

📥 Commits

Reviewing files that changed from the base of the PR and between 3154cd8 and 26b0080.

📒 Files selected for processing (1)
  • scripts/aw-readme-refresh.sh

Comment on lines +362 to +364
if ! gh auth setup-git --hostname github.com >/dev/null 2>&1; then
warn "gh auth setup-git failed — cross-repo git push may not authenticate"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- scripts/aw-readme-refresh.sh (around lines 330-390) ---\n'
sed -n '330,390p' scripts/aw-readme-refresh.sh | cat -n

printf '\n--- search for setup-git usage and auth-related handling ---\n'
rg -n "setup-git|GIT_TERMINAL_PROMPT|auth setup|warn .*authenticate|cross-repo git" scripts/aw-readme-refresh.sh .github -S

Repository: petry-projects/.github-private

Length of output: 259


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- scripts/aw-readme-refresh.sh outline ---\n'
ast-grep outline scripts/aw-readme-refresh.sh --view expanded

printf '\n--- nearby logic for repo refresh / clone / push ---\n'
rg -n "clone|push|pull|fetch|gh auth setup-git|GIT_TERMINAL_PROMPT|token|GITHUB_TOKEN|gh repo" scripts/aw-readme-refresh.sh -n -S

Repository: petry-projects/.github-private

Length of output: 259


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Show the relevant section and any surrounding auth/setup logic.
sed -n '340,380p' scripts/aw-readme-refresh.sh | cat -n
printf '\n'
rg -n "setup-git|GIT_TERMINAL_PROMPT|clone|push|warn " scripts/aw-readme-refresh.sh -S

Repository: petry-projects/.github-private

Length of output: 3189


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

sed -n '190,320p' scripts/aw-readme-refresh.sh | cat -n

Repository: petry-projects/.github-private

Length of output: 6615


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n "gh auth setup-git|credential helper|GIT_TERMINAL_PROMPT|clone failed|push --force-with-lease" scripts/aw-readme-refresh.sh -n -S

Repository: petry-projects/.github-private

Length of output: 679


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Inspect the repo-processing path and auth-related comments around clone/push.
sed -n '200,315p' scripts/aw-readme-refresh.sh | cat -n

Repository: petry-projects/.github-private

Length of output: 5795


Fail fast if gh auth setup-git fails.
With GIT_TERMINAL_PROMPT=0, this turns a global auth problem into repo-by-repo clone/push skips; aborting here surfaces the broken credential setup immediately.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/aw-readme-refresh.sh` around lines 362 - 364, The current `gh auth
setup-git` handling in the auth/bootstrap flow only warns and continues, which
hides a global credential problem. In the `aw-readme-refresh.sh` logic around
the `gh auth setup-git` check, change it to abort immediately on failure instead
of calling `warn`, so the script fails fast and surfaces the broken auth setup
before later clone/push operations run.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants