Skip to content

fix(review): read a merged pull request from its merged state #5397

Done

Description

@dan-petty

Problem Description

The change of #5346 makes devops review pr and devops ai analyze pr compare <base.ref>...<head>. For a pull request that was merged with a merge commit or a fast-forward, the head is an ancestor of the tip of the base branch. Then the compare lists no files, and the review is empty. This repository squash-merges, so the gap shows only in repositories that allow merge commits.

This is item 2 of #5388. It is split from #5388 because the compare read of the review is only in the open change of #5346. On main, devops review pr reads the pulls diff and the payload base.sha (src/devops_cli/commands/review.py, _run_pr_review_workflow), and that diff holds the files of a merged pull request. So the gap is not on main yet, and a fix on main now stacks on an open pull request.

Reproduction Steps

  1. Merge the change of fix(review): Review a pull request at the merge base of its base branch #5346.
  2. Run devops review pr <number> for a pull request that a merge commit merged, in a repository that allows merge commits.

Live on 2026-11-13: devops gh api 'repos/dan-petty/devops-cli/compare/main...f299667c9?per_page=1' gives status: behind and 0 files, because f299667c9 is a commit of main.

Expected vs Actual Behavior

Expected: for a merged pull request, the review and the analysis read the changes from the merged state: the pulls/{n}/files list or the merge commit. The merged state does not move. For an open pull request, they keep the compare of the base branch and the head commit.

Actual: after the change of #5346, the review and the analysis of a pull request that a merge commit merged read no files.

Acceptance criteria

  • A test with a pull request that a merge commit merged shows that devops review pr reads its files.
  • A test with the same pull request shows that devops ai analyze pr reads its files.

Blocked by

The open change of #5346. Start this item after that change merges.

Existing tool considered

The GitHub pulls and compare APIs, through the GitHub session. No new tool. Cost: about 80,000 tokens, 1 hour elapsed.

Source: #5388

Alternatives check of 2026-11-28: in-use.
The repository already uses this tool.
Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-11-20, maintained.
Reason: Searches found no external tool that decides between the compare and the merged state; the GitHub client the project already uses covers only the transport, while the branch on pull.merged and the tests stay in the repository.

Covers:

  • Paginated read of the pulls files list through the session
  • Pulls diff in the diff media type
  • One REST transport behind GitHubSession, no new dependency

Lacks:

  • No rule to choose compare versus fixed merged state
  • No repository tests or GitHub fakes
  • No guard against the stale file list of a squash merge

Proposed design

Problem statement

After the change of #5346, devops review pr and devops ai analyze pr read a pull request from the compare of <base.ref>...<head>. When a merge commit or a fast-forward merged the pull request, the head is an ancestor of the base tip, so the compare lists no files and the review is empty. The fix reads such a merged pull request from its fixed merged state, the pulls/{number}/files list and the pulls diff, at the payload's base.sha, and keeps the compare for an open or squash-merged pull request.

Acceptance criteria

Requirement: Merged pull request files list

The pull request content preparation SHALL read the changed files from pulls/{number}/files when the pull request is merged and the compare of its base branch and head lists no files.

Scenario: A merged payload with an empty compare reads the files list

  • WHEN A test gives _prepare_pr_content a merged pull request payload whose compare lists no files, and a GitHub fake that records each request.
  • THEN The test asserts a recorded request is GET /repos/<repo>/pulls/<number>/files?per_page=100 and the returned base revision holds each file of the files answer.

Requirement: Merged pull request diff

The pull request content preparation SHALL read the review diff from the pulls endpoint in the diff media type when it reads the files of a merged pull request from pulls/{number}/files.

Scenario: A merged payload reads the pulls diff

  • WHEN A test gives _prepare_pr_content a merged pull request payload whose compare lists no files and whose pulls endpoint answers a two-file diff.
  • THEN The test asserts the pages hold the two diff blocks and a recorded request is GET /repos/<repo>/pulls/<number> with the diff media type.

Requirement: Merged base text

The pull request content preparation SHALL read the base text and the base conventions at the payload's base.sha when it reads the files of a merged pull request from pulls/{number}/files.

Scenario: A merged payload reads the base at base.sha

  • WHEN A test gives _prepare_pr_content a merged pull request payload whose compare lists no files and a base.sha that differs from the head.
  • THEN The test asserts the returned base revision names base.sha and a recorded contents request holds ref=<base.sha>.

Requirement: Squash-merged pull request keeps the compare

The pull request content preparation SHALL read the files and the diff from the compare when the compare of the base branch and the head lists files, also for a merged pull request.

Scenario: A squash-merged payload keeps the compare

  • WHEN A test gives a merged pull request payload whose compare lists two files and a GitHub fake that records each request.
  • THEN The test asserts no recorded request holds /pulls/<number>/files and the pages hold the compare diff.

Requirement: Open pull request keeps the compare

The pull request content preparation SHALL read the changed files from the compare of the base ref and the head SHA when the pull request is not merged.

Scenario: Open payload reads the compare

  • WHEN A test gives a pull request payload with merged false and a GitHub fake that records each request.
  • THEN The test asserts a recorded request holds /compare/<base-ref>...<head-sha>?per_page=1 and no request holds /pulls/<number>/files.

Requirement: Analyze reads the merged state

devops ai analyze pr SHALL read the changed files from pulls/{number}/files when the pull request is merged and the compare of its base branch and head lists no files.

Scenario: Merged analysis reads the files list

  • WHEN A test runs devops ai analyze pr for a merged pull request whose compare lists no files and a GitHub fake that records each request.
  • THEN The test asserts a recorded request is GET /repos/<repo>/pulls/<number>/files?per_page=100 and the analysis record holds each file of the files answer.

Requirement: Review of a merged pull request has pages

devops review pr SHALL review the changed files of a merged pull request whose compare lists no files, and never an empty list.

Scenario: Merged review gets its two files

  • WHEN A test runs devops review pr for a merged pull request whose compare lists no files and whose files answer and diff hold two files.
  • THEN The test asserts the review receives two pages and each page names one of the two files.

Existing Tool Considered

The alternatives check of 2026-11-17 in the issue body found no external tool that covers the choice (Tool: none found), and the issue records No new tool. The open, maintained tool that covers the transport is the one ADR 0006 already chooses: gidgethub 6.0.0 (Apache-2.0), the GitHub REST client behind GitHubSession (docs/adr/0006-github-session-requests-go-through-gidgethub.md:11). It covers the need: GitHubClient.get_pull_files pages GET /repos/{owner}/{repo}/pulls/{number}/files?per_page=100 through GitHubSession.paginate, and GitHubClient.get_pr_diff reads the pulls diff in the diff media type, so the change adds no dependency. What it lacks: it is a transport, not a policy, so it does not decide between the compare of an open or squash-merged pull request and the fixed merged state of a merge-committed or fast-forwarded one, and it supplies no repository tests; _prepare_pr_content and devops ai analyze pr must branch on pull.merged and the empty compare, and the tests must prove both reads. The issue records the cost of the work at about 80,000 tokens and 1 hour elapsed.

Key questions

  • Does this item still wait on the change of fix(review): Review a pull request at the merge base of its base branch #5346?: No. The refined src/devops_cli/ai/review/runner.py compares pull.base.ref and pull.head.sha at line 976, and the fix(review): Review a pull request at the merge base of its base branch #5346 change is archived at openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/, so the compare read is in the refined commit and the item starts now. [sources: src/devops_cli/ai/review/runner.py:976, openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/tasks.md:18]
  • Which source gives the changed files and the diff of a merge-committed or fast-forwarded pull request?: Read the files from GET /repos/{owner}/{repo}/pulls/{number}/files and the diff from the pulls endpoint in the diff media type, when the pull request is merged and the compare of the base branch and the head lists no files. The pulls files list and the pulls diff are the pull request's own fixed state, and get_pr_diff already reads that diff. (best practice) [sources: src/devops_cli/github/client.py:648, src/devops_cli/github/client.py:890, tests/support/fakes/github.py:172, openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/proposal.md:37]
    • Chosen: pulls files list and pulls diff. Both are the pull request's own fixed state, GitHub keeps them after a merge commit or a fast-forward, and the GitHub fake already answers both routes.
    • Rejected: diff of the merge commit against its first parent. A fast-forward leaves merge_commit_sha equal to the head, so the diff holds only the last commit, and a rebase merge leaves it the last rebased commit.
    • Rejected: compare base...head. The head is an ancestor of the base tip, so the compare gives status: behind and 0 files, as the live probe of 2026-11-13 in the issue shows.
  • Does the fix read the merged state for every merged pull request?: No. It reads the merged state only when the compare of the base branch and the head lists no files, which is the merge-commit and fast-forward case. A squash-merged pull request's head is not an ancestor of the base tip, so its compare still lists the files; the pulls files endpoint and the pulls diff kept 184 files against the 11 of the squash commit for pull request 2509, so routing every merged pull request to them would read the stale list. (best practice) [sources: openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/proposal.md:37, openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/design.md:17, openspec/changes/archive/2026-11-13-2530-readiness-compare-from-base-branch/proposal.md:44, src/devops_cli/ai/review/runner.py:976]
    • Chosen: compare first, merged state only when it lists no files. It keeps the correct compare for a squash merge and reaches the fixed merged state only in the merge-commit and fast-forward case the issue names.
    • Rejected: every merged pull request reads the pulls files list. Pull request 2509 was squash-merged and the pulls files list held 184 files against 11 in its squash commit, so the review would read the stale list.
  • Which base commit does the review of a merged pull request read the base text and the base worktree at?: The payload's base.sha. The pulls files list and the pulls diff are computed from it: for pull request 2509, the compare from base.sha gave the same 184 files as the pulls files endpoint and the pulls diff, and the review read the conventions there before fix(review): Review a pull request at the merge base of its base branch #5346. It is an ancestor of the head, so the fetch of refs/pull/{number}/head brings it to the local repository. (best practice) [sources: src/devops_cli/github/client.py:74, openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/design.md:17, openspec/changes/archive/2026-11-13-5346-review-pr-merge-base/proposal.md:42, openspec/changes/archive/2026-11-13-2530-readiness-compare-from-base-branch/proposal.md:44]
    • Chosen: payload base.sha. The pulls files list and the pulls diff are computed from it, and the fetch of the head brings it to the local repository.
    • Rejected: merge commit's first parent. It is the base tip at the merge, not the base the pulls endpoints used, so base changes since the merge base would read as removed.
    • Rejected: the head SHA. It reads every file as added and gives the base worktree no diff.
  • How does the read get each file of a large pull request?: Re-add GitHubClient.get_pull_files, which reads pulls/{number}/files?per_page=100 through GitHubSession.paginate; the session follows each page's Link: rel="next" until a page has no next link, so a large pull request is read to the end. (best practice) [sources: src/devops_cli/github/session.py:110, src/devops_cli/config/defaults.py:835, CHANGELOG.md:5245]
    • Chosen: paginate through the session. It follows the next link, the page cap and the error classes that the session already gives, and it is how the pulls files read worked before fix(review): Review a pull request at the merge base of its base branch #5346.
    • Rejected: one request with no page parameter. GitHub lists at most 100 files a page, so a larger pull request loses files.
    • Rejected: loop over page numbers by hand. It duplicates the Link following, page cap and error mapping that GitHubSession.paginate already provides.
  • Where does devops ai analyze pr prepare the content of a pull request?: In src/devops_cli/commands/analyze.py: the pr command reads session.client.get_pull at line 540, then get_compare_files at line 544, and uses compared.files at line 554. The fix branches there on the merged state, or routes both commands through one shared helper. [sources: src/devops_cli/commands/analyze.py:540, src/devops_cli/commands/analyze.py:544, src/devops_cli/commands/analyze.py:554]
  • Does the pr-squash-diff spec change?: Yes. The requirement that the review MUST NOT read the pulls files endpoint or the pulls diff, and the analysis MUST NOT read the pulls files endpoint, now holds for a pull request whose compare lists files; a merged pull request whose compare lists no files reads the pulls files list and the pulls diff at the payload's base.sha. The change carries a spec delta for pr-squash-diff. (best practice) [sources: openspec/specs/pr-squash-diff/spec.md:9, openspec/specs/pr-squash-diff/spec.md:31]
    • Chosen: scope the MUST NOT to the compare read. The spec states the behavior the commands now have, and the merged state gets its own requirement and scenarios.
    • Rejected: keep the spec as it is. The commands would read the pulls endpoints while the spec forbids it, so the spec would be wrong.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/bug
    scope/review
    status/new
    value/medium
    effort/low
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches found no tool or library that covers the need: the only candidates are the GitHub REST compare and pulls APIs, which the project already calls through its own GitHub session, and the issue itself records "No new tool". The work is a code change in devops review pr and devops ai analyze pr to read the pulls/{n}/files list or the merge commit for a merged pull request, plus tests in this repository, so no external tool covers it.

    Tool: none found

    Lacks:

    • No external tool or library decides between the compare of an open pull request and the fixed merged state of a merged one; that choice belongs in the project's own review and analysis code (src/devops_cli/commands/review.py).
    • The GitHub REST API alone gives no automatic fallback: the project must branch on the pull request's merged state and read pulls/{n}/files or the merge commit itself.
    • The acceptance criteria need repository tests for devops review pr and devops ai analyze pr against a pull request merged with a merge commit, which no external tool provides.

    Searches run:

    • GitHub compare API returns no files for merged pull request, results: 5
    • gidgethub pull request files merged list API, results: 5
    • gh pr diff merged pull request merge commit files, results: 5
    • "pulls" "files" REST API GitHub list files of a pull request merged, results: 5
    • PyGithub PullRequest get_files example, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  7. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 2620fae (see proposed design in issue body).

  8. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: none, no tool. A person decides what the new result means for the item.

    Searches (7)

    Tools considered:

    Searches run:

    • python library read merged pull request changed files and diff GitHub API, results: 5
    • GitHub API compare returns no files for merged pull request, pulls files endpoint, results: 5
    • gidgethub GitHubClient pull request files pagination diff media type, results: 5
    • PyGithub get_pull files merged pull request diff, results: 5
    • GitHub REST API "list pull request files" endpoint documentation, results: 5
    • tool that resolves merged pull request files from GitHub for code review, results: 5
    • gidgethub GitHub API library python, results: 5

    Sources:

  9. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  10. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  11. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:17 UTC

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

    effort/lowpriority/p2-mediumscope/reviewsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions