Skip to content

Fold pr_review.py's Repeated Refusal, Subprocess, Write-Confirmation, and Ref Checks Into Helpers #3459

Closed

Description

@ptr727

Context

scripts/pr_review.py repeats four shapes at each site that needs them:

  • The write refusal. A refusal prints status=<KIND> nothing was written: <why> and returns its code at about sixteen sites across comment_on_pr, attest, reply_to_thread, and wait. Four of those are the same out-of-scope block that returns 64.
  • The subprocess call. origin_owner, receipt_reading, _git, _gh_run, and head_carries each repeat capture, UTF-8 decoding, a timeout, check=False, and turning OSError or SubprocessError into a failed result.
  • The write confirmation. comment_on_pr and both steps of answer_thread each dig the mutation result out through .get(k) or {}, then print the status and a truncated response on failure.
  • The ref check. UNSAFE_REF.search(x) or DOT_SEGMENT.search(x) appears three times, and pr_cleanup.py reaches DOT_SEGMENT through the gate.

Suggested Change

  • Add not_written(status, why, code) and scope_refusal(owner).
  • Add one _run(argv, timeout, ...). _git, _gh_run, and head_carries stay defined as thin wrappers, since tests patch them, and origin_owner keeps its broad except, since a decode error is not an OSError.
  • Add mutated(...) and unconfirmed(...) beside gh_graphql, which tests patch in place.
  • Add safe_ref(ref) and use it at every site, pr_cleanup.py included.

Done When

Each shape has one primitive, every site uses it, and every printed status= line and exit code is unchanged.

Activity

  1. added
    enhancement
    script
    on Oct 25, 2026
  2. added a commit that references this issue on Oct 26, 2026
    5344d82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions