Skip to content

refactor(github): roadmap store that reads and writes items, releases and board fields behind one interface #768

Closed

Description

@dan-petty

Context & Rationale

The roadmap jobs (#739-#744) and the service (#752) all read and write Items, Releases and board fields. Today each caller reads GitHub its own way. Failed reads often look empty, and no job can be tested without patching run_gh. Checked at ef21785:

Releases (milestones) are read and written five ways.

  • GitHubClient over PyGithub (github/client.py:222-309).
  • GhCliClient over gh (client.py:470-538). _closed_milestone_titles (github/release_epics.py:282-289) also reads closed milestones through it, and returns an empty set on failure.
  • _get_repo_milestones and _close_milestone_gh_cli in commands/gh.py:167-199 and :404-423.
  • The wrappers in github/milestones.py:167-366. They take client: Any, probe it with getattr and retry on TypeError. Both real clients take repo first, so the retries only serve test doubles such as SingleArgClient (tests/test_github_milestones.py:107-117).
  • _resolve_milestone_number in github/issues.py:380-412, used by gh issues create and edit. It raises on failure.
  • Lookup by version is written five times (commands/gh.py:408, client.py:304, milestones.py:296, :359, issues.py:373).

Editing a release closes it. edit_repository_milestone passes only the fields it is given (milestones.py:321-339), and GitHubClient.edit_milestone defaults state="closed" (client.py:276). So devops gh milestones edit v0.2.25 --description x closes v0.2.25 whenever a token resolves, and _resolve_github_token (commands/gh.py:115-130) falls back to gh auth token. Reproduced with a stubbed PyGithub repository: the call made was milestone.edit(state='closed', title='v0.2.25', description='new text').

Failed reads look empty, and failed writes look done.

  • GhCliClient.get_milestones and _get_repo_milestones return [] on any failure (client.py:493, commands/gh.py:199). devops gh milestones list then prints "No milestones found".
  • GhCliClient's milestone writes drop the exit status (client.py:517, :538), so edit reports success when GitHub refused.
  • parse_paginated_json returns whatever it parsed before the first malformed document, or [], and never raises (client.py:394-416).

Items in a release are read several ways, with different limits.

run_gh pagination has four traps. It drops --paginate and pages with ?page=N (github/rate_limiter.py:1499-1669).

  • A GraphQL query returns only its first page. A stubbed run_gh(["api", "graphql", "--paginate", ...]) made one call, to graphql?page=1, and ignored hasNextPage.
  • It assumes 100 rows a page unless the endpoint names per_page (:1499-1507), and stops at the first shorter page (:1575). GitHub's default page is 30 rows. So run_gh(["api", "--paginate", "repos/o/r/milestones?state=all"]) returns 30 rows and stops. This repository has 44 milestones. Reproduced with a stubbed subprocess: 30 of 75 rows, in one call.
  • It takes the first argument after api that doesn't start with - as the endpoint (:1518-1523). A flag value placed before the endpoint gets the page number instead: -X GET became GET?page=1.
  • REST paging stops silently after DEFAULT_GH_MAX_PAGINATED_PAGES, which is 100 pages (config/defaults.py:717).

There is no change history and no record of what a job set.

Tests. 210 places patch run_gh by module path, across 16 modules (rg -o "devops_cli\.[a-z_.]+\.run_gh" tests). No fake GitHub adapter exists.

Scope & Deliverables

  • Deliverable: one roadmap store, RoadmapStore, that every roadmap job reads and writes the roadmap through. It has a GitHub adapter and an in-memory adapter.
    • Reads:
      • Releases: all of them sorted by version, and one by version (0.2.25 and v0.2.25 find the same one).
      • Items: one by number; the Items in a Release, open and closed; the Backlog (open Items in no Release).
      • Candidates: open issues of the repository that are not on the board.
      • Changes since a given time, each with its actor and time: an Item joining or leaving a Release, being labeled or unlabeled, closed or reopened.
    • Writes:
      • Releases: create, edit (title, description, due date, state) and close, by version.
      • Items: add an issue to the board; set or clear its Release; set its Status, Priority, Value or Effort.
      • Every Item write also records the value it set: the job record (ADR 0002). An Item exposes its job record next to its fields, so a job can see whether a person has changed a field since.
    • Guarantees:
      • Reads page through every result.
      • Items are issues of this repository. Pull requests, draft issues and other repositories' items are never Items, and pull requests are never Candidates.
      • A read that can't complete raises. It never returns an empty or partial result.
      • No read is cached.
    • Adapters: GitHub, over an injected gh runner that defaults to run_gh; and in-memory, with no I/O, for tests. One contract suite runs against the in-memory adapter. The GitHub adapter has its own stub-runner tests for the same promises.
    • First callers (the Releases slice):
      • devops gh milestones list, status, close, edit and sync, and the milestone close in devops release (commands/release.py:1605-1631), move onto the store.
      • _closed_milestone_titles (github/release_epics.py:282-289) moves onto releases(), and a failed read now raises instead of returning an empty set. feat(github): github-sourced roadmap, migration and generated roadmap view (devops roadmap migrate, render) #739 later deletes the module.
      • Deleted, without shims: the client: Any wrappers in github/milestones.py; _get_repo_milestones and _close_milestone_gh_cli in commands/gh.py; the milestone methods of GitHubClient and GhCliClient; the wrappers' re-exports in github/__init__.py; and the test-only REST board read (projects.py:758-800, with _extract_urls_from_project_items).
      • Tests that patch run_gh, GitHubClient or _get_github_client to drive these paths are rewritten against the in-memory store, not kept alongside.
  • Acceptance criteria:
    • Interface. RoadmapStore is a runtime-checkable Protocol, and InMemoryRoadmapStore and GitHubRoadmapStore satisfy it. Verified by mypy --strict in the gate and by an isinstance case in the contract suite.
    • Contract suite (tests/test_roadmap_store_contract.py, in the gate, in-memory adapter). Each case is its own test:
      • release("0.2.25") and release("v0.2.25") return the same Release. An unknown version returns None.
      • Creating a version that already exists raises. releases() puts v0.2.9 before v0.2.10.
      • Editing a Release's description leaves its state unchanged.
      • items(release="v0.2.25") returns the open and closed Items in it and nothing else. backlog() returns open Items with no Release. candidates() returns open issues that are not on the board.
      • Setting a field to a value that isn't one of its board options raises and changes nothing.
      • After the store sets Priority to P2-Medium, the Item's Priority and its job record both read P2-Medium. After a person (as_actor("alice")) sets it to P1-High, the two differ. An Item the store never wrote has an empty job record.
      • After as_actor("alice") places an Item in a Release, changes_since(t0) holds exactly one joined-Release change for it, by alice.
    • GitHub adapter (tests/test_roadmap_github_store.py, in the gate, a stub runner returning recorded gh output). Each case is its own test:
      • Each write sends the expected argv. An edit that names no state sends no state.
      • Every REST listing puts its endpoint directly after api --paginate, and the endpoint carries per_page=100.
      • From a recorded listing of 44 milestones, release("0.2.25") and release("v0.2.25") return the same milestone number, and releases() puts v0.2.9 before v0.2.10.
      • A board listing that holds an issue, a pull request, a draft issue and another repository's issue yields one Item.
      • items(release="v0.2.25") returns a closed issue that is on the board, with its state and Release taken from the REST issue listing.
      • candidates() drops a pull request in the REST issue listing and an issue that is already on the board.
      • Setting a value that isn't one of the field's board options raises, and the runner records no write.
      • Setting Priority sends the field edit, then the Job record edit, whose JSON holds the new value. When the board has no Job record field, the write raises before any call that changes GitHub.
      • A non-zero exit, malformed JSON, and a board listing with fewer items than its totalCount each raise GitHubOperationError.
      • Every read passes use_cache=False.
      • changes_since pages issue events newest first and stops at the first event older than its argument. It keeps milestoned, demilestoned, labeled, unlabeled, closed and reopened events on issues, and drops pull request events and every other event type.
    • rg -n "^\s*(import github|from github )|GitHubGraphQLClient|httpx" src/devops_cli/roadmap prints nothing.
    • rg -n "except TypeError|client: Any" src/devops_cli/github/milestones.py prints nothing.
    • rg -n "_resolve_milestone_target_number|_close_milestone_gh_cli|_get_repo_milestones|_fetch_project_item_urls|_extract_urls_from_project_items|SingleArgClient" src tests prints nothing, and neither does rg -n "def (get|create|edit|close)_milestones?\(" src/devops_cli/github/client.py.
    • No test in tests/test_github_milestones.py, tests/test_gh_issues_milestones.py, tests/test_gh_cmd.py or tests/test_github_client.py patches run_gh, GitHubClient or _get_github_client to drive a milestone command. Verified by rg on those files and by review.
    • devops gh milestones edit v0.2.25 --description x leaves v0.2.25 open. Verified by a CLI test on the in-memory store.
    • When GitHub can't be read, devops gh milestones list exits 1 and names the failed read, instead of printing "No milestones found". Verified by a CLI test with a stub runner that exits 1.
    • Gate cost.
      • The two new test files run in under 1 s in total: uv run pytest -n0 --durations=0 tests/test_roadmap_store_contract.py tests/test_roadmap_github_store.py.
      • The rewritten milestone tests take no longer than the ones they replace, measured with --durations=0 on the same files before and after.
      • The task file records both measurements.
      • uv run devops ci passes within its 5-minute budget.
    • Checks a person runs against live GitHub. These are not tests.
      • Read-only, against this repository. The first command prints two numbers. They must equal the outputs of the second and third commands, in that order:
        uv run python -c "from devops_cli.roadmap.github_store import GitHubRoadmapStore as S; s = S('dan-petty/devops-cli', board_owner='dan-petty', board_number=2); print(len(s.items(release='v0.2.25')), len(s.candidates()))"
        gh project item-list 2 --owner dan-petty --format json --limit 2000 --jq '[.items[] | select(.content.type == "Issue" and .content.repository == "dan-petty/devops-cli" and .milestone.title == "v0.2.25")] | length'
        comm -23 <(gh issue list -R dan-petty/devops-cli --state open --limit 2000 --json number --jq '.[].number' | sort) <(gh project item-list 2 --owner dan-petty --format json --limit 2000 --jq '.items[] | select(.content.type == "Issue" and .content.repository == "dan-petty/devops-cli") | .content.number' | sort) | wc -l
        
      • Writes, on a scratch repository the person owns (never this one). The first read prints ["open","after"], and the second prints "closed":
        gh api repos/OWNER/SCRATCH/milestones -f title=v9.9.9 -f description=before
        uv run devops gh milestones edit v9.9.9 --description after -R OWNER/SCRATCH
        gh api 'repos/OWNER/SCRATCH/milestones?state=all' --jq '.[] | select(.title == "v9.9.9") | [.state, .description]'
        uv run devops gh milestones close v9.9.9 -R OWNER/SCRATCH
        gh api 'repos/OWNER/SCRATCH/milestones?state=all' --jq '.[] | select(.title == "v9.9.9") | .state'
        
  • Key questions:
  • Constraint:

Strategic Alignment

Activity

  1. added this to the v0.2.25 milestone on Oct 1, 2026
  2. added
    type/refactor
    scope/github
    priority/p1-high
    on Oct 1, 2026
  3. added a commit that references this issue on Oct 1, 2026
  4. self-assigned this
    on Oct 2, 2026
  5. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Closed by #919, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  6. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority/p1-highscope/githubtype/refactor

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions