Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a237a79915 | ||
|
|
18ed4de9f9 | ||
|
|
4d1389c3a8 |
+21
@@ -333,6 +333,7 @@ Einzurichten unter *Mein Konto → Benachrichtigungen*, pro Konto und beliebig v
|
|||||||
| ⚠️ **Abgleich fehlgeschlagen** | Das Git-System war nicht erreichbar oder hat abgelehnt |
|
| ⚠️ **Abgleich fehlgeschlagen** | Das Git-System war nicht erreichbar oder hat abgelehnt |
|
||||||
| 🔴 **CI rot** | Der letzte Lauf auf dem Default-Branch ist fehlgeschlagen |
|
| 🔴 **CI rot** | Der letzte Lauf auf dem Default-Branch ist fehlgeschlagen |
|
||||||
| 🏷️ **Neues Release** | Ein neuer Tag oder ein neues Release ist aufgetaucht |
|
| 🏷️ **Neues Release** | Ein neuer Tag oder ein neues Release ist aufgetaucht |
|
||||||
|
| 🕸️ **Projekt steht still** | Seit längerem kein Commit — Schwelle einstellbar, Vorgabe 60 Tage |
|
||||||
|
|
||||||
### Nur bei Änderung
|
### Nur bei Änderung
|
||||||
|
|
||||||
@@ -348,6 +349,24 @@ Zwei Feinheiten:
|
|||||||
- Der Merkstand wird auch dann fortgeschrieben, wenn **kein** Ziel eingerichtet ist. Sonst
|
- Der Merkstand wird auch dann fortgeschrieben, wenn **kein** Ziel eingerichtet ist. Sonst
|
||||||
käme beim ersten eingerichteten Ziel die ganze Vergangenheit hinterher.
|
käme beim ersten eingerichteten Ziel die ganze Vergangenheit hinterher.
|
||||||
|
|
||||||
|
### Stillstand
|
||||||
|
|
||||||
|
Der einzige Anlass, der an keinem Ereignis hängt — es passiert ja gerade nichts. Deshalb
|
||||||
|
ein eigener Durchlauf, **höchstens einmal am Tag**, unabhängig vom automatischen Abgleich.
|
||||||
|
Hört niemand auf diesen Anlass, läuft die Prüfung gar nicht erst.
|
||||||
|
|
||||||
|
Maßstab ist ausschließlich der **letzte Commit** im verknüpften Repository. Das
|
||||||
|
Änderungsdatum des Projekts taugt nicht: jeder Abgleich fasst es an und würde den
|
||||||
|
Stillstand immer wieder zurücksetzen. Projekte **ohne Repository** bleiben deshalb außen
|
||||||
|
vor, ebenso fertige und archivierte.
|
||||||
|
|
||||||
|
Gemeldet wird je Projekt einmal. Erneut erst, wenn danach wieder ein Commit kam und es
|
||||||
|
seitdem wieder still geworden ist — ein Projekt, das aufwacht und wieder einschläft, meldet
|
||||||
|
sich also ein zweites Mal.
|
||||||
|
|
||||||
|
Die Schwelle setzt ein Administrator unter *Admin-Einstellungen → Stillstand* (14 Tage bis
|
||||||
|
ein Jahr). Eine Änderung wirkt sofort, nicht erst nach 24 Stunden.
|
||||||
|
|
||||||
### Zustellwege
|
### Zustellwege
|
||||||
|
|
||||||
| Weg | Details |
|
| Weg | Details |
|
||||||
@@ -466,6 +485,8 @@ Datenbank):
|
|||||||
| `auth/password` | scrypt-Rundlauf, unterschiedliches Salz, Ablageformat, Verhalten bei kaputten Hashes, Passwortregeln |
|
| `auth/password` | scrypt-Rundlauf, unterschiedliches Salz, Ablageformat, Verhalten bei kaputten Hashes, Passwortregeln |
|
||||||
| `tasks` | Berechnung des abgeleiteten Fortschritts, Spaltenreihenfolge |
|
| `tasks` | Berechnung des abgeleiteten Fortschritts, Spaltenreihenfolge |
|
||||||
| `notify/pending` | Wann eine Benachrichtigung fällig ist: neuer Fehler ja, gleicher Fehler nein; CI-Wechsel nach rot; Release erst ab dem zweiten Abgleich |
|
| `notify/pending` | Wann eine Benachrichtigung fällig ist: neuer Fehler ja, gleicher Fehler nein; CI-Wechsel nach rot; Release erst ab dem zweiten Abgleich |
|
||||||
|
| `notify/stale` | Stillstandsschwelle, keine Zweitmeldung, aber erneute Meldung nach zwischenzeitlicher Aktivität |
|
||||||
|
| `validation` | Dass jeder Anlass, den die Oberfläche anbietet, auch vom Schema akzeptiert wird — entstanden aus genau diesem Fehler |
|
||||||
|
|
||||||
**`npm run test:e2e` — Ende-zu-Ende** (Playwright, 13 Stück, rund 20 Sekunden). Läuft
|
**`npm run test:e2e` — Ende-zu-Ende** (Playwright, 13 Stück, rund 20 Sekunden). Läuft
|
||||||
gegen die gebaute Anwendung mit eigener Datenbank auf Port 3111 — also durch Middleware,
|
gegen die gebaute Anwendung mit eigener Datenbank auf Port 3111 — also durch Middleware,
|
||||||
|
|||||||
+2
-7
@@ -11,13 +11,7 @@ Was bereits steht, listet [FEATURES.md](FEATURES.md).
|
|||||||
|
|
||||||
## 1 · Als Nächstes empfohlen
|
## 1 · Als Nächstes empfohlen
|
||||||
|
|
||||||
### 1.1 Stillstehende Projekte melden `S`
|
### 1.1 Webhooks statt Polling `M`
|
||||||
|
|
||||||
Die Benachrichtigungen decken Fehler und Releases ab. Was fehlt, ist der
|
|
||||||
sanfte Stups: „Seit 60 Tagen kein Commit". Braucht einen eigenen Durchlauf,
|
|
||||||
weil es kein Ereignis gibt, an dem es hängt — der Zeitgeber ist da.
|
|
||||||
|
|
||||||
### 1.2 Webhooks statt Polling `M`
|
|
||||||
|
|
||||||
Ein Push aktualisiert den Snapshot sofort, statt bis zum nächsten Durchlauf
|
Ein Push aktualisiert den Snapshot sofort, statt bis zum nächsten Durchlauf
|
||||||
zu warten. Braucht einen öffentlich erreichbaren Endpunkt mit
|
zu warten. Braucht einen öffentlich erreichbaren Endpunkt mit
|
||||||
@@ -117,6 +111,7 @@ Damit klar ist, was **nicht** kommt und warum:
|
|||||||
| **v0.5.0** Aufgabenbrett je Projekt mit sortierbaren Spalten, Fortschritt aus Aufgaben | ✓ |
|
| **v0.5.0** Aufgabenbrett je Projekt mit sortierbaren Spalten, Fortschritt aus Aufgaben | ✓ |
|
||||||
| **v0.6.0** Ende-zu-Ende-Tests mit Playwright, CI-Pipeline für Gitea Actions | ✓ |
|
| **v0.6.0** Ende-zu-Ende-Tests mit Playwright, CI-Pipeline für Gitea Actions | ✓ |
|
||||||
| **v0.7.0** Benachrichtigungen über ntfy, Webhook und E-Mail | ✓ |
|
| **v0.7.0** Benachrichtigungen über ntfy, Webhook und E-Mail | ✓ |
|
||||||
|
| **v0.8.0** Stillstehende Projekte melden, Schwelle im Adminbereich | ✓ |
|
||||||
|
|
||||||
Zur Entscheidung beim Export: Git-Tokens gehen **nicht** mit. Die Verbindung wird nur
|
Zur Entscheidung beim Export: Git-Tokens gehen **nicht** mit. Die Verbindung wird nur
|
||||||
beschrieben, das Token ist nach dem Import neu zu hinterlegen. Snapshots bleiben
|
beschrieben, das Token ist nach dem Import neu zu hinterlegen. Snapshots bleiben
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nebula",
|
"name": "nebula",
|
||||||
"version": "0.7.0",
|
"version": "0.8.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Nebula – Dashboard fuer Vibe-Coding Projekte mit Git-Anbindung (GitHub, GitLab, Gitea)",
|
"description": "Nebula – Dashboard fuer Vibe-Coding Projekte mit Git-Anbindung (GitHub, GitLab, Gitea)",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
-- AlterEnum
|
||||||
|
ALTER TYPE "NotificationEvent" ADD VALUE 'PROJECT_STALE';
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "AppSettings" ADD COLUMN "lastStaleCheckAt" TIMESTAMP(3),
|
||||||
|
ADD COLUMN "staleAfterDays" INTEGER NOT NULL DEFAULT 60;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Project" ADD COLUMN "notifiedStaleAt" TIMESTAMP(3);
|
||||||
@@ -48,6 +48,8 @@ enum NotificationEvent {
|
|||||||
CI_FAILED
|
CI_FAILED
|
||||||
/// Im Repository ist ein neuer Tag oder ein neues Release aufgetaucht.
|
/// Im Repository ist ein neuer Tag oder ein neues Release aufgetaucht.
|
||||||
NEW_RELEASE
|
NEW_RELEASE
|
||||||
|
/// Seit laengerem kein Commit mehr – der sanfte Stups.
|
||||||
|
PROJECT_STALE
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spalten des Aufgabenbretts innerhalb eines Projekts.
|
/// Spalten des Aufgabenbretts innerhalb eines Projekts.
|
||||||
@@ -181,6 +183,12 @@ model AppSettings {
|
|||||||
/// Kurzbericht des letzten Durchlaufs: { synced, failed, skipped, ms }
|
/// Kurzbericht des letzten Durchlaufs: { synced, failed, skipped, ms }
|
||||||
lastAutoSyncReport Json?
|
lastAutoSyncReport Json?
|
||||||
|
|
||||||
|
// ── Stillstand ─────────────────────────────────────────────
|
||||||
|
/// Ab wie vielen Tagen ohne Commit ein Projekt als stillstehend gilt.
|
||||||
|
staleAfterDays Int @default(60)
|
||||||
|
/// Die Pruefung laeuft hoechstens einmal am Tag.
|
||||||
|
lastStaleCheckAt DateTime?
|
||||||
|
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +281,9 @@ model Project {
|
|||||||
notifiedSyncError String?
|
notifiedSyncError String?
|
||||||
notifiedCiState String?
|
notifiedCiState String?
|
||||||
notifiedRelease String?
|
notifiedRelease String?
|
||||||
|
/// Wann zuletzt wegen Stillstands gemeldet wurde. Erneut gemeldet wird
|
||||||
|
/// erst, wenn danach wieder ein Commit kam und es dann wieder still wurde.
|
||||||
|
notifiedStaleAt DateTime?
|
||||||
|
|
||||||
notes Note[]
|
notes Note[]
|
||||||
tasks Task[]
|
tasks Task[]
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||||||
export default async function AdminPage() {
|
export default async function AdminPage() {
|
||||||
const admin = await requireAdminPage();
|
const admin = await requireAdminPage();
|
||||||
|
|
||||||
const [settings, users, eligible] = await Promise.all([
|
const [settings, users, eligible, staleListeners] = await Promise.all([
|
||||||
getAppSettings(),
|
getAppSettings(),
|
||||||
prisma.user.findMany({
|
prisma.user.findMany({
|
||||||
select: userSafeSelect,
|
select: userSafeSelect,
|
||||||
@@ -36,6 +36,9 @@ export default async function AdminPage() {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
prisma.notificationTarget.count({
|
||||||
|
where: { isActive: true, events: { has: "PROJECT_STALE" } },
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const data: AdminData = {
|
const data: AdminData = {
|
||||||
@@ -54,6 +57,11 @@ export default async function AdminPage() {
|
|||||||
lastReport: (settings.lastAutoSyncReport as AutoSyncReport | null) ?? null,
|
lastReport: (settings.lastAutoSyncReport as AutoSyncReport | null) ?? null,
|
||||||
eligible,
|
eligible,
|
||||||
},
|
},
|
||||||
|
stale: {
|
||||||
|
afterDays: settings.staleAfterDays,
|
||||||
|
lastCheckAt: settings.lastStaleCheckAt,
|
||||||
|
listeners: staleListeners,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export async function PATCH(request: Request) {
|
|||||||
autoSyncIntervalMinutes,
|
autoSyncIntervalMinutes,
|
||||||
autoSyncActiveOnly,
|
autoSyncActiveOnly,
|
||||||
autoSyncBatchSize,
|
autoSyncBatchSize,
|
||||||
|
staleAfterDays,
|
||||||
} = parsed.data;
|
} = parsed.data;
|
||||||
|
|
||||||
// Der Wechsel in den Einzelbetrieb wuerde weitere Konten aussperren –
|
// Der Wechsel in den Einzelbetrieb wuerde weitere Konten aussperren –
|
||||||
@@ -57,6 +58,11 @@ export async function PATCH(request: Request) {
|
|||||||
...(autoSyncIntervalMinutes !== undefined ? { autoSyncIntervalMinutes } : {}),
|
...(autoSyncIntervalMinutes !== undefined ? { autoSyncIntervalMinutes } : {}),
|
||||||
...(autoSyncActiveOnly !== undefined ? { autoSyncActiveOnly } : {}),
|
...(autoSyncActiveOnly !== undefined ? { autoSyncActiveOnly } : {}),
|
||||||
...(autoSyncBatchSize !== undefined ? { autoSyncBatchSize } : {}),
|
...(autoSyncBatchSize !== undefined ? { autoSyncBatchSize } : {}),
|
||||||
|
// Neue Schwelle: die Pruefung soll beim naechsten Tick greifen, nicht
|
||||||
|
// erst in 24 Stunden.
|
||||||
|
...(staleAfterDays !== undefined
|
||||||
|
? { staleAfterDays, lastStaleCheckAt: null }
|
||||||
|
: {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const settings = await prisma.appSettings.upsert({
|
const settings = await prisma.appSettings.upsert({
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
Download,
|
Download,
|
||||||
Fingerprint,
|
Fingerprint,
|
||||||
FolderGit2,
|
FolderGit2,
|
||||||
|
Hourglass,
|
||||||
Loader2,
|
Loader2,
|
||||||
Lock,
|
Lock,
|
||||||
Plus,
|
Plus,
|
||||||
@@ -67,6 +68,12 @@ export interface AdminData {
|
|||||||
/** Projekte mit Repository, die grundsaetzlich in Frage kommen. */
|
/** Projekte mit Repository, die grundsaetzlich in Frage kommen. */
|
||||||
eligible: number;
|
eligible: number;
|
||||||
};
|
};
|
||||||
|
stale: {
|
||||||
|
afterDays: number;
|
||||||
|
lastCheckAt: string | Date | null;
|
||||||
|
/** Wie viele Konten ueberhaupt auf Stillstand hoeren. */
|
||||||
|
listeners: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type Notice = { ok: boolean; text: string } | null;
|
type Notice = { ok: boolean; text: string } | null;
|
||||||
@@ -187,6 +194,7 @@ export function AdminManager({ data }: { data: AdminData }) {
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<AutoSyncSection data={data.autoSync} />
|
<AutoSyncSection data={data.autoSync} />
|
||||||
|
<StaleSection data={data.stale} />
|
||||||
|
|
||||||
{/* ── Instanz ─────────────────────────────────────── */}
|
{/* ── Instanz ─────────────────────────────────────── */}
|
||||||
<section className="glass p-5">
|
<section className="glass p-5">
|
||||||
@@ -574,6 +582,124 @@ function AutoSyncSection({ data }: { data: AdminData["autoSync"] }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STALE_OPTIONS = [14, 30, 60, 90, 180, 365];
|
||||||
|
|
||||||
|
function StaleSection({ data }: { data: AdminData["stale"] }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [days, setDays] = useState(data.afterDays);
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [notice, setNotice] = useState<Notice>(null);
|
||||||
|
|
||||||
|
async function save(value: number) {
|
||||||
|
setBusy(true);
|
||||||
|
setNotice(null);
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/admin/settings", {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ staleAfterDays: value }),
|
||||||
|
});
|
||||||
|
const body = await response.json().catch(() => ({}));
|
||||||
|
if (!response.ok) throw new Error(body.error ?? "Speichern fehlgeschlagen.");
|
||||||
|
setNotice({ ok: true, text: "Gespeichert." });
|
||||||
|
router.refresh();
|
||||||
|
} catch (caught) {
|
||||||
|
setDays(data.afterDays);
|
||||||
|
setNotice({ ok: false, text: caught instanceof Error ? caught.message : String(caught) });
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="glass p-5">
|
||||||
|
<div className="mb-4 flex items-start gap-3">
|
||||||
|
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-xl bg-amber-500/12 text-amber-300">
|
||||||
|
<Hourglass className="h-4 w-4" />
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-sm font-semibold uppercase tracking-wider text-slate-200">
|
||||||
|
Stillstand
|
||||||
|
</h2>
|
||||||
|
<p className="mt-1 max-w-xl text-sm text-slate-400">
|
||||||
|
Ab wann ein Projekt als eingeschlafen gilt. Massstab ist der letzte Commit im
|
||||||
|
verknuepften Repository – das Aenderungsdatum taugt nicht, weil jeder Abgleich
|
||||||
|
es anfasst. Projekte ohne Repository bleiben aussen vor, ebenso fertige und
|
||||||
|
archivierte.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<div>
|
||||||
|
<label className="field-label" htmlFor="stale-days">
|
||||||
|
Schwelle
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="stale-days"
|
||||||
|
className="field"
|
||||||
|
value={days}
|
||||||
|
disabled={busy}
|
||||||
|
onChange={(event) => {
|
||||||
|
const value = Number(event.target.value);
|
||||||
|
setDays(value);
|
||||||
|
void save(value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{STALE_OPTIONS.map((value) => (
|
||||||
|
<option key={value} value={value}>
|
||||||
|
nach {value} Tagen ohne Commit
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl className="grid grid-cols-2 gap-3">
|
||||||
|
<div className="glass-soft px-3 py-2.5">
|
||||||
|
<dt className="text-[11px] uppercase tracking-wider text-slate-500">
|
||||||
|
Letzte Pruefung
|
||||||
|
</dt>
|
||||||
|
<dd className="mt-1 text-sm text-slate-200" suppressHydrationWarning>
|
||||||
|
{data.lastCheckAt ? formatRelative(data.lastCheckAt) : "noch keine"}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div className="glass-soft px-3 py-2.5">
|
||||||
|
<dt className="text-[11px] uppercase tracking-wider text-slate-500">
|
||||||
|
Empfaenger
|
||||||
|
</dt>
|
||||||
|
<dd className="mt-1 text-sm tabular-nums text-slate-200">{data.listeners}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data.listeners === 0 ? (
|
||||||
|
<p className="mt-3 text-[11px] text-slate-600">
|
||||||
|
Niemand hoert derzeit auf diesen Anlass – die Pruefung laeuft dann gar nicht
|
||||||
|
erst. Einzurichten unter „Mein Konto → Benachrichtigungen“.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<p className="mt-3 text-[11px] text-slate-600">
|
||||||
|
Die Pruefung laeuft hoechstens einmal am Tag. Je Projekt wird einmal gemeldet;
|
||||||
|
erneut erst, wenn danach wieder ein Commit kam und es wieder still wurde.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{notice ? (
|
||||||
|
<p
|
||||||
|
className={cn(
|
||||||
|
"mt-3 rounded-lg border px-3 py-2 text-sm",
|
||||||
|
notice.ok
|
||||||
|
? "border-emerald-500/30 bg-emerald-500/10 text-emerald-200"
|
||||||
|
: "border-rose-500/30 bg-rose-500/10 text-rose-200",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{notice.text}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ModeCard({
|
function ModeCard({
|
||||||
active,
|
active,
|
||||||
disabled,
|
disabled,
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { daysSince, isStaleDue } from "./stale";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Entscheidung, wann ein Projekt als eingeschlafen gilt – und vor allem,
|
||||||
|
* wann es *nicht* erneut gemeldet wird.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TAG = 86_400_000;
|
||||||
|
const jetzt = new Date("2026-07-26T12:00:00Z");
|
||||||
|
const vorTagen = (tage: number) => new Date(jetzt.getTime() - tage * TAG);
|
||||||
|
/** Schwelle: 60 Tage. */
|
||||||
|
const cutoff = vorTagen(60);
|
||||||
|
|
||||||
|
describe("isStaleDue", () => {
|
||||||
|
it("meldet ein Projekt, dessen letzter Commit laenger zurueckliegt", () => {
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: null }, vorTagen(90), cutoff)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet nichts innerhalb der Frist", () => {
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: null }, vorTagen(30), cutoff)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet nichts genau an der Schwelle", () => {
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: null }, cutoff, cutoff)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet nichts ohne bekannten letzten Commit", () => {
|
||||||
|
// Ein Projekt ohne Repository oder ohne Snapshot laesst sich nicht
|
||||||
|
// beurteilen – lieber schweigen als raten.
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: null }, null, cutoff)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet dasselbe Projekt kein zweites Mal", () => {
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: vorTagen(5) }, vorTagen(90), cutoff)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet erneut, wenn zwischendurch gearbeitet wurde und es wieder still ist", () => {
|
||||||
|
// Gemeldet vor 200 Tagen, danach ein Commit vor 90 Tagen, seitdem Ruhe.
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: vorTagen(200) }, vorTagen(90), cutoff)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("meldet nicht erneut, wenn der Commit vor der letzten Meldung lag", () => {
|
||||||
|
expect(isStaleDue({ notifiedStaleAt: vorTagen(10) }, vorTagen(90), cutoff)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("daysSince", () => {
|
||||||
|
it("zaehlt volle Tage", () => {
|
||||||
|
expect(daysSince(vorTagen(60), jetzt)).toBe(60);
|
||||||
|
expect(daysSince(vorTagen(1), jetzt)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rundet angebrochene Tage ab", () => {
|
||||||
|
expect(daysSince(new Date(jetzt.getTime() - 1.9 * TAG), jetzt)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("liefert null fuer soeben", () => {
|
||||||
|
expect(daysSince(jetzt, jetzt)).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import type { Project, RepoSnapshot } from "@prisma/client";
|
||||||
|
import { APP_URL } from "@/lib/config";
|
||||||
|
import { prisma } from "@/lib/db";
|
||||||
|
import { statusOf } from "@/lib/status";
|
||||||
|
import { deliver } from "./channels";
|
||||||
|
import { EVENT_META, type NotificationMessage } from "./types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meldet Projekte, in denen laenger nichts passiert ist.
|
||||||
|
*
|
||||||
|
* Anders als die uebrigen Anlaesse haengt dieser an keinem Ereignis – es
|
||||||
|
* passiert ja gerade nichts. Deshalb ein eigener Durchlauf, hoechstens
|
||||||
|
* einmal am Tag.
|
||||||
|
*
|
||||||
|
* Massstab ist ausschliesslich der letzte Commit im verknuepften
|
||||||
|
* Repository. Das Aenderungsdatum des Projekts taugt nicht: jeder Abgleich
|
||||||
|
* fasst es an und wuerde den Stillstand immer wieder zuruecksetzen.
|
||||||
|
* Projekte ohne Repository bleiben folglich aussen vor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface StaleReport {
|
||||||
|
at: string;
|
||||||
|
checked: number;
|
||||||
|
stale: number;
|
||||||
|
notified: number;
|
||||||
|
thresholdDays: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Entscheidet, ob ein Projekt jetzt zu melden ist. */
|
||||||
|
export function isStaleDue(
|
||||||
|
project: Pick<Project, "notifiedStaleAt">,
|
||||||
|
lastCommitAt: Date | null,
|
||||||
|
cutoff: Date,
|
||||||
|
): boolean {
|
||||||
|
// Ohne bekannten letzten Commit gibt es nichts zu beurteilen.
|
||||||
|
if (!lastCommitAt) return false;
|
||||||
|
// Noch innerhalb der Frist.
|
||||||
|
if (lastCommitAt >= cutoff) return false;
|
||||||
|
// Noch nie gemeldet: jetzt.
|
||||||
|
if (!project.notifiedStaleAt) return true;
|
||||||
|
// Schon gemeldet – erneut nur, wenn danach wieder ein Commit kam und es
|
||||||
|
// seitdem wieder still geworden ist.
|
||||||
|
return lastCommitAt > project.notifiedStaleAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wie viele volle Tage seit dem letzten Commit vergangen sind. */
|
||||||
|
export function daysSince(date: Date, now: Date = new Date()): number {
|
||||||
|
return Math.floor((now.getTime() - date.getTime()) / 86_400_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function message(
|
||||||
|
project: Project,
|
||||||
|
snapshot: RepoSnapshot | null,
|
||||||
|
tage: number,
|
||||||
|
): NotificationMessage {
|
||||||
|
return {
|
||||||
|
event: "PROJECT_STALE",
|
||||||
|
title: `${EVENT_META.PROJECT_STALE.emoji} ${project.name}: seit ${tage} Tagen kein Commit`,
|
||||||
|
body:
|
||||||
|
`Der letzte Commit liegt ${tage} Tage zurueck. ` +
|
||||||
|
`Status: ${statusOf(project.status).label}. Vielleicht abschliessen oder archivieren?`,
|
||||||
|
priority: "normal",
|
||||||
|
url: snapshot?.htmlUrl ?? `${APP_URL}/projects/${project.id}`,
|
||||||
|
project: { id: project.id, name: project.name, slug: project.slug },
|
||||||
|
at: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Durchlauf. Meldet je Projekt hoechstens einmal und schreibt den
|
||||||
|
* Merkstand fort – auch dann, wenn niemand zuhoert.
|
||||||
|
*/
|
||||||
|
export async function runStaleCheck(thresholdDays: number): Promise<StaleReport> {
|
||||||
|
const now = new Date();
|
||||||
|
const cutoff = new Date(now.getTime() - thresholdDays * 86_400_000);
|
||||||
|
|
||||||
|
const kandidaten = await prisma.project.findMany({
|
||||||
|
where: {
|
||||||
|
// Fertige und archivierte Projekte duerfen ruhen.
|
||||||
|
status: { notIn: ["DONE", "ARCHIVED"] },
|
||||||
|
ownerId: { not: null },
|
||||||
|
snapshot: { isNot: null },
|
||||||
|
},
|
||||||
|
include: { snapshot: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const faellig = kandidaten.filter((project) =>
|
||||||
|
isStaleDue(project, project.snapshot?.lastCommitAt ?? null, cutoff),
|
||||||
|
);
|
||||||
|
|
||||||
|
let zugestellt = 0;
|
||||||
|
|
||||||
|
for (const project of faellig) {
|
||||||
|
const lastCommitAt = project.snapshot?.lastCommitAt;
|
||||||
|
if (!lastCommitAt || !project.ownerId) continue;
|
||||||
|
|
||||||
|
const ziele = await prisma.notificationTarget.findMany({
|
||||||
|
where: { userId: project.ownerId, isActive: true, events: { has: "PROJECT_STALE" } },
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const ziel of ziele) {
|
||||||
|
const ergebnis = await deliver(
|
||||||
|
ziel,
|
||||||
|
message(project, project.snapshot, daysSince(lastCommitAt, now)),
|
||||||
|
);
|
||||||
|
zugestellt += 1;
|
||||||
|
await prisma.notificationTarget.update({
|
||||||
|
where: { id: ziel.id },
|
||||||
|
data: { lastSentAt: now, lastOk: ergebnis.ok, lastMessage: ergebnis.message },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auch ohne Ziel vermerken, sonst kaeme beim ersten eingerichteten Ziel
|
||||||
|
// die gesamte Vergangenheit hinterher.
|
||||||
|
await prisma.project.update({
|
||||||
|
where: { id: project.id },
|
||||||
|
data: { notifiedStaleAt: now },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
at: now.toISOString(),
|
||||||
|
checked: kandidaten.length,
|
||||||
|
stale: faellig.length,
|
||||||
|
notified: zugestellt,
|
||||||
|
thresholdDays,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ export const NOTIFICATION_EVENTS: NotificationEvent[] = [
|
|||||||
"SYNC_FAILED",
|
"SYNC_FAILED",
|
||||||
"CI_FAILED",
|
"CI_FAILED",
|
||||||
"NEW_RELEASE",
|
"NEW_RELEASE",
|
||||||
|
"PROJECT_STALE",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const EVENT_META: Record<
|
export const EVENT_META: Record<
|
||||||
@@ -26,6 +27,11 @@ export const EVENT_META: Record<
|
|||||||
description: "Im Repository ist ein neuer Tag oder ein Release aufgetaucht.",
|
description: "Im Repository ist ein neuer Tag oder ein Release aufgetaucht.",
|
||||||
emoji: "🏷️",
|
emoji: "🏷️",
|
||||||
},
|
},
|
||||||
|
PROJECT_STALE: {
|
||||||
|
label: "Projekt steht still",
|
||||||
|
description: "Seit laengerem kein Commit mehr. Die Schwelle setzt ein Administrator.",
|
||||||
|
emoji: "🕸️",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Eine fertig formulierte Nachricht, unabhaengig vom Zustellweg. */
|
/** Eine fertig formulierte Nachricht, unabhaengig vom Zustellweg. */
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Prisma } from "@prisma/client";
|
import type { Prisma } from "@prisma/client";
|
||||||
import { getAppSettings } from "@/lib/auth/settings";
|
import { getAppSettings } from "@/lib/auth/settings";
|
||||||
import { prisma } from "@/lib/db";
|
import { prisma } from "@/lib/db";
|
||||||
|
import { runStaleCheck } from "@/lib/notify/stale";
|
||||||
import { syncProject } from "@/lib/sync";
|
import { syncProject } from "@/lib/sync";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,6 +21,8 @@ import { syncProject } from "@/lib/sync";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const TICK_MS = 60_000;
|
const TICK_MS = 60_000;
|
||||||
|
/** Stillstand aendert sich langsam – einmal am Tag genuegt. */
|
||||||
|
const STALE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
||||||
/** Kleine Verschnaufpause zwischen zwei Projekten. */
|
/** Kleine Verschnaufpause zwischen zwei Projekten. */
|
||||||
const PAUSE_MS = 400;
|
const PAUSE_MS = 400;
|
||||||
/** Hoechstens so lange wird nach Fehlschlaegen zurueckgehalten. */
|
/** Hoechstens so lange wird nach Fehlschlaegen zurueckgehalten. */
|
||||||
@@ -64,18 +67,54 @@ export function startAutoSyncScheduler() {
|
|||||||
async function tick() {
|
async function tick() {
|
||||||
try {
|
try {
|
||||||
const settings = await getAppSettings();
|
const settings = await getAppSettings();
|
||||||
if (!settings.autoSyncEnabled) return;
|
|
||||||
|
|
||||||
const intervalMs = Math.max(5, settings.autoSyncIntervalMinutes) * 60_000;
|
if (settings.autoSyncEnabled) {
|
||||||
const last = settings.lastAutoSyncAt?.getTime() ?? 0;
|
const intervalMs = Math.max(5, settings.autoSyncIntervalMinutes) * 60_000;
|
||||||
if (Date.now() - last < intervalMs) return;
|
const last = settings.lastAutoSyncAt?.getTime() ?? 0;
|
||||||
|
if (Date.now() - last >= intervalMs) {
|
||||||
|
await runAutoSyncPass("zeitplan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await runAutoSyncPass("zeitplan");
|
// Unabhaengig vom Abgleich: der Stillstand ergibt sich aus dem
|
||||||
|
// gespeicherten Stand, dafuer muss nichts geholt werden.
|
||||||
|
await maybeCheckStale();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[nebula] Automatischer Abgleich fehlgeschlagen:", error);
|
console.error("[nebula] Automatischer Abgleich fehlgeschlagen:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stillstandspruefung, hoechstens einmal am Tag. Laeuft nur, wenn ueberhaupt
|
||||||
|
* jemand darauf hoert – sonst waere es reine Datenbanklast.
|
||||||
|
*/
|
||||||
|
async function maybeCheckStale() {
|
||||||
|
const settings = await getAppSettings();
|
||||||
|
const last = settings.lastStaleCheckAt?.getTime() ?? 0;
|
||||||
|
if (Date.now() - last < STALE_CHECK_INTERVAL_MS) return;
|
||||||
|
|
||||||
|
const zuhoerer = await prisma.notificationTarget.count({
|
||||||
|
where: { isActive: true, events: { has: "PROJECT_STALE" } },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Zeitstempel auch ohne Zuhoerer setzen, damit nicht jede Minute gezaehlt
|
||||||
|
// wird.
|
||||||
|
await prisma.appSettings.update({
|
||||||
|
where: { id: "singleton" },
|
||||||
|
data: { lastStaleCheckAt: new Date() },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (zuhoerer === 0) return;
|
||||||
|
|
||||||
|
const report = await runStaleCheck(Math.max(1, settings.staleAfterDays));
|
||||||
|
if (report.stale > 0) {
|
||||||
|
console.log(
|
||||||
|
`[nebula] Stillstand: ${report.stale} von ${report.checked} Projekten ` +
|
||||||
|
`ueber ${report.thresholdDays} Tage ohne Commit, ${report.notified} Meldungen.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ein Durchlauf. Laeuft nie zweimal gleichzeitig – ein zweiter Aufruf
|
* Ein Durchlauf. Laeuft nie zweimal gleichzeitig – ein zweiter Aufruf
|
||||||
* waehrend eines laufenden Durchlaufs bekommt null zurueck.
|
* waehrend eines laufenden Durchlaufs bekommt null zurueck.
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { NOTIFICATION_EVENTS } from "@/lib/notify/types";
|
||||||
|
import { notificationTargetCreateSchema } from "./validation";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dieser Test entstand aus einem Fehler: beim Ergaenzen eines neuen
|
||||||
|
* Anlasses war das Zod-Schema nicht mitgezogen worden, die API lehnte ihn
|
||||||
|
* mit 422 ab. Die Liste steht an zwei Stellen – hier wird geprueft, dass
|
||||||
|
* sie zusammenpassen.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const basis = {
|
||||||
|
name: "Handy",
|
||||||
|
channel: "NTFY" as const,
|
||||||
|
target: "https://ntfy.sh/mein-thema",
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("notificationTargetCreateSchema", () => {
|
||||||
|
it("kennt jeden Anlass, den die Oberflaeche anbietet", () => {
|
||||||
|
for (const event of NOTIFICATION_EVENTS) {
|
||||||
|
const ergebnis = notificationTargetCreateSchema.safeParse({
|
||||||
|
...basis,
|
||||||
|
events: [event],
|
||||||
|
});
|
||||||
|
expect(ergebnis.success, `Anlass ${event} wird abgelehnt`).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("verlangt mindestens einen Anlass", () => {
|
||||||
|
expect(notificationTargetCreateSchema.safeParse({ ...basis, events: [] }).success).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("weist unbekannte Anlaesse ab", () => {
|
||||||
|
expect(
|
||||||
|
notificationTargetCreateSchema.safeParse({ ...basis, events: ["WAS_AUCH_IMMER"] })
|
||||||
|
.success,
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("verlangt bei E-Mail eine Adresse, keine URL", () => {
|
||||||
|
const alsUrl = notificationTargetCreateSchema.safeParse({
|
||||||
|
name: "Post",
|
||||||
|
channel: "EMAIL",
|
||||||
|
target: "https://example.com",
|
||||||
|
events: ["SYNC_FAILED"],
|
||||||
|
});
|
||||||
|
expect(alsUrl.success).toBe(false);
|
||||||
|
|
||||||
|
const alsAdresse = notificationTargetCreateSchema.safeParse({
|
||||||
|
name: "Post",
|
||||||
|
channel: "EMAIL",
|
||||||
|
target: "ich@example.com",
|
||||||
|
events: ["SYNC_FAILED"],
|
||||||
|
});
|
||||||
|
expect(alsAdresse.success).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("verlangt bei Webhook und ntfy eine http-URL", () => {
|
||||||
|
for (const channel of ["WEBHOOK", "NTFY"] as const) {
|
||||||
|
expect(
|
||||||
|
notificationTargetCreateSchema.safeParse({
|
||||||
|
name: "X",
|
||||||
|
channel,
|
||||||
|
target: "ich@example.com",
|
||||||
|
events: ["SYNC_FAILED"],
|
||||||
|
}).success,
|
||||||
|
).toBe(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -146,6 +146,8 @@ export const profileUpdateSchema = z.object({
|
|||||||
export const adminSettingsSchema = z.object({
|
export const adminSettingsSchema = z.object({
|
||||||
mode: z.enum(["SINGLE_USER", "MULTI_USER"]).optional(),
|
mode: z.enum(["SINGLE_USER", "MULTI_USER"]).optional(),
|
||||||
allowRegistration: z.boolean().optional(),
|
allowRegistration: z.boolean().optional(),
|
||||||
|
/** Ab wie vielen Tagen ohne Commit ein Projekt als stillstehend gilt. */
|
||||||
|
staleAfterDays: z.coerce.number().int().min(7).max(365).optional(),
|
||||||
autoSyncEnabled: z.boolean().optional(),
|
autoSyncEnabled: z.boolean().optional(),
|
||||||
/** Untergrenze 5 Minuten – haeufiger waere den Git-APIs gegenueber unfair. */
|
/** Untergrenze 5 Minuten – haeufiger waere den Git-APIs gegenueber unfair. */
|
||||||
autoSyncIntervalMinutes: z.coerce.number().int().min(5).max(10080).optional(),
|
autoSyncIntervalMinutes: z.coerce.number().int().min(5).max(10080).optional(),
|
||||||
@@ -173,7 +175,7 @@ export const adminUserUpdateSchema = z.object({
|
|||||||
// ── Benachrichtigungen ───────────────────────────────────────
|
// ── Benachrichtigungen ───────────────────────────────────────
|
||||||
|
|
||||||
const CHANNELS = ["WEBHOOK", "NTFY", "EMAIL"] as const;
|
const CHANNELS = ["WEBHOOK", "NTFY", "EMAIL"] as const;
|
||||||
const EVENTS = ["SYNC_FAILED", "CI_FAILED", "NEW_RELEASE"] as const;
|
const EVENTS = ["SYNC_FAILED", "CI_FAILED", "NEW_RELEASE", "PROJECT_STALE"] as const;
|
||||||
|
|
||||||
export const notificationTargetCreateSchema = z
|
export const notificationTargetCreateSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user