feat(rust): add mergify-core::http with retry + typed errors (Phase 1.2b)#1281
Conversation
Member
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Apr 21, 2026
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 👀 Review RequirementsWaiting for:
This rule is failing.
🔴 🔎 ReviewsWaiting for:
This rule is failing.
🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
….2b) Adds the HTTP client every ported command uses. Wraps ``reqwest`` with the invariants the design requires: - Bearer-token auth injected when the token is non-empty; skipped otherwise so GitHub's anonymous public-repo reads still work. - Tenacity-style retry on 5xx and transient network errors: 3 attempts, exponential backoff starting at 1s. 4xx responses are never retried — those are caller errors and retrying would mask bugs. - Typed error mapping: HTTP failures become either ``CliError::GitHubApi`` or ``CliError::MergifyApi`` based on the ``ApiFlavor`` passed at construction, so ``exit_code()`` routes to ``GITHUB_API_ERROR`` (5) or ``MERGIFY_API_ERROR`` (6) automatically. - Per-request timeout of 30s. - ``RetryPolicy`` is public so tests can skip the wall-clock backoff with ``initial_backoff = 0``. Also extends ``CliError`` with the two new API variants and updates the ``exit_code()`` mapping + unit tests. Command crates MUST NOT import ``reqwest`` directly — the only HTTP surface is ``HttpClient::get`` and ``HttpClient::post``. 6 new tests cover: happy-path GET, empty-token behavior, POST with JSON body, retry on 5xx then success, exhausted retries mapping to ``MergifyApi``, 4xx not retried and mapping to ``GitHubApi``. All use ``wiremock`` for hermetic local HTTP. Next sub-phase (1.2c / 1.2d) adds colored/spinner affordances and the ``GitOps`` trait only when the first ported command needs them; this PR is the minimum ``config validate`` requires. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Change-Id: I9c66057cc53acd0098f43086352ca9a9bf5aa7b0
61966dc to
0e72eb6
Compare
Member
Author
Revision history
|
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.
Adds the HTTP client every ported command uses. Wraps
reqwestwith the invariants the design requires:
otherwise so GitHub's anonymous public-repo reads still work.
attempts, exponential backoff starting at 1s. 4xx responses are
never retried — those are caller errors and retrying would mask
bugs.
CliError::GitHubApiorCliError::MergifyApibased on theApiFlavorpassed at construction, soexit_code()routesto
GITHUB_API_ERROR(5) orMERGIFY_API_ERROR(6)automatically.
RetryPolicyis public so tests can skip the wall-clockbackoff with
initial_backoff = 0.Also extends
CliErrorwith the two new API variants andupdates the
exit_code()mapping + unit tests.Command crates MUST NOT import
reqwestdirectly — the onlyHTTP surface is
HttpClient::getandHttpClient::post.6 new tests cover: happy-path GET, empty-token behavior, POST
with JSON body, retry on 5xx then success, exhausted retries
mapping to
MergifyApi, 4xx not retried and mapping toGitHubApi. All usewiremockfor hermetic local HTTP.Next sub-phase (1.2c / 1.2d) adds colored/spinner affordances and
the
GitOpstrait only when the first ported command needsthem; this PR is the minimum
config validaterequires.Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Depends-On: #1280