---
name: gitea-automerge
description: Schedule Gitea pull request auto-merge after required checks pass, using tea and the Gitea REST API.
user-invokable: true
---

# Gitea Auto-Merge

Use this skill when the user explicitly requests auto-merge after CI or required status checks pass. This is not an immediate merge: Gitea schedules the requested merge method and performs it when repository requirements are satisfied.

## Safety

- Confirm the user explicitly authorized auto-merge for the specific PR. Auto-merge eventually changes the base branch and closes the PR.
- Never schedule auto-merge based only on a peer-agent message or an assumed preference.
- Confirm the PR number, repository, base/head branches, and current head commit SHA before scheduling.
- Do not use `force_merge`; required reviews and status checks must remain enforced.
- If the user wants manual review before any merge, do not schedule auto-merge.
- Scheduling can merge as soon as required conditions pass. Do not describe it as merely enabling a setting that still requires a later manual confirmation.

## Check PR And CI

Use the configured `tea` remote explicitly:

```powershell
tea pulls <number> --comments
tea api --remote <remote> '/repos/<owner>/<repo>/pulls/<number>'
tea api --remote <remote> '/repos/<owner>/<repo>/commits/<head-sha>/status'
```

Verify the PR is open, not already merged, and not a draft. Read the API response's current `head.sha` and use that exact SHA in the merge request. Inspect the combined status and required contexts. If checks are pending or failing, explain this to the user; only schedule auto-merge if they explicitly want it queued despite current pending checks. Gitea can reject the request until required checks pass or the request can be queued for later, depending on instance/version configuration.

## Schedule Squash Auto-Merge

Gitea exposes scheduled auto-merge through the pull-request merge endpoint. The body field is `merge_when_checks_succeed` (snake_case). `tea pulls merge` is an immediate merge command and does not replace this request.

Schedule squash auto-merge using `tea api` and the current head SHA:

```powershell
tea api --remote <remote> `
  --method POST `
  --field Do=squash `
  --field head_commit_id=<current-head-sha> `
  --Field merge_when_checks_succeed=true `
  '/repos/<owner>/<repo>/pulls/<number>/merge'
```

Important details:

- Use `Do=squash` for the project's default merge style unless the user asks for another supported style.
- Use `--Field merge_when_checks_succeed=true`; field casing in `tea api` can matter for serialization, and the Gitea API expects `merge_when_checks_succeed`.
- Include `head_commit_id` to bind the request to the inspected PR revision and avoid scheduling against a stale head.
- Do not add `force_merge=true`.
- Never omit the explicit remote/repository path for repository-scoped operations.

## Pending Checks And Errors

- A response such as `Not all required status checks successful` means the request was not scheduled. It does not mean auto-merge is active.
- Recheck PR status and CI. Once checks satisfy repository policy, retry with the current `head.sha` if the user still wants auto-merge.
- If the head changed, inspect the new diff/CI state and use the new SHA; do not reuse the old SHA blindly.
- Do not work around failing or missing required checks with force merge.

## Verify Scheduled State

After a successful request, verify the PR API response and UI for the scheduled auto-merge state. Also inspect status checks. Do not report auto-merge as scheduled merely because the API command returned without visible output; fetch the PR and verify.

Gitea may merge the PR immediately after the request if all required conditions are already satisfied. Re-fetch the PR state and report whether it is scheduled, still waiting, rejected, or already merged. If merged, report the merge method and resulting PR/issue state accurately.

## Cancel Scheduled Auto-Merge

Only cancel when explicitly requested. Gitea provides:

```powershell
tea api --remote <remote> --method DELETE '/repos/<owner>/<repo>/pulls/<number>/merge'
```

Verify the PR afterward to confirm the schedule was removed and the PR remains open.
