kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at cd7cada2f86b4e866a15b4323bb8d6d7ab5bba8b 67 lines 1.7 kB view raw
1import { sql } from "drizzle-orm"; 2import db from "../../../database"; 3import { labelTable } from "../../../database/schema"; 4import { 5 findAllIntegrationsByGiteaRepo, 6 repoOwnerLogin, 7} from "../services/integration-lookup"; 8import { baseUrlFromRepositoryHtmlUrl } from "../utils/webhook-repo"; 9 10/** Gitea label events include the created label; older payloads may also set ref_type */ 11type LabelCreatePayload = { 12 ref?: string; 13 ref_type?: string; 14 label?: { 15 name: string; 16 color: string; 17 description?: string | null; 18 }; 19 repository: { 20 owner: { login?: string; username?: string }; 21 name: string; 22 html_url: string; 23 }; 24}; 25 26export async function handleGiteaLabelCreated(payload: LabelCreatePayload) { 27 if ((payload.ref_type && payload.ref_type !== "label") || !payload.label) { 28 return; 29 } 30 31 const { repository, label } = payload; 32 33 const baseUrl = baseUrlFromRepositoryHtmlUrl(repository.html_url); 34 if (!baseUrl) return; 35 36 const owner = repoOwnerLogin(repository); 37 const integrations = await findAllIntegrationsByGiteaRepo( 38 baseUrl, 39 owner, 40 repository.name, 41 ); 42 43 for (const integration of integrations) { 44 if (!integration.project) { 45 continue; 46 } 47 48 const workspaceId = integration.project.workspaceId; 49 if (!workspaceId) { 50 continue; 51 } 52 53 const color = label.color ? `#${label.color.replace(/^#/, "")}` : "#6B7280"; 54 55 await db 56 .insert(labelTable) 57 .values({ 58 name: label.name, 59 color, 60 workspaceId, 61 }) 62 .onConflictDoNothing({ 63 target: [labelTable.workspaceId, labelTable.name], 64 where: sql`${labelTable.taskId} is null`, 65 }); 66 } 67}