diff --git a/openspec/changes/pep-101-compare-by-branch/proposal.md b/openspec/changes/pep-101-compare-by-branch/proposal.md new file mode 100644 index 00000000..c820d535 --- /dev/null +++ b/openspec/changes/pep-101-compare-by-branch/proposal.md @@ -0,0 +1,8 @@ +# Proposal: PEP-101 — «Принять» с 404 на сравнении + +## Why +PEP-93 сравнивал `main...`; Gitea 1.22 принимает в compare только имена веток и отвечает 404 — «Принять» ломался у всех PR проектов. + +## What Changes +- Сравнение по имени ветки головы PR; ошибка сравнения не блокирует мерж. +- mock-gitea: compare с SHA → 404, как настоящая. diff --git a/openspec/changes/pep-101-compare-by-branch/specs/delivery-pipeline/spec.md b/openspec/changes/pep-101-compare-by-branch/specs/delivery-pipeline/spec.md new file mode 100644 index 00000000..48808605 --- /dev/null +++ b/openspec/changes/pep-101-compare-by-branch/specs/delivery-pipeline/spec.md @@ -0,0 +1,8 @@ +## ADDED Requirements + +### Requirement: Сбой проверки «нечего мержить» не блокирует приёмку +«Принять» SHALL мержить PR, даже если сравнение веток в Gitea не удалось. + +#### Scenario: Gitea не сравнила +- **WHEN** запрос сравнения веток вернул ошибку +- **THEN** PR мержится обычным путём diff --git a/openspec/changes/pep-101-compare-by-branch/tasks.md b/openspec/changes/pep-101-compare-by-branch/tasks.md new file mode 100644 index 00000000..6dbcfe68 --- /dev/null +++ b/openspec/changes/pep-101-compare-by-branch/tasks.md @@ -0,0 +1,2 @@ +- [x] 1.1 compare по ветке, ошибка не блокирует +- [x] 1.2 мок как Gitea 1.22 diff --git a/packages/runner/src/ci-feedback.ts b/packages/runner/src/ci-feedback.ts index 6abdff00..26261f64 100644 --- a/packages/runner/src/ci-feedback.ts +++ b/packages/runner/src/ci-feedback.ts @@ -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 { +export async function mergeOrCloseEmpty(ref: TaskRef, pull: { number: number; head: { sha: string; ref: string }; base: { ref: string } }, gitea: GiteaClient): Promise { 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; diff --git a/packages/testkit/src/mock-gitea.ts b/packages/testkit/src/mock-gitea.ts index 5127db9a..16a6235c 100644 --- a/packages/testkit/src/mock-gitea.ts +++ b/packages/testkit/src/mock-gitea.ts @@ -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]!)) };