PEP-101: Accept compares by branch name (Gitea 1.22 404s on a SHA) and never blocks on a failed compare

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Асель 2026-11-15 14:21:29 +05:00
parent 51847e1ac1
commit 9611ab53ed
5 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,8 @@
# Proposal: PEP-101 — «Принять» с 404 на сравнении
## Why
PEP-93 сравнивал `main...<sha>`; Gitea 1.22 принимает в compare только имена веток и отвечает 404 — «Принять» ломался у всех PR проектов.
## What Changes
- Сравнение по имени ветки головы PR; ошибка сравнения не блокирует мерж.
- mock-gitea: compare с SHA → 404, как настоящая.

View File

@ -0,0 +1,8 @@
## ADDED Requirements
### Requirement: Сбой проверки «нечего мержить» не блокирует приёмку
«Принять» SHALL мержить PR, даже если сравнение веток в Gitea не удалось.
#### Scenario: Gitea не сравнила
- **WHEN** запрос сравнения веток вернул ошибку
- **THEN** PR мержится обычным путём

View File

@ -0,0 +1,2 @@
- [x] 1.1 compare по ветке, ошибка не блокирует
- [x] 1.2 мок как Gitea 1.22

View File

@ -237,9 +237,12 @@ export async function mergeTaskPr(ref: TaskRef, client?: GiteaClient): Promise<"
* one and was merged first) can't be merged — Gitea answers 405 «Please try again later». Then
* the work is in main: close the PR with a note instead. True when merged, false when closed.
*/
export async function mergeOrCloseEmpty(ref: TaskRef, pull: { number: number; head: { sha: string }; base: { ref: string } }, gitea: GiteaClient): Promise<boolean> {
export async function mergeOrCloseEmpty(ref: TaskRef, pull: { number: number; head: { sha: string; ref: string }; base: { ref: string } }, gitea: GiteaClient): Promise<boolean> {
const { giteaOwner: owner, giteaRepo: repo } = ref.project;
if ((await gitea.commitsAhead(owner, repo, pull.base.ref, pull.head.sha)) === 0) {
// PEP-101: Gitea 1.22 compares branch names only (a SHA → 404); a failed compare never blocks
// the merge — Gitea itself refuses what can't be merged.
const ahead = await gitea.commitsAhead(owner, repo, pull.base.ref, pull.head.ref).catch(() => null);
if (ahead === 0) {
await gitea.commentIssue(owner, repo, pull.number, `Все коммиты этого PR уже в \`${pull.base.ref}\` (вошли с другим PR) — закрываю без мержа. ${ref.key} принята.`).catch(() => {});
await gitea.closePullRequest(owner, repo, pull.number);
return false;

View File

@ -466,7 +466,10 @@ export class MockGitea {
return { status: 201, body: {} };
}
if (method === "GET" && (m = sub.match(/^compare\/(.+)\.\.\.(.+)$/))) {
const n = this.ahead(r, decodeURIComponent(m[1]!), decodeURIComponent(m[2]!));
// Like Gitea 1.22: branch names only — a commit SHA is "not found".
const [base, head] = [decodeURIComponent(m[1]!), decodeURIComponent(m[2]!)];
if ([base, head].some((x) => /^[0-9a-f]{40}$/.test(x))) return { status: 404, body: { message: "The target couldn't be found." } };
const n = this.ahead(r, base, head);
return { status: 200, body: { total_commits: n, commits: [], files: [] } };
}
if (method === "GET" && (m = sub.match(/^commits\/([^/]+)\/status$/))) return { status: 200, body: this.combined(r, decodeURIComponent(m[1]!)) };