Skip to content

refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891

Closed

Description

@dan-petty

Ready: implementation plan (refined 2026-10-17 at 3dd7fa6)

This section supersedes any text below that conflicts with it.

Decisions

  • Whether this item waits for all of refactor(github): the github session owns transport, ledger, error classes and link pagination #983: no. It needs only refactor(github): the github session owns transport, ledger, error classes and link pagination #983's PR 1 (session.rest(), the not-found, unread and scope error classes, the origin hook, pacing and ledger feed) and PR 2 (session.paginate()). refactor(github): the github session owns transport, ledger, error classes and link pagination #983's later PRs (gh-output classifier, run_gh paging, roadmap store, ETag cache, fake promotion) touch nothing this item calls.
  • How responses are typed: pydantic models of only the fields each caller reads, validated from gidgethub's JSON, per the owner's 2026-10-08 refactor(github): the github session owns transport, ledger, error classes and link pagination #983 decision. They live in src/devops_cli/github/client.py beside RepoInfo (:29): PullRequest (title, and head and base as a CommitRef with sha, ref and repository full name), PullRequestFile (filename, status, previous filename, additions, changes).
  • Whether the GitHubClient name stays: yes, as the typed facade over the session. It is built as GitHubClient(session) by session.client (src/devops_cli/github/session.py:52-57) and holds the real calls, so it is not a shim.
  • What a pull request read sends: GET /repos/{repo}/pulls/{n} for get_pull, and a new get_pull_files(repo, n) that pages pulls/{n}/files?per_page=100 with session.paginate(). A head repository that GitHub returns as null (a deleted fork) is None in the model, and callers fall back to the base repository as today's or repo does (src/devops_cli/ai/review/runner.py:873-874).
  • How get_file_at reads a file: the JSON contents endpoint, GET /repos/{repo}/contents/{path}?ref={ref}, base64-decoded. It returns None for a 404, a directory listing, an encoding other than base64 (a file over 1 MB) or bytes that are not UTF-8, and raises the session's GitHubUnreadError for any other failure. That keeps today's contract (absent, binary or too large, client.py:105-114) and stops a failed read from looking like a missing file.
  • How get_merge_base reads: GET /repos/{repo}/compare/{base}...{head}?per_page=1, returning merge_base_commit.sha, None only on a 404.
  • How an org's repositories are listed: GET /orgs/{org}/repos?type=all (or type=public). On GitHubNotFoundError with org == session.login, GET /user/repos?affiliation=owner&visibility=all (or public). repos clone-org <login> then clones the repositories the account owns into that login's directory; PyGithub's user.get_repos() also returned collaborator and organization repositories, which belong under other owners.
  • Whether the review's posting changes: no. devops review pr posts one issue comment with POST /repos/{repo}/issues/{n}/comments, and a dry run posts nothing.
  • What happens to the label methods: deleted with _get_github_client (src/devops_cli/commands/gh.py:141-148). GhCliClient already implements LabelClient (src/devops_cli/github/labels.py:111-119), so gh labels sync uses GhCliClient(target_repo) and _get_repo_labels drops its PyGithub fallback (commands/gh.py:165-170). Two implementations of one protocol become one.
  • How SSH keys are registered: one path, on the session. register_key_on_github lists /user/keys and /user/ssh_signing_keys with paginate() and posts only the keys that are missing. The gh path (_register_with_gh, _gh_auth_ok, _gh_list_keys, _gh_add_key, src/devops_cli/github/ssh.py:51-145) is deleted, because since refactor(github): one github session per identity owning token, quota and transport #767 both paths act as the same identity. A 422 after the list is a failure, not "already registered": GitHub reports a duplicate key only in message text (error code custom), and the list decides that structurally.
  • What a missing scope says: a GitHubScopeError from either SSH call becomes SSHRegistrationError with today's hint, gh auth refresh -h github.com -s admin:public_key,write:ssh_signing_key (ssh.py:139-143).
  • SSHRegistrationError's base: GitHubOperationError instead of RuntimeError (ssh.py:20). AGENTS.md requires domain errors to inherit DevOpsCLIError, and commands/ssh.py:161 and :250 catch it by name, so nothing else changes.
  • Which methods go as dead: create_pr_review_comment (client.py:150-167), delete_user_ssh_key (:96-97), get_issues, create_issue, edit_issue (:202-263), get_pages_info and get_pages_builds (:267-279). rg finds no caller of any of them in src (the create_issue hits are the roadmap store's own method). The milestone methods are already gone (refactor(github): roadmap store that reads and writes items, releases and board fields behind one interface #768), so fix(github): gh milestones edit without --state closes the milestone #777's default no longer applies here.
  • get_pr_diff and _add_signing_key: already on the session after refactor(github): the github session owns transport, ledger, error classes and link pagination #983's PR 1; this item does not touch them except that the signing key joins the one SSH path.
  • Whether removing PyGithub drops anything else: no. pyjwt stays through mcp, pynacl is declared directly (pyproject.toml:41, fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120), and requests and urllib3 stay through other packages (checked in uv.lock).
  • What happens to the other PyGithub mentions in src: the docstrings at commands/repos.py:60, commands/gh.py:142, github/session.py:7, :54, github/client.py:1, :40, :102 and github/ssh.py:38, :47 go with the code they describe, and the reset-margin comment at src/devops_cli/config/constants.py:1036-1039 keeps its reason (GitHub reports reset in whole seconds) but no longer cites PyGithub's source; the 1 s margin itself is unchanged. The criterion rg -i pygithub src then holds without an exception.
  • How the docs change: ai/knowledge_base/devops_cli/libraries/pygithub.md is deleted with its row in the knowledge-base README (src/devops_cli/ai/knowledge_base/README.md:50); python_packages.md (:39, :171-172) names gidgethub and the session instead; AGENTS.md:85 drops "PyGithub" from its deprecation list, edited in place; docs/KNOWLEDGE_BASE.md is regenerated with uv run devops docs generate --sync-readme.

Delivery

  1. PR 1 (M): pull requests, files, merge base and repositories on the session. GitHubClient(session), the two models, get_pull, get_pull_files, get_file_at, get_merge_base, get_org_repos and a create_issue_comment(repo, n, body); the review runner, devops review pr, devops analyze pr and devops repos clone-org use them; the dead methods, the label methods and _get_github_client are deleted. Tests first, all over refactor(github): the github session owns transport, ledger, error classes and link pagination #983's github_api fake: a recorded PR payload with two pages of files (the second reached through Link) gives analyze pr and the review's PR fetch the same title and changed-file list as before; get_file_at returns None for a 404, a directory, encoding: none and non-UTF-8 bytes, and raises GitHubUnreadError on a 500 after the retries; get_merge_base returns None on a 404 and raises on a 500; devops review pr sends exactly one POST /repos/{repo}/issues/{n}/comments, and none with --dry-run; repos clone-org lists /orgs/{org}/repos, and falls back to /user/repos?affiliation=owner only when the org is a 404 and the name is the session's login; every request carries the session's token; gh labels sync --dry-run runs on GhCliClient. Files: src/devops_cli/github/client.py, src/devops_cli/github/session.py, src/devops_cli/github/labels.py, src/devops_cli/ai/review/runner.py, src/devops_cli/commands/review.py, src/devops_cli/commands/analyze.py, src/devops_cli/commands/repos.py, src/devops_cli/commands/gh.py, new tests/fixtures/github/ payloads, tests/test_github_client.py, tests/test_github_session.py, tests/test_analyze.py, tests/test_repos.py, tests/test_review_pr_post.py, tests/test_review_scope.py, tests/test_review_runner.py, tests/test_review_path_routing.py, tests/test_batch_2_review_defects.py, tests/test_gh_cmd.py, tests/test_github_milestones.py. Refs refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891.
  2. PR 2 (S): SSH keys on the session, and PyGithub removed. One registration path, SSHRegistrationError under GitHubOperationError, the key methods on GitHubClient, then PyGithub out of pyproject.toml:16 and uv.lock, the knowledge-base page and the AGENTS.md mention. Tests first: over the fake, register_key_on_github lists both endpoints and posts only the missing key; a key present in both lists sends no POST; a 422 on the POST raises SSHRegistrationError; a 403 whose x-accepted-oauth-scopes names write:ssh_signing_key raises it with the refresh hint; no gh subprocess runs. Files: src/devops_cli/github/ssh.py, src/devops_cli/github/client.py, src/devops_cli/github/session.py, src/devops_cli/config/constants.py, pyproject.toml, uv.lock, src/devops_cli/ai/knowledge_base/devops_cli/libraries/pygithub.md (deleted), src/devops_cli/ai/knowledge_base/README.md, src/devops_cli/ai/knowledge_base/devops_cli/python_packages.md, AGENTS.md, docs/KNOWLEDGE_BASE.md, tests/test_github_ssh.py, tests/test_ssh.py, changelog.d/891.md. Closes refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891.

Acceptance criteria

  • rg -n "^\s*(from github( |\.)|import github$)" src tests prints nothing.
  • rg -n -i pygithub pyproject.toml uv.lock src AGENTS.md prints nothing.
  • Review, analyze, repos clone-org and SSH key registration run over httpx2.MockTransport in their tests, every request carries the session's token, and no test patches PyGithub, httpx2 or gidgethub.
  • get_file_at returns None on a 404, a directory, a file over 1 MB and non-UTF-8 bytes, and raises GitHubUnreadError on a 500 after the retries; get_merge_base returns None only on a 404.
  • For the recorded PR payload, analyze pr and the review's PR fetch build the same title and changed-file list as before, including the files on the second page.
  • devops review pr posts exactly one issue comment through POST /repos/{repo}/issues/{n}/comments, and a dry run posts none.
  • register_key_on_github runs no gh subprocess, posts only missing keys, and treats a 422 as a failure.
  • rg -n "_get_github_client|create_pr_review_comment|delete_user_ssh_key|get_pages_builds|_register_with_gh|_gh_add_key" src tests prints nothing.
  • uv run devops ci passes within its 5-minute budget; each new test runs in under 1 s and opens no socket.
  • changelog.d/891.md lists the PyGithub removal under ### Removed and the typed client under ### Changed; CHANGELOG.md is untouched.
  • Pending a person (live GitHub, read-only): from the repository root, uv run devops analyze pr <an open PR number> --no-enhanced lists that PR's changed files.

Current references

  • PyGithub pin: pyproject.toml:16; pynacl pin: pyproject.toml:41
  • RepoInfo, GitHubClient.__init__: src/devops_cli/github/client.py:29, :39-46
  • get_org_repos: src/devops_cli/github/client.py:48-85
  • SSH key methods: src/devops_cli/github/client.py:87-97
  • get_pull, get_file_at, get_merge_base: src/devops_cli/github/client.py:101-129
  • create_pr_review_comment: src/devops_cli/github/client.py:150-167
  • Label, issue and Pages wrappers: src/devops_cli/github/client.py:171-279
  • GitHubSession.client: src/devops_cli/github/session.py:52-57
  • register_key_on_github, _register_with_token_api, gh path, _add_signing_key: src/devops_cli/github/ssh.py:24, :37, :51-145, :148
  • SSHRegistrationError: src/devops_cli/github/ssh.py:20
  • LabelClient: src/devops_cli/github/labels.py:111-119
  • _get_github_client, _get_repo_labels, labels sync: src/devops_cli/commands/gh.py:141-148, :151-171, :244
  • Review PR fetch: src/devops_cli/ai/review/runner.py:793-833 (_prepare_pr_content), :836 (_pr_changed_file), :845 (_pr_base_revision), :866 (_materialize_pr_head)
  • _resolve_pr_files, _post_pr_review_comment: src/devops_cli/commands/review.py:595, :608-635
  • analyze_pr PR read: src/devops_cli/commands/analyze.py:520-571
  • _require_client, clone_org, its get_org_repos call: src/devops_cli/commands/repos.py:59-65, :148, :183
  • SSH command callers: src/devops_cli/commands/ssh.py:161, :202, :250, :307
  • Knowledge base: src/devops_cli/ai/knowledge_base/devops_cli/libraries/pygithub.md, src/devops_cli/ai/knowledge_base/README.md:50, src/devops_cli/ai/knowledge_base/devops_cli/python_packages.md:39, :171-172, docs/KNOWLEDGE_BASE.md:32
  • AGENTS.md PyGithub mention: AGENTS.md:85
  • Other PyGithub mentions: src/devops_cli/commands/repos.py:60, src/devops_cli/commands/gh.py:142, src/devops_cli/github/session.py:7, :54, src/devops_cli/github/client.py:1, :40, :102, src/devops_cli/github/ssh.py:38, :47, src/devops_cli/config/constants.py:1036-1039

Dependencies and order


Context & Rationale

GitHubClient wraps PyGithub: pyproject.toml:16 pins PyGithub==2.10.0, and the client is built at github/client.py:39-46. After #767, the client is built only from the session's token. Its calls still use PyGithub's own HTTP stack, retries and rate handling, so they bypass the session's quota ledger, retry policy and error classes. Checked at ef21785:

  • Pull requests. get_pull returns a PyGithub PullRequest (client.py:136-138).
    • ai/review/runner.py:1885-1889 reads its title.
    • _materialize_pr_head (:1897-1940) reads head and base through getattr, calls get_files(), and fetches files with get_file_at.
    • commands/review.py:556 lists the changed files, and :588 posts with pull.create_issue_comment.
    • commands/analyze.py:612-616 and :663 make the same reads.
  • File reads. get_file_at (client.py:140-149) returns None on any exception, so a failed read looks like a missing file.
  • Repositories. get_org_repos (:83-120) is used by commands/repos.py:177.
  • SSH keys. The SSH key methods (:122-132) are used by github/ssh.py:38-49.
  • Dead methods. create_pr_review_comment (:170-189) and delete_user_ssh_key (:131-132) have no callers.
  • Labels and milestones. These methods (:191-312) are reached through _get_github_client (commands/gh.py:133-141) and commands/release.py:1616, unless refactor(github): roadmap store that reads and writes items, releases and board fields behind one interface #768's Releases slice has already removed them. edit_milestone defaults to state="closed" (:276; see fix(github): gh milestones edit without --state closes the milestone #777).
  • Tests. PyGithub mocks are built in tests/test_github_client.py, test_repos.py, test_analyze.py, test_ssh.py, test_github_ssh.py, test_review_pr_post.py, test_review_scope.py, test_review_runner.py, test_review.py and test_gh_cmd.py.
  • Agent guidance. ai/knowledge_base/devops_cli/libraries/pygithub.md teaches agents to use PyGithub, and AGENTS.md:109 lists it.

Scope & Deliverables

  • Deliverable: the remaining GitHubClient methods call session.rest() and session.paginate() and return pydantic models. PyGithub is removed.
    • A PullRequest model carries the title, the head and base SHA and repository, and the changed files from pulls/{n}/files. The review, analyze, repos and SSH callers use it.
    • devops review pr posts its single comment with POST /repos/{repo}/issues/{n}/comments, as it does today.
    • get_file_at returns None only on a 404. Any other failure raises the session's unread error.
    • create_pr_review_comment and delete_user_ssh_key are deleted. So are the label and milestone methods, if refactor(github): roadmap store that reads and writes items, releases and board fields behind one interface #768 hasn't already removed them.
    • Removed without shims: PyGithub from pyproject.toml and uv.lock, pygithub.md, and the PyGithub mention at AGENTS.md:109.
  • Acceptance criteria:
    • Both of these print nothing; the reviewer runs them:
      • rg -n "^\s*(from github( |\.)|import github$)" src tests
      • rg -n -i pygithub pyproject.toml uv.lock src AGENTS.md
    • The rewritten tests run review, analyze, repos clone-org and SSH key registration on httpx2.MockTransport. Each asserts that every request carries the session's token. Verified by unit tests.
    • get_file_at returns None on a 404 and raises the unread error on a 500 after retries. Verified by a unit test.
    • For a recorded PR payload, analyze pr and the review's PR fetch build the same title and changed-file list as before. Verified by a unit test with a fixture.
    • uv run devops ci stays within its 5-minute budget. Each new test runs in under 1 s, and no test opens a socket.
    • Person check (live GitHub, read-only). From the repo root, uv run devops analyze pr <an open PR number> --no-enhanced lists that PR's changed files.
  • Key questions:
    • Does the GitHubClient name stay? (proposed) Yes. It becomes the typed REST facade over the session and holds the real calls, so it is not a shim.
    • Do the review's posting semantics change? (proposed) No. It still posts one issue comment.
    • How are an org's repositories listed? (proposed) With GET /orgs/{org}/repos, as today. When the name is the signed-in user (session.login), they come from GET /user/repos?affiliation=owner, which matches today's user.get_repos() fallback.
  • Constraint: no new dependency. No request leaves the session.

Strategic Alignment

Split off #767 during the v0.2.25/v0.2.26 readiness review (2026-10-01): Moving the PyGithub calls off it touches review, analyze, repos and SSH code and about ten test modules. That would push #767 past one PR. The roadmap service doesn't use these calls, and #767 already builds GitHubClient from the session's token, so the identity constraint holds without this. What it adds is one ledger, retry policy and error model for those calls.

Update 2026-10-08: refinement

Per the owner's #983 decision, gidgethub returns JSON and callers validate their fields; PyGithub stays until #983 lands. Depends on #983 and #1120 (PyNaCl). Five more methods have no caller (github/client.py:202-280).

  • get_merge_base and get_file_at return None only on a 404.
  • One SSH key path; only a 422 naming an existing key counts as registered (github/ssh.py:150, :162).

Proposed design

Problem statement

The GitHubClient class currently wraps PyGithub, which bypasses the session's quota ledger, retry policy, and error classes. This issue refactors the client to use the GitHub session directly for all API calls, removing PyGithub dependency.

Acceptance criteria

  • Criterion 1: PyGithub is completely removed from the codebase with no remaining imports or references
    Verification: Running rg -n "^\s*(from github( |\.)|import github$)" src tests prints nothing
  • Criterion 2: All GitHub API calls go through the session's REST transport and pagination methods
    Verification: Tests verify that every request carries the session's token and runs over httpx2.MockTransport
  • Criterion 3: The get_file_at method returns None only on a 404 and raises GitHubUnreadError on other failures
    Verification: Unit tests check that get_file_at returns None for 404, directory, large file, and non-UTF-8 bytes, and raises GitHubUnreadError for 500 after retries
  • Criterion 4: Pull request data is fetched using typed Pydantic models instead of PyGithub objects
    Verification: Tests verify that analyze pr and review PR fetch build the same title and changed-file list as before, including files from second page via pagination
  • Criterion 5: SSH key registration uses only one path through the session
    Verification: Tests check that register_key_on_github lists both endpoints and posts only missing keys, with no gh subprocess calls
  • Criterion 6: The GitHubClient class no longer contains dead methods like create_pr_review_comment and delete_user_ssh_key
    Verification: Running rg -n "_get_github_client|create_pr_review_comment|delete_user_ssh_key|get_pages_builds|_register_with_gh|_gh_add_key" src tests prints nothing

Key questions

  • Does the GitHubClient name stay?: Yes. It becomes the typed REST facade over the session and holds the real calls, so it is not a shim. (proposed) [sources: src/devops_cli/github/client.py:39-46]
  • Do the review's posting semantics change?: No. It still posts one issue comment. (proposed) [sources: src/devops_cli/github/client.py:170-189]
  • How are an org's repositories listed?: With GET /orgs/{org}/repos, as today. When the name is the signed-in user (session.login), they come from GET /user/repos?affiliation=owner, which matches today's user.get_repos() fallback. (proposed) [sources: src/devops_cli/github/client.py:83-120]

Fit

Needs splitting into 2 items:

  1. PR 1 (M): pull requests, files, merge base and repositories on the session
  2. PR 2 (S): SSH keys on the session, and PyGithub removed

Suspected block

None.

Dependencies

#983

Activity

  1. added
    type/refactor
    scope/github
    priority/p2-medium
    on Oct 1, 2026
  2. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Amendment from the 2026-10-08 client-library audit (at 05e9388):

    Found by the 2026-10-08 client-library audit.

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Owner decision on #983, 2026-10-08: the GitHub session's transport is gidgethub over the egress-checked httpx2 pool. gidgethub returns JSON, not typed models. So this item moves its callers onto the session and validates only the fields each one reads with pydantic models: response validation, not hand-written REST methods. PyGithub stays until #983's session lands. #1120 (declaring PyNaCl) still lands first.

  4. added this to the v0.2.37 milestone on Oct 17, 2026
  5. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  6. 4 remaining items

  7. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Amendment (2026-10-19): folded here by intake under the agent filing quota

    The cycle's agent filing allowance (#1153) was used, so devops roadmap intake filed nothing and named this item as the nearest. The candidate below finishes moving gh failure handling onto #983's classifier, and it sits beside this item's move of the remaining GitHub calls onto the session. It can land with this item or be filed on its own in a later cycle. #983's task file names this amendment as its follow-up. Candidate title: "refactor(github): route the remaining gh-text matchers through the gh classifier".

    Friction

    #983 (PR 3, #1682) gave gh's failures one classification, read from gh's exit status and stderr through one table (src/devops_cli/github/error_classifier.py, gh_failure_details and its _GhClassifier rows). Four callers still decide what a gh failure means by matching gh's text themselves:

    • each can drift from the table;
    • some match words that GitHub or a user can put in the text, so they misread a failure;
    • a fix to the table doesn't reach them.

    #983's task file names this as follow-up work.

    Evidence

    At release/v0.2.37 20a0191:

    • _is_branch_unprotected_error (src/devops_cli/github/branch_protection.py:128) treats any output containing "404" and "branch" or "protection" as an unprotected branch. A 404 for a missing repository or a token without access also matches, so reading protection for a repository the token can't see reports "no protection" instead of a failure.
    • create_repository_issue (src/devops_cli/github/issues.py:250) looks for "could not add to milestone" in stderr or stdout. It retries without the milestone only when that phrase appears, and otherwise reports the raw text.
    • _report_create_failure (src/devops_cli/commands/pr.py:865) looks for "must first push" to suggest pushing the branch.
    • extract_retry_after (src/devops_cli/github/rate_limiter.py:606) reads a Retry-After value with a regex over any message, beside the classifier's own parse_retry_after and retry_after_seconds.

    Remedy

    Acceptance criteria

    • Tests first, offline, at the gh process edge, with recorded gh stderr and exit codes:
      • a 404 for a repository the token can't read is a read failure, not "unprotected";
      • a milestone refusal retries without the milestone, and any other create failure doesn't;
      • the push hint appears only for the missing-base outcome;
      • Retry-After is read in one place.
    • rg -n '"404" in|must first push|could not add to milestone|retry\[- \]after' src/devops_cli prints only classifier table rows.
    • uv run devops ci passes.
  8. modified the milestones: v0.2.38, , v0.2.39 on Oct 20, 2026
  9. added
    status/in-progress
    on Oct 22, 2026
  10. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1924, merged into release/v0.2.39 as d67d528.

    Cause
    No module imports PyGithub since the pull request part of this item. Three leftovers stayed: its knowledge-base manual, its words in the documents and the RuntimeError base of SSHRegistrationError. A RuntimeError with no error code is outside the domain error taxonomy of AGENTS.md.

    Change
    SSHRegistrationError is now a GitHubOperationError. It takes the code GITHUB_OPERATION_FAILED and the exit status 1. devops_cli.github.ssh joins CONST_DOMAIN_EXCEPTION_MODULES, and docs/ERRORS.md lists the class. This PR deletes the PyGithub knowledge-base manual and its rows. python_packages.md now names gidgethub and the session. AGENTS.md, docs/TESTING.md, ADR 0006, a comment in constants.py and two task files no longer name PyGithub as a tool in use. The task file reads complete. changelog.d/891.md lists the PyGithub removal and the typed client. It states exactly when get_file_at and get_merge_base return nothing, and when a 422 counts as registered.

    Existing tool considered
    This PR builds no code. The transport is gidgethub (ADR 0006) and the earlier parts of this item already moved every call onto it. This part only deletes files and text and changes one base class.

    Tests
    test_a_registration_failure_is_a_github_operation_error_of_the_domain_taxonomy checks the class, the code and the exit status. The row of SSHRegistrationError in docs/ERRORS.md has an assertion in test_configuration_and_error_catalog_docs_describe_real_surface. Five tests count one manual fewer: test_list_kn…

    18 file(s) changed.

    How it was verified

    Check runs at 70b2d5e:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Service Image: skipping
    • Dependency Freshness: skipping
    • DevContainer Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-891-ssh-keys-through-the-gidgethub-session.md:

    • register_key_on_github sends only session requests: one POST to /user/keys and one to /user/ssh_signing_keys with the session's token, and no GET when GitHub accepts both (test_a_key_is_added_as_an_auth_key_and_a_signing_key_with_the_sessions_token). It runs no gh api or gh auth status; get_github_session() still runs gh auth token once to find the token.
    • A 422 counts as registered only when the session's listing holds the key or cannot be read, at both endpoints, and a key on a later page is found (test_a_422_counts_as_registered_only_when_the_session_lists_the_key, test_a_key_listed_on_a_later_page_counts_as_registered).
    • A 403 carrying scope headers is a registration error caused by GitHubScopeError with the refresh hint, at both endpoints (test_a_token_without_the_scope_is_a_registration_error_with_the_refresh_hint); a 5xx is a registration error caused by GitHubUnreadError and reads no listing (test_a_5xx_is_a_registration_error_with_the_sessions_error_as_its_cause); no login is a registration error that names gh auth login and sends nothing (test_registration_without_a_github_login_is_a_registration_error).
    • A 404 on POST /user/keys or POST /user/ssh_signing_keys is a registration error caused by GitHubScopeError (itself caused by the GitHubNotFoundError) that names the endpoint's scope and gh auth refresh -h github.com -s admin:public_key,write:ssh_signing_key, and registration stops there (test_a_404_at_a_key_endpoint_names_the_scopes_and_the_command_that_adds_them); a 404 on the listing a 422 sends the session to read still counts as a listing that can't be read (test_a_422_counts_as_registered_only_when_the_session_lists_the_key, listing-not-found).
    • devops ssh rotate removes the key it generated when GitHub refuses it (test_a_rotation_github_refuses_removes_the_new_key).
    • devops ssh rotate prints the scope command when GitHub answers 404, and removes the key it generated (test_a_rotation_github_answers_with_a_404_warns_with_the_scope_command_and_removes_the_new_key).
    • GitHubClient and GhCliClient have no attribute named get_user_ssh_keys, add_user_ssh_key, delete_user_ssh_key, create_pr_review_comment, get_issues, create_issue, edit_issue, get_pages_info or get_pages_builds, and devops_cli.models exports no SSHKeyInfo; devops_cli.github.issues has no edit_repository_issue, close_repository_issue or _build_issue_patch_payload.
    • tests/test_github_session.py has no test that mocks PyGithub, and test_the_client_is_built_only_by_the_session holds the one place that builds the client.
    • Pending a person: with a GitHub login whose token lacks admin:public_key, run uv run devops ssh register --key-file <private key path> and expect the failure to name admin:public_key and the gh auth refresh -h github.com -s admin:public_key,write:ssh_signing_key command, because the 404 GitHub answers a token without the scope is recorded from gh's output, not from a live call.
    • Pending a person: with a GitHub login, run uv run devops ssh register --key-file <private key path of a key already on the account> and expect Registered <title> on GitHub (auth + signing)., because GitHub answers 422 for each key it holds and the listing confirms it.
    • get_pull returns the title and both commits of the recorded pull request. The head has no repository, because the fork is deleted. The test asserts the token of the session on every request (test_a_pull_request_is_read_with_its_title_and_both_commits). An answer that is no pull request raises GitHubUnreadError (test_a_pull_request_that_lacks_a_title_is_unread).
    • get_pull_files reads both pages of the recorded listing (test_the_files_of_a_pull_request_come_from_every_page). devops ai analyze pr and the pull request fetch of the review give the recorded title and both changed files (test_analyze_pr_lists_the_title_and_the_files_of_every_page, test_a_pr_review_of_the_recorded_pull_request_reads_both_pages_of_files). The review reads the head files from the base repository when the fork is deleted.
    • get_file_at returns None for a 404, a directory, a link, a file over 1 MB and bytes that are not UTF-8 (test_a_file_that_is_absent_binary_or_too_large_is_none). It raises the error of the session for a 500, a refused token and a body that is not a file (test_a_file_that_could_not_be_read_raises_instead_of_reading_as_absent).
    • A request encodes the path, the ref, the repository name and the organization name (test_a_path_and_a_ref_are_encoded_in_the_request, test_a_repository_name_is_encoded_in_the_request, test_an_organization_name_is_encoded_in_the_request).
    • get_merge_base returns the merge base of the recorded comparison and None for a 404 only. It raises for a 5xx and for a comparison without a merge base (test_the_merge_base_is_read_from_the_compare_endpoint, test_a_comparison_github_does_not_find_has_no_merge_base, test_a_comparison_that_could_not_be_read_raises).
    • get_org_repos lists /orgs/{org}/repos. It falls back to /user/repos?affiliation=owner only for a 404 and the login of the session. It leaves out forks, private repositories and archived repositories as asked (test_the_account_of_the_session_lists_the_repositories_it_owns_when_it_is_no_organization, test_another_account_that_is_no_organization_raises_the_not_found_error).
    • devops repos clone-org reports a missing organization as a GitHub error, without a traceback, and creates no directory (test_repos_clone_org_names_the_missing_organization).
    • devops review pr reports a GitHub failure as its error, without a traceback. This holds for the pull request (test_a_pr_review_ends_with_the_github_error_when_the_pull_request_cannot_be_read). It holds for a base file of a symbol delta and for .devops/review.toml at the merge base (test_a_pr_review_ends_with_the_github_error_when_a_file_of_the_base_cannot_be_read).
    • devops ai analyze pr reports a GitHub failure on the pull request or on its files as its error, without a traceback (test_analyze_pr_ends_with_the_github_error_when_the_pull_request_cannot_be_read).
    • The review reads the merge base and the base files from the base repository that the pull request names (test_a_pr_review_reads_the_merge_base_from_the_base_repository_the_pull_request_names).
    • devops review pr --post sends exactly one POST /repos/{repo}/issues/{n}/comments, and a dry run sends none (test_devops_review_pr_post_publishes_comment, test_devops_review_pr_post_dry_run_skips_comment, test_devops_review_pr_post_empty_diff_makes_zero_model_calls).
    • The comment lists the files that the pull request leaves in place (test_devops_review_pr_post_names_the_files_the_pull_request_leaves_in_place). The command exits 1 and posts nothing when GitHub fails the read of the files (test_devops_review_pr_post_stops_when_the_files_of_the_pull_request_cannot_be_read).
    • devops gh labels sync --dry-run lists the labels with GhCliClient and creates none (test_cli_labels_sync). GitHubClient has no label method, and _get_github_client is gone.
    • rg --glob '*.py' -n "^\s*(from github( |\.)|import github$)" src tests prints nothing. uv run deptry src passes without PyGithub. The swallowed-failures ceilings of github/client.py and commands/review.py are gone. The ceiling of commands/gh.py is 1, and the ceiling of ai/review/path_classes.py is 2.
    • Pending a person: from the repository root, run uv run devops ai analyze pr <an open PR number> --no-enhanced and expect the changed files of that pull request. No test reads live GitHub.
    • SSHRegistrationError is a GitHubOperationError and a DevOpsCLIError, with the code GITHUB_OPERATION_FAILED and the exit status 1 (test_a_registration_failure_is_a_github_operation_error_of_the_domain_taxonomy). docs/ERRORS.md lists it (test_configuration_and_error_catalog_docs_describe_real_surface).
    • These commands print nothing: rg --glob '*.py' -n "^\s*(from github( |\.)|import github$)" src tests, rg -n -i pygithub pyproject.toml uv.lock src AGENTS.md and rg -n "_get_github_client|create_pr_review_comment|delete_user_ssh_key|_register_with_gh|_gh_add_key" src tests. The last one leaves out get_pages_builds, because the module function of that name in github/pages.py is in use.
    • The knowledge base holds 79 manuals. devops_cli has 39 of them, and 22 of those are library manuals. it_domains has 40 (test_list_knowledge_base_articles_all, test_list_knowledge_base_articles_by_category, test_list_knowledge_base_articles_by_division, test_get_knowledge_base_stats, test_every_target_manual_has_valid_front_matter).
    • Pending a person: run uv run devops review pr <an open PR number> --pre-analysis-only and expect a review without an error. get_pull and get_pr_diff read one URL with two media types, and gidgethub keeps its cache by URL only.
  11. added a commit that references this issue on Oct 23, 2026
  12. removed
    status/in-progress
    on Oct 30, 2026
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

    priority/p2-mediumscope/githubtype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions