Merge pull request 'PEP-146: повторное нажатие кнопки не даёт ошибку' (#134) from task/pep-146 into main

This commit is contained in:
peppa-bot 2026-11-16 13:01:46 +05:00
commit feab7e8536
6 changed files with 26 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
import { FormButton } from "./form-button";
const buttonVariants = cva(
"inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md border border-transparent text-sm font-medium transition-colors outline-none hover:no-underline focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 cursor-pointer",
@ -35,7 +36,7 @@ function Button({
asChild = false,
...props
}: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & { asChild?: boolean }) {
const Comp = asChild ? Slot : "button";
const Comp = asChild ? Slot : FormButton;
return <Comp data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} />;
}

View File

@ -0,0 +1,16 @@
"use client";
import * as React from "react";
import { useFormStatus } from "react-dom";
/**
* PEP-146: the <button> behind every `Button`. While the server action of its form is running
* it cannot be pressed again — a second click used to send the same form twice and the second
* request answered with an error («уже занят», «уже обновляется»). Outside a form, and for
* `type="button"`, nothing changes.
*/
export function FormButton({ disabled, type, ...props }: React.ComponentProps<"button">) {
const { pending } = useFormStatus();
const busy = pending && type !== "button";
return <button type={type} disabled={disabled || busy} aria-busy={busy || undefined} {...props} />;
}

View File

@ -170,7 +170,9 @@ export async function deployProd(db: Db, project: Project, by: string, client?:
.from(releases)
.where(and(eq(releases.projectId, project.id), eq(releases.env, "prod"), eq(releases.status, "deploying")))
.limit(1);
if (running) throw new PeppaError(m("{project}: рабочая версия уже обновляется ({sha})", { project: project.key, sha: short(running.sha) }));
// PEP-146: a second press of «Показать всем» while the update is on its way is not an error —
// the person gets the update that is already running.
if (running) return running;
// Tasks since the last prod release: every healthy staging release after it.
const since = await db
.select()

View File

@ -141,7 +141,6 @@ export const runner: Dict = {
"🚀 {project} в проде: {sha}{host}": "🚀 {project} in prod: {sha}{host}",
"{project}: в версии для проверки нет работающих изменений — показывать нечего": "{project}: the version for review has no working changes — nothing to show",
"{project}: прод уже выкатывается ({sha})": "{project}: prod is already being deployed ({sha})",
"{project}: рабочая версия уже обновляется ({sha})": "{project}: the live version is already being updated ({sha})",
"Обновление рабочей версии не запущено: {error}": "The update of the live version did not start: {error}",
// Hosts

View File

@ -109,7 +109,6 @@ export const runner: Dict = {
"🚀 {project} в проде: {sha}{host}": "🚀 {project} продта: {sha}{host}",
"{project}: в версии для проверки нет работающих изменений — показывать нечего": "{project}: тексеруге арналған нұсқада жұмыс істейтін өзгерістер жоқ — көрсететін ештеңе жоқ",
"{project}: прод уже выкатывается ({sha})": "{project}: прод қазір шығарылуда ({sha})",
"{project}: рабочая версия уже обновляется ({sha})": "{project}: жұмыс нұсқасы қазір жаңартылуда ({sha})",
"Обновление рабочей версии не запущено: {error}": "Жұмыс нұсқасын жаңарту іске қосылмады: {error}",
"Хост {host} недоступен по SSH: {error}": "Хост {host} SSH арқылы қолжетімсіз: {error}",
"нет соединения": "байланыс жоқ",

View File

@ -155,7 +155,11 @@ describe("Деплой по окружениям", () => {
assert.equal(prod[0]!.status, "healthy");
assert.equal(prod[0]!.deployedBy, "mock-pm");
assert.deepEqual(prod[0]!.tasks, [`${d.p.key}-7`]);
await assert.rejects(runner.deployProd(db, d.proj, "mock-pm").then(() => runner.deployProd(db, d.proj, "mock-pm")), /уже обновляется/);
// PEP-146: a second press while the update is running is not an error — the same update comes back.
const first = await runner.deployProd(db, d.proj, "mock-pm");
const second = await runner.deployProd(db, d.proj, "mock-pm");
assert.equal(second.id, first.id, "no second update is started");
assert.equal((await releases(d.proj.id)).filter((x) => x.env === "prod" && x.status === "deploying").length, 1);
});
test("Telegram button: answering the staging message with «Выкатить в прод» starts prod", async () => {