Skip to content

Report what the forge said when a merge is refused - #15214

Open
ameyypawar wants to merge 1 commit into
gitbutlerapp:masterfrom
ameyypawar:fix/8403-forge-error-body
Open

Report what the forge said when a merge is refused#15214
ameyypawar wants to merge 1 commit into
gitbutlerapp:masterfrom
ameyypawar:fix/8403-forge-error-body

Conversation

@ameyypawar

Copy link
Copy Markdown
Contributor

🧠 Changes

merge_pull_request now reports what GitHub said, not just the status it said it with, by using response_error() — the helper the rest of the client already reaches for, including update_pull_request ten lines above it.

response_error() in turn surfaces GitHub's message rather than the whole JSON object, so a toast reads 405 Method Not Allowed: <sentence> instead of that sentence buried between documentation_url and status. Bodies carrying errors are passed through whole, since that array is the part of a validation failure worth reading and message is only its headline.

GitLab's merge_merge_request had the same gap, in a file that already spells {status} - {error_text} at five other sites. One line.

☕️ Reasoning

Merging with a method the repository has disabled fails today with nothing to act on. #8403 describes it as two problems stacked: the picker offers all three methods because nothing fetches allow_merge_commit / allow_squash_merge / allow_rebase_merge, and the rejection that follows is reduced to a status code. This is the second one. The first is UI work tracked separately in #8654, and greying options out is easier to judge once the failure is legible.

The change is small because the intent was already there: response_error()'s own doc comment says "so GitHub's error message reaches the user", four sites in stacks.rs use it, and #15212 is adding seven more. merge_pull_request was the one that missed it.

Three things this deliberately does not do:

  • response_error() itself stays uncovered. Reaching it needs a real reqwest::Response, and there is no mock-HTTP anywhere in the workspace; extracting a one-line format! purely to test it seemed worse than the gap. What it delegates to is tested, fallbacks included.
  • The five remaining response.status() sites in client.rs are untouched, keeping this a bug fix rather than a sweep. Happy to convert them in one go if you would prefer that.
  • Error text now reaches the telemetry showError sends. Preferring message narrows what that carries compared with raw bodies, which is part of why errors is a carve-out rather than the general rule.

I have not reproduced a 405 against a repository with the method disabled, so the exact wording GitHub uses is taken from the issue rather than something I have seen. Nothing in the change depends on it.

🎫 Affected issues

Addresses: #8403

Merging with a method the repository has disabled failed with only a status
code, leaving nothing to act on. The GitHub client's merge path now uses
`response_error()`, the helper the rest of the client already reaches for, and
that helper surfaces GitHub's `message` rather than the whole JSON object.
Bodies carrying `errors` are passed through whole, since that array is the part
of a validation failure worth reading.

GitLab's merge path had the same gap, in a file that already includes the body
at five other sites.
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