Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_CYCLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The module `devops_cli.release.merge_candidate` reads the open pull requests tha
| Origin | The release App opened it, from a `release-please--branches--main` branch of this repository into `main`. |
| Labels | It has `autorelease: pending` and does not have `hold-release`. |
| Title | The title is `chore(main): release <version>`. |
| Files | It changes only `.release-please-manifest.json`, `CHANGELOG.md`, `pyproject.toml` and `uv.lock`, and it adds, removes and renames none of them. |
| Files | It changes only `.release-please-manifest.json`, `CHANGELOG.md`, `pyproject.toml` and `uv.lock`, and it adds, removes and renames none of them. The guard reads the files from the compare of `main` and the head commit, which is the diff that the squash merge applies. It does not read the file list of the pull request, because that list can hold files of `main` after the merge base moved. |
| Checks | Every check that the ruleset of `main` requires passed on its head commit. No other check failed there, because the publish jobs of the release run the same scans. |
| `main` | No required check failed on the head of `main`. |
| Mergeable | GitHub reports it as mergeable. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-13
skip_specs: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Design

## Decisions

- **Compare from the base branch name, not from the payload `base.sha`.**: GitHub compares from the merge base of the two commits, so the compare of the base branch and the head commit is the diff that the squash merge applies. The compare from a stale `base.sha` gives the same stale list as the pulls endpoint (#2530: `compare/0137f231...344adba9` gave 184 files, `compare/main...344adba9` gave 11).
- **Name the head by the head commit sha.**: The row reads the checks of that commit, and the pick merges that commit with `--match-head-commit`, so the diff, the checks and the merge are of one commit.
- **Add `GitHubClient.get_compare_diff` beside `get_compare_files`, and give it and `get_pr_diff` one private read of a diff.**: Jev reads a unified diff, and the compare endpoint serves the diff media type that `get_pr_diff` reads. The open change of #5346 adds `get_compare_diff` and `_read_diff` with the same names, signatures, answers and place in the file. The change that merges second gets one conflict in `client.py`, and its resolution keeps one copy of each method. Another place in the file would merge with no conflict and define the method two times.
- **Give `_jev_holds` the `PullStatus` of the draft.**: The status that `_settle` read holds the head commit and `base_ref`, so the check sends no new read of the pull request.
- **Add `client` to the protocol `RestSession` of the pick.**: `GitHubSession.client` gives the typed client of the same session, so the compare request is paced and charged as the other reads of the pick. The tests run the pick on the real session over the GitHub fake.
- **Compare from `ReleasePull.base_ref` and not from the constant `main`.**: A pull request into another base is refused by the branch guard, and the read stays the diff that a merge into its own base applies.
- **Do not add a refusal for a compare answer at GitHub's limit of 300 files.**: The release files are four paths, so a list of 300 files holds at least 296 other paths, and the file guard refuses each.
- **Keep `GitHubClient.get_pr_diff`.**: `devops review pr` reads it on `main` (`src/devops_cli/ai/review/runner.py:952`).

## Rejected alternatives

- **Compare from the payload `base.sha`.**: GitHub does not move `base.sha` when a merge commit moves the merge base, so the compare from it holds the files of the merged base (#2530).
- **Keep the pulls endpoints because GitHub moved `base.sha` in the 16 probed pull requests.**: The probe holds only force-pushes. A merge of the base branch into a plan branch, from `devops pr update-branch` or the update button of GitHub, is the case of #2530, where `base.sha` stayed stale.
- **Build the diff for Jev from the `patch` fields of the compare files answer.**: That writes a diff format by hand, and GitHub serves the unified diff of the same compare in one request.
- **Read the merge base with `get_compare_files` first and then the diff from the merge base.**: That is two requests for one answer. The three-dot compare of the base branch already starts at the merge base.
- **Build item 2 of the issue in this change.**: The compare read of `devops review pr` is only in the open change of #5346. On `main`, the review reads the pulls diff, which holds the files of a merged pull request. A test of item 2 on `main` would pass now and fail when that change merges, so the item moves to #5397.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Proposal: #5388

## Why

The issue #5388 reports two readers of pull request changes that do not use the merge base. The Jev completeness check of the row `stage_ready` reads the diff of the pulls endpoint (`src/devops_cli/roadmap/stage/stage_ready.py`, `_jev_holds`). The scheduled release merge reads the pulls files list (`src/devops_cli/release/merge_candidate.py`, `_changed_files`). GitHub can keep a stale `base.sha` after the merge base of a pull request moved. Then these two reads hold files of other changes: Jev judges a plan with files that the plan does not change, and the release guard refuses a release pull request for a file of `main`. The fix of #2530 moved the readiness reads to the compare of the base branch and the head commit for the same cause.

## What Changes

- `GitHubClient.get_compare_diff(repo, base, head)` reads the unified diff of `head` since its merge base with `base` from the compare endpoint, in the diff media type. It and `get_pr_diff` share one private read of a diff.
- The Jev completeness check of the row `stage_ready` reads the diff of the draft with `get_compare_diff` from the base branch of the draft (`PullStatus.base_ref`) and its head commit. It reads no diff of the pulls endpoint.
- The pick of the scheduled release merge reads the files of a release pull request with `GitHubClient.get_compare_files` from the base branch of the pull request and its head commit. It sends no pulls files request. The protocol `RestSession` of the pick names the `client` of the session.
- `RELEASE_CYCLE.md` says where the file guard reads the files.
- Item 2 of the issue, the review of a pull request that a merge commit merged, is not in this change. It moves to #5397, because the compare read of `devops review pr` is only in the open change of #5346.
- The change alters what the row and the pick read from GitHub, which a consumer observes, so it carries two spec deltas.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `roadmap-stage/ready`: the new requirement Jev reads the diff of a stage draft from the compare of its base branch. The requirement The Service asks Jev about the criteria of a green stage draft does not change.
- `release-scheduled-merge`: the new requirement The pick reads the files from the compare of the base branch. The requirement The pull request must change only the files that release-please writes does not change.

## Impact

- Code: `src/devops_cli/github/client.py`, `src/devops_cli/roadmap/stage/stage_ready.py`, `src/devops_cli/release/merge_candidate.py`
- Tests: `tests/roadmap/stage/test_roadmap_stage_ready_jev.py`, `tests/release/test_release_merge_pick.py`, `tests/github/test_github_client.py`
- Docs: `RELEASE_CYCLE.md`
- Permissions: the compare endpoint needs `contents: read`. The job of `.github/workflows/release-merge.yml` gives `GITHUB_TOKEN` `contents: read`. The Service already reads the compare endpoint with its App token in `read_draft` (`src/devops_cli/roadmap/implement/implement_pull.py:296`).

## Feasibility

- `src/devops_cli/roadmap/stage/stage_ready.py:114` on `origin/main` (4ef7c6f11) sends `client.get_pr_diff(repo, number)` to Jev, and `src/devops_cli/release/merge_candidate.py:244` reads `pulls/{number}/files`. These are the two reads that the issue names.
- The merge base of a plan pull request can move. The plan fix step rebases the plan commit onto the latest default branch and force-pushes the plan branch (`src/devops_cli/roadmap/steps/fix_plan.py:488`). `devops pr update-branch` sends GitHub's `pulls/{n}/update-branch`, which merges the base branch into the head (`src/devops_cli/github/branch_update.py:36`). The update button of GitHub does the same.
- The merge base of a release pull request can move. The timeline of the release pull request of 0.127.0 holds one `head_ref_force_pushed` event, and that of 0.126.0 holds two: release-please force-pushes a new commit onto the tip of `main` when it updates the pull request.
- A live probe on 2026-11-13 of the 16 last closed pull requests of the Service App and the release App compared `compare/<base.sha>...<head>` with `compare/main...<head>`. In all 16, `base.sha` was the merge base and the two file counts were equal, so GitHub moved `base.sha` on each of those force-pushes. The stale case of #2530 came after a merge commit: `base.sha` 0137f231, merge base 5c4d24ee, 184 files against 11. So the two reads hold the defect only after a merge of the base branch into the head, and the compare read removes the dependency on GitHub moving `base.sha`.
- `devops gh api -H 'Accept: application/vnd.github.diff' 'repos/dan-petty/devops-cli/compare/main...8d08977f'` gave 7 `diff --git` lines on 2026-11-13, the same count as the pulls diff of the open plan pull request of #5272. So the compare endpoint serves the diff media type that `get_pr_diff` reads.
- `PullStatus` holds `base_ref` from `base.ref` of the payload (`src/devops_cli/github/client.py:98`), and `ReleasePull` holds `base_ref` too, so both readers know the base branch with no new request.
- `.github/workflows/release-merge.yml` gives the pick job `contents: read`, `pull-requests: read` and `checks: read`.
- Both readers read only open pull requests, so the rule of the issue for a merged pull request does not apply to them. `_settle` returns before the Jev check for a pull request that is not an open draft, and the pick lists `pulls?state=open`.
- A second live read on 2026-11-13 confirmed the release case: the timeline of the release pull request #5366 holds one `head_ref_force_pushed` event, and its `base.sha` f299667c9 is the tip of `main` when it merged.
- Item 2 cannot be built on `main` now. The pull request of #5346 is open on 2026-11-13, and only it compares `<base.ref>...<head>` in `devops review pr` and `devops ai analyze pr`. On `main`, `devops review pr` reads the pulls diff and `base.sha` (`src/devops_cli/commands/review.py:731`), and the pulls diff holds the files of a merged pull request. The item moves to #5397, which starts after that change merges.

## Existing Tool Considered

gidgethub 6.0.0 (Apache-2.0, maintained) is the GitHub REST client that ADR 0006 chooses. The GitHub session sends the compare request through it, and `GitHubClient.get_compare_files` already reads the compare. The change adds no dependency: it adds one read of the compare in the diff media type and moves two callers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## ADDED Requirements

### Requirement: The pick reads the files from the compare of the base branch
It SHALL read the files of a pull request from the compare of its base branch and its head commit, the diff that the squash merge applies. It MUST NOT read the pulls files list, because GitHub can keep a stale `base.sha` after the merge base moved, and then that list holds files of `main`.

#### Scenario: A stale base sha
- **WHEN** the payload `base.sha` of a release pull request is not the merge base, and its pulls files list holds a file of `main` beside the release files
- **THEN** the pick reads the compare of `main` and the head commit, sends no pulls files request, and picks the pull request
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## ADDED Requirements

### Requirement: Jev reads the diff of a stage draft from the compare of its base branch
The diff in the request of the Jev completeness check SHALL be the compare of the base branch of the draft and its head commit. The row MUST NOT read the diff of the pulls endpoint and MUST NOT compare from the payload `base.sha`, because GitHub can keep a stale `base.sha` after the merge base moved.

#### Scenario: A stale base sha
- **WHEN** the payload `base.sha` of a green draft is not the merge base, and the compare from it holds the files of another change
- **THEN** the request to Jev holds the diff of the compare of the base branch and the head commit, and the round reads no diff of the pulls endpoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Tasks

## 1. Behavior

- [x] 1.1 Write a failing test: a green stage draft with a stale payload `base.sha` sends Jev the diff of the compare of the base branch and the head commit, and the round reads no diff of the pulls endpoint
- Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_ready_jev.py`
- [x] 1.2 Write a failing test: the pick of the scheduled release merge reads the files of a release pull request with a stale payload `base.sha` from the compare of `main` and the head commit, sends no pulls files request, and picks the pull request
- Verification: `$ uv run devops ci test tests/release/test_release_merge_pick.py`
- [x] 1.3 Write a test: `GitHubClient.get_compare_diff` sends one request to the three-dot compare in the diff media type
- Verification: `$ uv run devops ci test tests/github/test_github_client.py`
- [x] 1.4 Add `GitHubClient.get_compare_diff`, give it and `get_pr_diff` one private read of a diff, give `_jev_holds` the `PullStatus` of the draft, and read the release files with `get_compare_files`
- Verification: `$ uv run devops ci fail-to-pass --base origin/main`

## 2. Documents

- [x] 2.1 Say in `RELEASE_CYCLE.md` that the file guard reads the compare of `main` and the head commit
- Verification: `$ uv run devops ci docs`
7 changes: 7 additions & 0 deletions openspec/specs/release-scheduled-merge/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ It SHALL pick the lowest-numbered pull request that passes and no other. `main`
#### Scenario: The label and the procedure
- **WHEN** `.github/labels.yml` and `RELEASE_CYCLE.md` are read
- **THEN** the label is declared and the procedure names the workflow, the cadence, the label and **Disable workflow**

### Requirement: The pick reads the files from the compare of the base branch
It SHALL read the files of a pull request from the compare of its base branch and its head commit, the diff that the squash merge applies. It MUST NOT read the pulls files list, because GitHub can keep a stale `base.sha` after the merge base moved, and then that list holds files of `main`.

#### Scenario: A stale base sha
- **WHEN** the payload `base.sha` of a release pull request is not the merge base, and its pulls files list holds a file of `main` beside the release files
- **THEN** the pick reads the compare of `main` and the head commit, sends no pulls files request, and picks the pull request
7 changes: 7 additions & 0 deletions openspec/specs/roadmap-stage/ready/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,10 @@ A diff over `CONST_ROADMAP_JEV_MAX_DIFF_TOKENS`, an item with no criterion, and
#### Scenario: A diff over the bound
- **WHEN** the diff holds more tokens than the bound
- **THEN** the check sends no request, logs the reason, and counts `skipped`

### Requirement: Jev reads the diff of a stage draft from the compare of its base branch
The diff in the request of the Jev completeness check SHALL be the compare of the base branch of the draft and its head commit. The row MUST NOT read the diff of the pulls endpoint and MUST NOT compare from the payload `base.sha`, because GitHub can keep a stale `base.sha` after the merge base moved.

#### Scenario: A stale base sha
- **WHEN** the payload `base.sha` of a green draft is not the merge base, and the compare from it holds the files of another change
- **THEN** the request to Jev holds the diff of the compare of the base branch and the head commit, and the round reads no diff of the pulls endpoint
16 changes: 15 additions & 1 deletion src/devops_cli/github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,16 @@ def get_compare_files(self, repo: str, base: str, head: str) -> CompareFiles:
files = _read_as(_CompareFiles, self._session.rest("GET", endpoint), path=endpoint).files
return CompareFiles(files=files, truncated=len(files) >= CONST_GITHUB_COMPARE_FILES_LIMIT)

def get_compare_diff(self, repo: str, base: str, head: str) -> str:
"""The unified diff of `head` since its merge base with `base`, from the compare endpoint.

With the tip of a pull request's base branch as `base`, this is the diff of the files that
`get_compare_files` lists, and not the diff of the pulls endpoint, which can keep a stale
`base.sha` after a merge commit moved the merge base (#5388). GitHub sends a diff as text;
any other answer raises `GitHubUnreadError`.
"""
return self._read_diff(_repo_path(repo, f"compare/{quote(base)}...{quote(head)}"))

def get_commit_pulls(self, repo: str, sha: str) -> list[CommitPull]:
"""Every pull request that GitHub associates with the commit `sha`, merged or not.

Expand Down Expand Up @@ -690,7 +700,11 @@ def get_pr_diff(self, repo: str, number: int) -> str:
GitHub sends a diff as text; any other answer, JSON or a body without a content type,
raises `GitHubUnreadError`. A pull request with no changes returns an empty string.
"""
path = _repo_path(repo, f"pulls/{number}")
return self._read_diff(_repo_path(repo, f"pulls/{number}"))

def _read_diff(self, path: str) -> str:
"""The diff GitHub serves at `path` in the diff media type, raising `GitHubUnreadError`
for an answer that is not text."""
diff = self._session.rest("GET", path, accept=CONST_GITHUB_DIFF_MEDIA_TYPE)
if not isinstance(diff, str):
raise GitHubUnreadError(
Expand Down
Loading