Skip to content

refactor(http-client): share GitHub release fetching between lookups - #191

Merged
kirillDevPro merged 2 commits into
masterfrom
lane/refactor-2026-11-30
Nov 30, 2026
Merged

kirillDevPro merged 2 commits into
masterfrom
lane/refactor-2026-11-30

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

Refactor lane.

Signal: duplicated logic. latest_github_release (github.rs:34-95
before) and get_release_by_tag_name (github.rs:97-157 before) each
carried their own copy of three steps: building and sending the GET
request (FollowAll redirects, the optional GITHUB_TOKEN bearer header),
reading the body and rejecting a 4xx status (github.rs:42-67 and
111-136); the two log::error! lines on a body that fails to
deserialize (github.rs:73-77 and 140-144); and stripping the sha256:
prefix from asset digests (github.rs:87-93 and 147-153). The copies
had already drifted once: the digest strip existed only in the latest
lookup until b338a1f fixed the tagged one. Each step is now one private
function both lookups call: fetch_github_api_body (github.rs:92),
log_undeserializable_body (github.rs:124) and
strip_sha256_digest_prefixes (github.rs:135). Error messages, context
strings, log text and every public item are unchanged.

Lines: the two lookups 124 -> 56, the file 208 -> 195.

Tests covering it: crates/moon-http-client/tests/github_release_fetch.rs
(pinned against the untouched code in the previous commit),
release_by_tag_url.rs and release_by_tag_digest.rs. Re-run with
cargo test -p moon-http-client --all-features; the dependants
moon-reqwest-client and moon-gpui stay green with
cargo test -p moon-reqwest-client and cargo test -p moon-gpui.

Reviewer: Codex. It confirmed the copies were identical in text and
arguments and that every public item keeps its name and signature. It
raised three non-semantic differences, kept after checking the source:
the response is now dropped when fetch_github_api_body returns rather
than at the end of the lookup, but the body has already been read to
EOF and no await point lies between the two places, so no other task
can observe the gap and a panicking body Drop still panics the same
call; and the log records and error backtraces now point at the shared
helper's file:line, with the same text, level and order.

Pins, through a scripted HttpClient, what latest_github_release and
get_release_by_tag_name do today: the endpoint, the FollowAll redirect
policy and the GITHUB_TOKEN bearer header they send; the
`status error <code>, response: <body>` error on a 4xx; a 5xx body
reaching the JSON parser with each lookup's own deserialization error;
the `error fetching latest release` context on a failed send; the
sha256: prefix stripped from asset digests and nothing else; and the
latest lookup's release-selection rule with its `finding a prerelease`
error.
Refactor lane.

Signal: duplicated logic. latest_github_release (github.rs:34-95
before) and get_release_by_tag_name (github.rs:97-157 before) each
carried their own copy of three steps: building and sending the GET
request (FollowAll redirects, the optional GITHUB_TOKEN bearer header),
reading the body and rejecting a 4xx status (github.rs:42-67 and
111-136); the two log::error! lines on a body that fails to
deserialize (github.rs:73-77 and 140-144); and stripping the sha256:
prefix from asset digests (github.rs:87-93 and 147-153). The copies
had already drifted once: the digest strip existed only in the latest
lookup until b338a1f fixed the tagged one. Each step is now one private
function both lookups call: fetch_github_api_body (github.rs:92),
log_undeserializable_body (github.rs:124) and
strip_sha256_digest_prefixes (github.rs:135). Error messages, context
strings, log text and every public item are unchanged.

Lines: the two lookups 124 -> 56, the file 208 -> 195.

Tests covering it: crates/moon-http-client/tests/github_release_fetch.rs
(pinned against the untouched code in the previous commit),
release_by_tag_url.rs and release_by_tag_digest.rs. Re-run with
`cargo test -p moon-http-client --all-features`; the dependants
moon-reqwest-client and moon-gpui stay green with
`cargo test -p moon-reqwest-client` and `cargo test -p moon-gpui`.

Reviewer: Codex. It confirmed the copies were identical in text and
arguments and that every public item keeps its name and signature. It
raised three non-semantic differences, kept after checking the source:
the response is now dropped when fetch_github_api_body returns rather
than at the end of the lookup, but the body has already been read to
EOF and no await point lies between the two places, so no other task
can observe the gap and a panicking body Drop still panics the same
call; and the log records and error backtraces now point at the shared
helper's file:line, with the same text, level and order.
@kirillDevPro
kirillDevPro merged commit 63cede6 into master Nov 30, 2026
4 checks passed
@kirillDevPro
kirillDevPro deleted the lane/refactor-2026-11-30 branch November 30, 2026 05:44
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.

1 participant