gitea plugin seeds default templates on board create and update

This commit is contained in:
2026-03-21 22:44:48 +02:00
parent 949c1331af
commit a8eb6ba03e

View File

@@ -87,6 +87,34 @@ async function fetchReleases(url, repoFullName, token) {
})); }));
} }
const DEFAULT_TEMPLATES = [
{
name: "Bug Report", isDefault: true, position: 0,
fields: [
{ key: "steps_to_reproduce", label: "Steps to reproduce", type: "textarea", required: true, placeholder: "1. Go to...\n2. Click on...\n3. See error" },
{ key: "expected_behavior", label: "Expected behavior", type: "textarea", required: true },
{ key: "actual_behavior", label: "Actual behavior", type: "textarea", required: true },
],
},
{
name: "Feature Request", isDefault: false, position: 1,
fields: [
{ key: "use_case", label: "Use case", type: "textarea", required: true, placeholder: "What problem would this solve?" },
{ key: "proposed_solution", label: "Proposed solution", type: "textarea", required: true },
],
},
];
async function seedTemplates(prisma, boardId) {
const existing = await prisma.boardTemplate.count({ where: { boardId } });
if (existing > 0) return;
await prisma.boardTemplate.createMany({
data: DEFAULT_TEMPLATES.map((t) => ({
boardId, name: t.name, fields: t.fields, isDefault: t.isDefault, position: t.position,
})),
}).catch(() => {});
}
function parseProfileUrl(raw) { function parseProfileUrl(raw) {
const clean = String(raw).replace(/\/+$/, ""); const clean = String(raw).replace(/\/+$/, "");
const parts = clean.split("/"); const parts = clean.split("/");
@@ -127,6 +155,7 @@ async function syncRepos(ctx) {
where: { slug }, where: { slug },
data: { externalUrl: repo.htmlUrl, description: repo.description || board.description }, data: { externalUrl: repo.htmlUrl, description: repo.description || board.description },
}); });
await seedTemplates(ctx.prisma, board.id);
updated++; updated++;
} else { } else {
const name = titleCase(repo.name); const name = titleCase(repo.name);
@@ -143,6 +172,7 @@ async function syncRepos(ctx) {
iconColor, iconColor,
}, },
}); });
await seedTemplates(ctx.prisma, board.id);
created++; created++;
} }