Repository navigation
feat(migrate-consumers): open fork PRs when the machine user lacks write access - #6
Conversation
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
Fork-PR fallback logic is sound overall — routing, collision guard, idempotent PR lookup, and dry-run reporting all work correctly. Two error-handling gaps in the new fork route could cause confusing failures or hard-to-diagnose skips.
| COMMIT_REPO="$REPO" | ||
| PR_HEAD="$BRANCH" | ||
| else | ||
| FORK_OWNER=$(gh api user --jq .login) |
There was a problem hiding this comment.
[MEDIUM] No error check on gh api user --jq .login — silent empty FORK_OWNER causes misleading downstream failures
When ROUTE=fork, FORK_OWNER is resolved via:
FORK_OWNER=$(gh api user --jq .login)Two failure paths exist:
-
gh api userexits non-zero (network error, token lacksuserscope): underset -euo pipefail, a non-zero exit from a command substitution assigned directly to a variable aborts the entire workflow run, not just this one repo. The whole migration job fails with no per-repoSUMMARY_SKIPPEDentry and no actionable error pointing to the root cause. -
ghexits 0 but.loginis empty (e.g., GitHub App token returning a different JSON shape, orjqemitting an empty string for a null field):FORK_OWNERis silently set to"", producingFORK="/repo-name". Subsequentgh api "repos//repo-name"calls fail with confusing 404s, and the repo ends up in(fork not ready)— a misleading message that hides the real problem.
Suggested fix:
FORK_OWNER=$(gh api user --jq .login) || {
echo "::warning::Could not resolve machine-user login for $REPO — skipping"
SUMMARY_SKIPPED+="- ${REPO} (could not resolve fork owner)"$'\n'
cleanup_workdir
continue
}
if [ -z "$FORK_OWNER" ]; then
echo "::warning::Machine-user login resolved to empty for $REPO — skipping"
SUMMARY_SKIPPED+="- ${REPO} (empty fork owner)"$'\n'
cleanup_workdir
continue
fi| echo "No write access on $REPO — opening a fork PR from ${FORK}" | ||
| # Fork is idempotent (no-op when it already exists) and created | ||
| # asynchronously, so poll until the API can see it. | ||
| gh repo fork "$REPO" --clone=false --default-branch-only >/dev/null 2>&1 || true |
There was a problem hiding this comment.
[MEDIUM] Fork creation errors silently swallowed — (fork not ready) is misleading when gh repo fork itself fails
gh repo fork "$REPO" --clone=false --default-branch-only >/dev/null 2>&1 || trueThe >/dev/null 2>&1 || true combination discards both output and exit code. When fork creation fails (rate limit, transient API error, permissions issue), the error message is gone and the polling loop runs for 30 seconds (10×3 s) before emitting "Fork did not become available in time — skipping". This message is accurate for the async-readiness case but misleading when the fork creation itself failed — an operator seeing it cannot distinguish "fork API is slow" from "fork creation was rejected."
The || true is intentional for idempotency (some gh versions return non-zero when the fork already exists), but that only justifies ignoring the exit code — it doesn't require discarding stderr.
Suggested fix — capture stderr so it surfaces in the skip warning:
FORK_ERR=$(gh repo fork "$REPO" --clone=false --default-branch-only 2>&1 >/dev/null || true)
# ... polling loop ...
if [ -z "$FORK_READY" ]; then
echo "::warning::Fork ${FORK} did not become available — skipping $REPO${FORK_ERR:+ (fork error: $FORK_ERR)}"
...
fi
derekmisler
left a comment
There was a problem hiding this comment.
two issues in the new fork path worth fixing before the pilot run: a jq null/false mismatch in the routing logic that can silently skip forkable repos, and a missing error handler on FORK_OWNER that would abort the whole step on a transient API failure. everything else looks solid.
| CAN_PUSH=$(gh api "repos/$REPO" --jq '.permissions.push' 2>/dev/null || echo "false") | ||
| if [ "$CAN_PUSH" = "true" ]; then | ||
| ROUTE="direct" | ||
| elif [ "$(gh api "repos/$REPO" --jq '.allow_forking' 2>/dev/null || echo "false")" = "true" ]; then |
There was a problem hiding this comment.
issue: jq returns the string "null" (not "false") when .allow_forking is absent from the API response. || echo "false" only fires when the whole gh invocation fails, not when the field is missing. so a repo with no permissions.push key and no allow_forking key both fall through here and get routed to skip, silently missing the fork path.
fix: cache the response and use // false in jq to coerce null to a boolean:
REPO_META=$(gh api "repos/$REPO" 2>/dev/null || echo '{}')
CAN_PUSH=$(echo "$REPO_META" | jq -r '.permissions.push // false')
ALLOW_FORKING=$(echo "$REPO_META" | jq -r '.allow_forking // false')bonus: one API call instead of two, which also closes the race where settings change between the two calls.
| COMMIT_REPO="$REPO" | ||
| PR_HEAD="$BRANCH" | ||
| else | ||
| FORK_OWNER=$(gh api user --jq .login) |
There was a problem hiding this comment.
issue: FORK_OWNER=$(gh api user --jq .login) has no error handler, and set -euo pipefail is active. every other fallible command in this loop has a || { ... cleanup_workdir; continue; } guard; this one is missing it. a transient API failure (rate limit, network blip, auth issue) aborts the entire migration step immediately instead of skipping just this one repo.
fix:
FORK_OWNER=$(gh api user --jq .login) || {
echo "::warning::could not resolve machine-user login -- skipping $REPO"
SUMMARY_SKIPPED+="- ${REPO} (fork-owner lookup failed)"$'\n'
cleanup_workdir
continue
}
derekmisler
left a comment
There was a problem hiding this comment.
ci is green, approving!
Summary
The first real
migrate-consumersrun opened PRs on only 16 of 64 consumers; the other 48 failed because the machine user lacks write access on those repos. This adds a fork-PR fallback so those repos can still receive a migration PR.Per repo, after the rewrite, a route is resolved:
allow_forking=true, so fork under the machine user, create the signed commit on the fork, and open a cross-repo PR (headowner:branch). Needs only read on the upstream, like an external contribution.The route is resolved before the dry-run gate, so a dry run reports the route per repo (
route: direct|fork|skip) without any writes.Coverage
billing,infra-tailscale,jit,registry-tools,secrets-engine-private) and are skipped for a write grant or a manual update.Robustness
head=owner:branch), becausegh pr list --headdoes not support that form and would never match a fork PR.Validation
bash -nand YAML parse pass.repos=docker/cli,dry-run=false) before the full run.