Landing L3: gc forgejo pr state --json also reports mergeable and the reviews of the head #36

Merged
city-root merged 2 commits from worker/gascitypacks-vq0 into main 2026-11-12 10:14:07 +00:00
Contributor

gc forgejo pr state --json also reports mergeable and the reviews of a pull request (Landing L3, gascitypacks-vq0), two fields added to schema version 1.

  • mergeable: mergeable, not_mergeable or draft for an open pull request, null otherwise. Forgejo 17.0.1 answers a bare boolean, false for a conflict, a running conflict check and a failed one alike, so not_mergeable says "not now", and the README says how a caller waits for a second read before it takes it as a conflict.
  • reviews: every review, oldest first, each with id, account, team, state, commit, body, official, stale, dismissed, submitted_at. All pages are read (the forge pages by row and drops other accounts' pending reviews from a page, so a short page is not the last). The README gives the jq rules for "the current head has an approval that counts" and "a blocking review stands", and says what a caller cannot know (the whitelist is not readable with the city's token).
  • Contract: the fields that existed keep their names and meaning; schema_version stays "1". With --json the command exits 1 with nothing on stdout when the reviews cannot be read or an open pull request has no mergeable field, where #34 printed an object. Without --json nothing changes and the merge order behaves as before.
  • Client rules hold: only the forge's own 404 is missing, 5xx/timeouts/bad tokens are errors, a foreign --pr gets no request, and the token goes to the forge's host only.

Verified: go vet and go test in forgejo, gc lint ., tests/formula.sh, tests/merge.sh. The README holds the table of what the output says for no review, an approval of the current head, an approval of an earlier head, a request for changes, a dismissed review and a pull request whose mergeability is still being checked.

Second round (rebased onto main 2a91bb2, which carries the tests/gnu-tools.sh fix): the README now says the --json exit-1 case; a review requested of a team keeps the team's name in team.

gascitypacks-vq0

`gc forgejo pr state --json` also reports `mergeable` and the `reviews` of a pull request (Landing L3, gascitypacks-vq0), two fields added to schema version 1. - `mergeable`: `mergeable`, `not_mergeable` or `draft` for an open pull request, null otherwise. Forgejo 17.0.1 answers a bare boolean, false for a conflict, a running conflict check and a failed one alike, so `not_mergeable` says "not now", and the README says how a caller waits for a second read before it takes it as a conflict. - `reviews`: every review, oldest first, each with `id`, `account`, `team`, `state`, `commit`, `body`, `official`, `stale`, `dismissed`, `submitted_at`. All pages are read (the forge pages by row and drops other accounts' pending reviews from a page, so a short page is not the last). The README gives the jq rules for "the current head has an approval that counts" and "a blocking review stands", and says what a caller cannot know (the whitelist is not readable with the city's token). - Contract: the fields that existed keep their names and meaning; `schema_version` stays `"1"`. With `--json` the command exits 1 with nothing on stdout when the reviews cannot be read or an open pull request has no `mergeable` field, where #34 printed an object. Without `--json` nothing changes and the merge order behaves as before. - Client rules hold: only the forge's own 404 is `missing`, 5xx/timeouts/bad tokens are errors, a foreign `--pr` gets no request, and the token goes to the forge's host only. Verified: `go vet` and `go test` in `forgejo`, `gc lint .`, `tests/formula.sh`, `tests/merge.sh`. The README holds the table of what the output says for no review, an approval of the current head, an approval of an earlier head, a request for changes, a dismissed review and a pull request whose mergeability is still being checked. Second round (rebased onto main 2a91bb2, which carries the `tests/gnu-tools.sh` fix): the README now says the `--json` exit-1 case; a review requested of a team keeps the team's name in `team`. gascitypacks-vq0
feat(forgejo): gc forgejo pr state --json reports mergeable and the reviews (gascitypacks-vq0)
Some checks failed
test / changelog (pull_request) Successful in 5s
test / scripts (pull_request) Failing after 10s
test / lint (pull_request) Successful in 19s
e5ffa99fc8
Landing L3. The review command, the rework order and the review order will
read a pull request through this output, so it has to say, from the output
alone, whether the current head has an approval that counts under the city's
branch protection and whether a blocking review stands.

The object gains two fields in schema version 1, which stays "1": nothing an
older caller reads changed. `mergeable` is mergeable, not_mergeable or draft
for an open pull request, null otherwise. `reviews` is every review, oldest
first, each with id, account, state, commit, body, official, stale, dismissed
and submitted_at; null for missing and foreign.

Read from Forgejo 17.0.1's source (not tried on a real pull request):
- the API's mergeable is a bare boolean, false for a conflict, a conflict
  check still running and a failed one alike, so "still checking" cannot get
  a value of its own; not_mergeable says only what the forge says, and the
  README says how a caller confirms a conflict with a later read;
- the reviews list is paged by row, and other accounts' pending reviews are
  dropped from each page afterwards, so a short page is not the last. The
  tool reads to an empty page that X-Total-Count confirms, and the fake
  forge answers the same way (bare array, X-Total-Count of all rows, pending
  reviews dropped after paging);
- a new approval or rejection clears `official` on the account's earlier
  reviews, so a later approval ends an earlier request for changes; a
  request for changes blocks whatever its commit.

The README gives the two decision rules as jq programs (tested on jq 1.6,
1.7.1 and 1.8.2), a table of the cases, and what a caller cannot know. The
tests cover each case of the table, paging, the failure rules and the
version 1 fields; go vet, go test, gc lint, tests/merge.sh and the v1
changelog check pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Contributor

Review of e5ffa99 (Landing L3, gascitypacks-vq0). Not approved and not merged, because a required check failed. The change itself passes review: the failed check comes from a race in an existing test, not from this change.

The failed check: test / scripts, run 104 (job 4193).

  • The job ran tests/worktree-setup.sh and tests/worktree.sh (both print ok), then exited with status 141 (SIGPIPE) in tests/gnu-tools.sh, before that script printed ok.
  • The cause is tests/gnu-tools.sh:235, first="$(rows | head -n 1)", under set -euo pipefail (line 9). rows (line 39) is a while loop that echoes one line at a time. head exits after the first line, so the loop's next echo gets SIGPIPE, the pipeline returns 141, and set -e ends the script. Whether it happens depends on timing.
  • I reproduced the mechanism in isolation (rows-shaped loop | head -n 1 under pipefail exits 141). Locally, 40 runs of the script all passed; on the Linux runner it lost the race.
  • This pull request touches neither tests/ nor roles/, and the same script passed on every earlier run.

What must change before this can merge:

  1. Get test / scripts green on this head: re-run the job, or rebase onto main once the race is fixed. The race is not this change's to fix. The Operator should file it separately: at tests/gnu-tools.sh:235, take the first row without a pipe that can break, for example first="$(rows | sed -n 1p)" or first="$(printf '%s\n' "$tools" | awk 'NF{print; exit}')".

Minor, optional in this pull request:
2. forgejo/assets/forgejo/reviews.go, forgeReview: a review requested of a team has account: null and the team is dropped (the forge sends it as team, modules/structs/pull_review.go:32). Two teams' requests then look the same. A team field, or a README sentence that team requests carry no name, would close that.
3. README "Reading a pull request's state": say that --json now exits 1 when the reviews list cannot be read, or when an open pull request has no mergeable. An older caller that got an object from #34's tool in those cases now gets an error. This is safe, but it is a change in behaviour.

What I checked, and what holds (Forgejo source at v17.0.1, 363f3dc):

  • mergeable. The API field is a bare bool (modules/structs/pull.go:38), set from pr.Mergeable() (services/convert/pull.go:89). That is false for checking, conflict, error and a WIP title (models/issues/pull.go:887-895), and Status is not in the API's answer. So the deviation is forced by the forge.
    • not_mergeable says neither "conflicts" nor "clean", mergeable is the only value that means clean, and draft has its own value. No two situations share a value that claims more than the forge said. The README's rule (take it as a conflict only on a later read at the same head) is right.
  • Review fields are passed through as the forge has them (services/convert/pull_review.go:16-62): official, stale, dismissed, commit_id, and the states APPROVED, REQUEST_CHANGES, COMMENT, PENDING, REQUEST_REVIEW and "" (modules/structs/pull_review.go:13-26), in lower case with "" as unknown.
    • official is cleared on the account's earlier reviews by a new approve or reject, on both paths (models/issues/review.go:422-426 and :452-456), and comes from the whitelist (models/git/protected_branch.go:177-194).
    • A dismissal applies only to approve/reject (review.go:575-576).
    • The counting rules quoted match models/issues/pull.go:906-941.
    • The README's approval rule (commit == head) is stricter than the forge's, deliberately, and it says so.
  • Every page is read. The forge pages by row, then drops other accounts' pending reviews (convert/pull_review.go:65-79), puts the total only in X-Total-Count (routers/api/v1/repo/pull_review.go:95-108), orders by created_unix, id (review_list.go:122-133), and uses a 30/50 page size (setting/api.go:24-25). The pack's fake does the same.
    • My own case, on a separate fake: 120 rows with the first 55 other accounts' pending reviews (page 1 comes back empty) and an official REQUEST_CHANGES as row 120. It gave 65 reviews and block: true, in 4 requests.
    • Mutations fail the tests: stopping on a short page fails 5 cases, and stopping on any empty page fails 1.
  • The contract holds. The six fields of #34 are unchanged for 17 cases (each old field equal between main and head). Keeping schema_version at "1" is right under the rule #34 published: fields added, none changed.
    • The one-word output is byte-identical (stdout, stderr, exit) and makes no extra request. The merge order is untouched.
    • The client rules hold: the reviews' 404 is an error, never missing.
  • The merge result passes everything CI runs, on head merged into main e22b7f9: go vet, go test, every tests/*.sh (gnu-tools included), gc lint ., and the changelog check built from v1 source (valid=true). test / lint and test / changelog on the head: success.

Once test / scripts is green on this head, it can be approved and merged as it stands.

Review of e5ffa99 (Landing L3, gascitypacks-vq0). **Not approved and not merged**, because a required check failed. The change itself passes review: the failed check comes from a race in an existing test, not from this change. **The failed check: `test / scripts`, run 104 (job 4193).** - The job ran `tests/worktree-setup.sh` and `tests/worktree.sh` (both print `ok`), then exited with status **141** (SIGPIPE) in `tests/gnu-tools.sh`, before that script printed `ok`. - The cause is `tests/gnu-tools.sh:235`, `first="$(rows | head -n 1)"`, under `set -euo pipefail` (line 9). `rows` (line 39) is a `while` loop that echoes one line at a time. `head` exits after the first line, so the loop's next `echo` gets SIGPIPE, the pipeline returns 141, and `set -e` ends the script. Whether it happens depends on timing. - I reproduced the mechanism in isolation (`rows`-shaped loop | `head -n 1` under pipefail exits 141). Locally, 40 runs of the script all passed; on the Linux runner it lost the race. - This pull request touches neither `tests/` nor `roles/`, and the same script passed on every earlier run. **What must change before this can merge:** 1. **Get `test / scripts` green on this head**: re-run the job, or rebase onto main once the race is fixed. The race is not this change's to fix. The Operator should file it separately: at `tests/gnu-tools.sh:235`, take the first row without a pipe that can break, for example `first="$(rows | sed -n 1p)"` or `first="$(printf '%s\n' "$tools" | awk 'NF{print; exit}')"`. **Minor, optional in this pull request:** 2. `forgejo/assets/forgejo/reviews.go`, `forgeReview`: a review requested of a team has `account: null` and the team is dropped (the forge sends it as `team`, `modules/structs/pull_review.go:32`). Two teams' requests then look the same. A `team` field, or a README sentence that team requests carry no name, would close that. 3. README "Reading a pull request's state": say that `--json` now exits 1 when the reviews list cannot be read, or when an open pull request has no `mergeable`. An older caller that got an object from #34's tool in those cases now gets an error. This is safe, but it is a change in behaviour. **What I checked, and what holds (Forgejo source at v17.0.1, 363f3dc):** - **`mergeable`.** The API field is a bare `bool` (`modules/structs/pull.go:38`), set from `pr.Mergeable()` (`services/convert/pull.go:89`). That is false for `checking`, `conflict`, `error` and a WIP title (`models/issues/pull.go:887-895`), and `Status` is not in the API's answer. So the deviation is forced by the forge. - `not_mergeable` says neither "conflicts" nor "clean", `mergeable` is the only value that means clean, and `draft` has its own value. No two situations share a value that claims more than the forge said. The README's rule (take it as a conflict only on a later read at the same head) is right. - **Review fields** are passed through as the forge has them (`services/convert/pull_review.go:16-62`): `official`, `stale`, `dismissed`, `commit_id`, and the states APPROVED, REQUEST_CHANGES, COMMENT, PENDING, REQUEST_REVIEW and "" (`modules/structs/pull_review.go:13-26`), in lower case with "" as `unknown`. - `official` is cleared on the account's earlier reviews by a new approve or reject, on both paths (`models/issues/review.go:422-426` and :452-456), and comes from the whitelist (`models/git/protected_branch.go:177-194`). - A dismissal applies only to approve/reject (`review.go:575-576`). - The counting rules quoted match `models/issues/pull.go:906-941`. - The README's approval rule (`commit == head`) is stricter than the forge's, deliberately, and it says so. - **Every page is read.** The forge pages by row, then drops other accounts' pending reviews (`convert/pull_review.go:65-79`), puts the total only in `X-Total-Count` (`routers/api/v1/repo/pull_review.go:95-108`), orders by `created_unix, id` (`review_list.go:122-133`), and uses a 30/50 page size (`setting/api.go:24-25`). The pack's fake does the same. - My own case, on a separate fake: 120 rows with the first 55 other accounts' pending reviews (page 1 comes back empty) and an official REQUEST_CHANGES as row 120. It gave 65 reviews and `block: true`, in 4 requests. - Mutations fail the tests: stopping on a short page fails 5 cases, and stopping on any empty page fails 1. - **The contract holds.** The six fields of #34 are unchanged for 17 cases (each old field equal between main and head). Keeping `schema_version` at "1" is right under the rule #34 published: fields added, none changed. - The one-word output is byte-identical (stdout, stderr, exit) and makes no extra request. The merge order is untouched. - The client rules hold: the reviews' 404 is an error, never `missing`. - **The merge result passes everything CI runs**, on head merged into main e22b7f9: `go vet`, `go test`, every `tests/*.sh` (gnu-tools included), `gc lint .`, and the changelog check built from v1 source (`valid=true`). `test / lint` and `test / changelog` on the head: success. Once `test / scripts` is green on this head, it can be approved and merged as it stands.
mikluko force-pushed worker/gascitypacks-vq0 from e5ffa99fc8
Some checks failed
test / changelog (pull_request) Successful in 5s
test / scripts (pull_request) Failing after 10s
test / lint (pull_request) Successful in 19s
to e89c6457ef
All checks were successful
test / changelog (pull_request) Successful in 5s
test / lint (pull_request) Successful in 17s
test / scripts (pull_request) Successful in 34s
2026-11-12 10:07:09 +00:00
Compare
Author
Contributor

Rework round done, pushed as e89c645 on top of main (2a91bb2, the gnu-tools SIGPIPE fix, so the checks run on a head that carries it).

  • README: the section on compatibility now says that with --json the command exits 1, with nothing on stdout, when the reviews cannot be read or an open pull request has no mergeable field, where the command of #34 printed an object; the CHANGELOG entry says it too.
  • A review requested of a team keeps the team name: each review has a new team field (string or null), taken from the forge's team.name; account stays null for such a review. Tests, the README table, the help text and the CHANGELOG follow.
  • The pull request now has a description.

Nothing else changed. Locally: go vet, go test, gc lint, tests/formula.sh and tests/merge.sh pass.

Rework round done, pushed as e89c645 on top of main (2a91bb2, the gnu-tools SIGPIPE fix, so the checks run on a head that carries it). - README: the section on compatibility now says that with `--json` the command exits 1, with nothing on stdout, when the reviews cannot be read or an open pull request has no `mergeable` field, where the command of #34 printed an object; the CHANGELOG entry says it too. - A review requested of a team keeps the team name: each review has a new `team` field (string or null), taken from the forge's `team.name`; `account` stays null for such a review. Tests, the README table, the help text and the CHANGELOG follow. - The pull request now has a description. Nothing else changed. Locally: go vet, go test, gc lint, tests/formula.sh and tests/merge.sh pass.
city-root-review left a comment

Reviewed e89c645 in full (rebase of e5ffa99 unchanged plus the team field and the README exit-1 note): go vet, go test, gc lint, every tests/*.sh and the changelog check pass on the merge result; CI green.

Reviewed e89c645 in full (rebase of e5ffa99 unchanged plus the team field and the README exit-1 note): go vet, go test, gc lint, every tests/*.sh and the changelog check pass on the merge result; CI green.
Author
Contributor

Review of e89c645 (Landing L3, gascitypacks-vq0, rework round). Approved by city-root-review and merged (squash, 08a754e).

What I checked

  • The rework is what the bead's notes asked, nothing else. 2c0934e is e5ffa99 rebased onto main 2a91bb2: its added and removed lines are identical to e5ffa99's diff (taken from the forge). e89c645 adds only the team field (reviews.go: the forge's team.name, null for a review of an account), its tests, the README row, the help text, and the README and CHANGELOG sentences that --json now exits 1, with nothing on stdout, when the reviews cannot be read or an open pull request has no mergeable.
  • The whole diff, read again. mergeable: draft first, a missing field is an error, true maps to mergeable and false to not_mergeable; it never claims a conflict or a clean pull request the forge did not report. Reviews: every page is read, and the tool stops only on an empty page that X-Total-Count confirms. Only the pull request's own 404 is missing; a 404, 5xx, 401 or undecodable page of the reviews is exit 1. Without --json nothing changes and no request is added (renderState returns before any request).
  • Schema version 1 still holds. The six old fields keep their names and meaning, so a version-1 reader survives the two new fields. The only change it sees is the new exit 1, and the README now says so.
  • The forge's fields, checked live on sarak.sh (read-only). A pull request has mergeable and draft. A review has user, team, state, commit_id, official, stale, dismissed, submitted_at, and the list sends X-Total-Count. The fake forge answers in the same shape, pages by row, and drops other accounts' pending reviews.
  • CI on e89c645: test / changelog, test / lint and test / scripts succeeded (run 1625).
  • The merge result. Main had not moved, so it is the head itself. On it: go vet, go test (also with -race), gc lint ., every tests/*.sh the workflow runs, and the changelog check built from mikluko/changelog v1 source all pass (valid=true). The entry is under [Unreleased].
  • Shell: none added. The logic is in tested Go.

Follow-up (minor, not blocking)

  • pullReviews decides about an empty page with page*limit >= total, taking limit as 50. If a forge caps MAX_RESPONSE_ITEMS below 50, an empty page made only of other accounts' pending reviews could end the read early. That cannot happen on sarak.sh's defaults.

Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.

Review of e89c645 (Landing L3, gascitypacks-vq0, rework round). **Approved by `city-root-review` and merged** (squash, 08a754e). **What I checked** - **The rework is what the bead's notes asked, nothing else.** `2c0934e` is e5ffa99 rebased onto main 2a91bb2: its added and removed lines are identical to e5ffa99's diff (taken from the forge). `e89c645` adds only the `team` field (`reviews.go`: the forge's `team.name`, null for a review of an account), its tests, the README row, the help text, and the README and CHANGELOG sentences that `--json` now exits 1, with nothing on stdout, when the reviews cannot be read or an open pull request has no `mergeable`. - **The whole diff, read again.** `mergeable`: draft first, a missing field is an error, `true` maps to `mergeable` and `false` to `not_mergeable`; it never claims a conflict or a clean pull request the forge did not report. Reviews: every page is read, and the tool stops only on an empty page that `X-Total-Count` confirms. Only the pull request's own 404 is `missing`; a 404, 5xx, 401 or undecodable page of the reviews is exit 1. Without `--json` nothing changes and no request is added (`renderState` returns before any request). - **Schema version 1 still holds.** The six old fields keep their names and meaning, so a version-1 reader survives the two new fields. The only change it sees is the new exit 1, and the README now says so. - **The forge's fields, checked live on sarak.sh (read-only).** A pull request has `mergeable` and `draft`. A review has `user`, `team`, `state`, `commit_id`, `official`, `stale`, `dismissed`, `submitted_at`, and the list sends `X-Total-Count`. The fake forge answers in the same shape, pages by row, and drops other accounts' pending reviews. - **CI on e89c645:** `test / changelog`, `test / lint` and `test / scripts` succeeded (run 1625). - **The merge result.** Main had not moved, so it is the head itself. On it: `go vet`, `go test` (also with `-race`), `gc lint .`, every `tests/*.sh` the workflow runs, and the changelog check built from mikluko/changelog v1 source all pass (`valid=true`). The entry is under `[Unreleased]`. - **Shell:** none added. The logic is in tested Go. **Follow-up (minor, not blocking)** - `pullReviews` decides about an empty page with `page*limit >= total`, taking `limit` as 50. If a forge caps `MAX_RESPONSE_ITEMS` below 50, an empty page made only of other accounts' pending reviews could end the read early. That cannot happen on sarak.sh's defaults. Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/gascitypacks!36
No description provided.