gitea.tea/modules/task
Jan Baer 4d09587d4c
Some checks are pending
goreleaser / goreleaser (push) Waiting to run
goreleaser / release-image (push) Waiting to run
fix(pulls): report the real reason when a merge is refused (#1107)
## Problem

`tea pr merge <index>` reports the same misleading error for every refusal:

```
failed to merge PR, is it still open?
```

The PR usually *is* still open — `tea pr <index>` shows it as open and lists `Conflicting files` — so the message sends users looking in the wrong direction.

## Root cause

Gitea answers an unmergeable PR with a 405 and a body naming the actual cause. The SDK's `MergePullRequest` is built on `getStatusCode`, which returns only the status code and never calls `statusCodeToErr`, so the body is discarded. tea receives `success=false, err=nil` with no server explanation to pass on, and fell back to guessing that the PR might be closed.

## Changes

- Derive the refusal reason from the pull request when a merge fails: already merged, closed, draft, or not mergeable.
- When the PR looks mergeable but was refused anyway, name the conditions tea cannot observe (required status checks, requested reviews, branch protection) instead of guessing.
- Include the PR index in the error.
- Add table-driven tests for every reason, plus the case where the follow-up PR lookup fails.

The extra API call happens only on the failure path.

Fixes #1022

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/1107
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Jan Baer <jan.s.baer@googlemail.com>
2026-09-09 19:15:46 +00:00
..
assignees.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
issue_create.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
issue_edit.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
labels.go fix(labels): add org label for ls and pr (#1017) 2026-06-24 17:46:12 +00:00
labels_export.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_create.go feat(login): add status command (#1087) (#1105) 2026-08-28 23:55:13 +00:00
login_create_test.go Skip token uniqueness check when using SSH authentication (#898) 2026-02-19 15:19:45 +00:00
login_httpsign.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_ssh.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_status.go feat(login): add status command (#1087) (#1105) 2026-08-28 23:55:13 +00:00
login_status_test.go feat(login): add status command (#1087) (#1105) 2026-08-28 23:55:13 +00:00
milestone_create.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_checkout.go Add reply to code review (#978) 2026-06-26 21:40:31 +00:00
pull_clean.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_create.go Make tea pulls create honor --output json (#1111) 2026-09-08 19:20:40 +00:00
pull_create_test.go spdx (#581) 2023-09-08 01:40:02 +00:00
pull_edit.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
pull_merge.go fix(pulls): report the real reason when a merge is refused (#1107) 2026-09-09 19:15:46 +00:00
pull_merge_test.go fix(pulls): report the real reason when a merge is refused (#1107) 2026-09-09 19:15:46 +00:00
pull_review.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_review_comment.go Add reply to code review (#978) 2026-06-26 21:40:31 +00:00
repo_clone.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
wiki.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00
wiki_test.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00