Skip to content

refactor(forge): share one REST client between GitHub, Gitea and GitLab pagination - #1287

Merged
BryanFRD merged 1 commit into
mainfrom
refactor/forge-rest-client
Oct 6, 2026
Merged

BryanFRD merged 1 commit into
mainfrom
refactor/forge-rest-client

Conversation

@BryanFRD

@BryanFRD BryanFRD commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Closes #1285

gitea.rs was 36.7% duplicated from github.rs (Sonar): pagination, the three release calls and the three comment calls, identical except for headers, the page-size parameter and the error codes. GitLab had a third copy of the pagination loop.

src/forge/rest.rs now holds a RestClient built per forge with its auth header, extra headers and page-size parameter (RestClient::github, ::gitea, ::gitlab). It owns pagination, create_release, find_draft_release, publish_release, find_comment, create_comment and update_comment. Each forge keeps its own context messages and error codes by wrapping the call, so the error chain users see is unchanged.

Two small differences worth knowing:

  • Pagination now builds its query with ureq's query, giving the same ?per_page=…&page=… (or ?limit=… on Gitea) URL as before.
  • On GitHub, the comment calls now also send X-GitHub-Api-Version, which the release and pagination calls already did. That is the documented header; the inconsistency was accidental.

percent_encode_path moves from config::loader_js to a neutral crate::uri module, since both forges and the JS loader use it (raised in the reviews of #1267 and #1269).

Forge and config tests pass (518), including the fake-server API tests for each forge.

@BryanFRD
BryanFRD enabled auto-merge (squash) October 6, 2026 06:49

@ferrfleet ferrfleet Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behaviour matches the old per-forge code: same headers (GitHub comment calls now also send X-GitHub-Api-Version, which is harmless), same page sizes, same error contexts and codes. Switching to .query() for paging is an improvement. Test and Coverage were still running when I reviewed.

Nit: RestClient::gitlab (src/forge/gitlab.rs:54) is only used for pagination. Its repo_url is built and then never read, and the client still exposes create_release, create_comment, update_comment and find_comment. Those methods use GitHub/Gitea paths and payloads (/issues/..., body rather than description), so a later caller would get a client that looks valid and hits the wrong GitLab endpoints. I'd move the pagination loop into a free paginate(request_fn, ...) that all three forges share, and keep RestClient for GitHub and Gitea only. If you'd rather keep the GitLab constructor, at least add a doc comment saying only paginated_json_array applies.

@BryanFRD
BryanFRD merged commit a4af50c into main Oct 6, 2026
32 checks passed
@BryanFRD
BryanFRD deleted the refactor/forge-rest-client branch October 6, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(forge): GitHub and Gitea duplicate their REST client

1 participant