Repository navigation
refactor(http-client): share GitHub release fetching between lookups - #191
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 dependantsmoon-reqwest-client and moon-gpui stay green with
cargo test -p moon-reqwest-clientandcargo 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.