fix(ci): replace gh pr CLI with Gitea v1 REST in workflows + scripts (#75 class A) #80
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/issue75-class-A-gh-pr-to-gitea-rest"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Class A of the post-#66 sweep tracked in #75: replace
gh pr list / view / diff / commentshapes with direct Gitea v1 REST calls.Why
Gitea exposes /api/v1/ only — no GraphQL → HTTP 405; no /api/v3 → HTTP 404.
gh pr ...calls hit one or both and fail silently (or noisily, depending on the call site). PR #66 fixed the most-acute case (auto-sync-main-to-staging.yml) by switching to direct push; this PR extends the same fix to the rest of class A.Files
.github/workflows/auto-tag-runtime.ymlgh pr list --state merged --search SHAcurl /api/v1/repos/.../pulls?state=closed+ jq filter onmerge_commit_shascripts/check-stale-promote-pr.shgh pr list / view / commentcurl /api/v1/repos/.../pulls + .../reviews + .../issues/{n}/comments, synthesizesmergeStateStatus/reviewDecisionfrom Gitea fields so existing fixtures + tests still applyscripts/ops/check_migration_collisions.pygh pr list+gh pr diff(subprocess)/api/v1/repos/.../pulls + .../pulls/{n}/files, helper_gitea_getfor shared auth + error handlingTest plan
open_prs_with_migration_prefixagainst prefix=999 returns 0 results (expected)Hostile self-review — three weakest spots
fetch_prsmakes N+1 HTTP calls (one for the PR list + one /reviews per PR). On the molecule-ai fleet there's typically 0–2 open base=main head=staging PRs, so worst-case ~3 round-trips per cron firing.mergeable=nullasUNKNOWN→DIRTYrather than re-fetching. Acceptable: Gitea recomputes lazily, the next cron firing recovers.open_prs_with_migration_prefixreturns[]on a transient 5xx rather than retrying. Acceptable: base-branch check still catches the more-common collision class.Closes part of #75
🤖 Generated with Claude Code
Part of the post-#66 sweep to remove `gh` CLI dependencies that fail silently against Gitea (which exposes /api/v1 only — no GraphQL → 405, no /api/v3 → 404). Class A covers `gh pr list / view / diff / comment` shapes. Affected: - `.github/workflows/auto-tag-runtime.yml` Replaced `gh pr list --search SHA --json number,labels` with a curl to `/api/v1/repos/.../pulls?state=closed&sort=newest&limit=50` + jq filter on `merge_commit_sha == github.sha`. Same end-to-end behaviour: locate the merged PR for this push, read its labels, pick the bump kind. Defensive `?.name // empty` jq guard handles unlabelled PRs without erroring. The 50-PR window is comfortably larger than the volume of staging→main promotes that close in any reasonable detection window. - `scripts/check-stale-promote-pr.sh` Rewrote `fetch_prs` and `post_comment` to call Gitea's REST API directly. Gitea doesn't expose GitHub's compound `mergeStateStatus` / `reviewDecision` fields, so the new fetcher pulls `/pulls?state=open&base=main` then for each PR pulls `/pulls/{n}/reviews` and synthesizes the GitHub-shape JSON the rest of the script (and the existing fixture-based unit tests) consume: BLOCKED + REVIEW_REQUIRED ↔ mergeable=true AND 0 APPROVED reviews DIRTY ↔ mergeable=false (alarm doesn't fire) CLEAN + APPROVED ↔ mergeable=true AND ≥1 APPROVED review Comment-posting moves to `POST /repos/.../issues/{n}/comments` (Gitea treats PRs as issues for the comment surface, same as GitHub's REST). All 23 fixture-driven unit tests still pass — fixtures pass GitHub-shape JSON via PR_FIXTURE which short-circuits the live fetch path. - `scripts/ops/check_migration_collisions.py` Replaced `gh pr list` + `gh pr diff` calls with stdlib `urllib` against /api/v1. Helper `_gitea_get` centralizes auth + error handling; uses GITEA_TOKEN env, falling back to GITHUB_TOKEN (act_runner) and GH_TOKEN. Return shape from `open_prs_with_migration_prefix` mimics the historical `--json number,headRefName` so the call sites are unchanged. All 9 regex-classifier unit tests still pass; live integration test against the production Gitea API returns 0 collisions for prefix=999 as expected. curl invocation pattern is `curl --fail-with-body -sS` (NOT `-fsS` — the two short-fail flags are mutually exclusive in modern curl; caught by `curl: You must select either --fail or --fail-with-body, not both` during local verification). Token model: workflows pass act_runner's GITHUB_TOKEN (per-run, repo read scope) — same surface used by the auto-sync fix in PR #66 plus the surrounding workflows. No new repo secrets required. Verification: bash unit tests (23/23 pass), python unittest (9/9 pass), live curl call against production Gitea returns 200 with the expected shape, YAML / shell / Python syntax all validate. Closes part of #75. Other classes (D — `gh api`; F — `gh run list`) land in follow-up PRs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>gh-CLI sweep class A (gh pr list/view/diff/comment → Gitea REST). 3 files: auto-tag-runtime.yml + 2 ops scripts. 23 unit tests + 9 python tests pass. Live-integration verified against prod Gitea. 24/24 first-run green; 2nd-run pre-existing pr-guards flake. Ready.