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 9a620ba2f31238f03cd28f1da5ef3838d67e4e8a 78 lines 1.7 kB view raw
1import db from "../../../database"; 2import { activityTable } from "../../../database/schema"; 3import { findExternalLink } from "../services/link-manager"; 4import { findAllIntegrationsByRepo } from "../services/task-service"; 5 6type IssueCommentCreatedPayload = { 7 action: string; 8 issue: { 9 number: number; 10 }; 11 comment: { 12 id: number; 13 body: string; 14 html_url: string; 15 user: { 16 login: string; 17 avatar_url: string; 18 } | null; 19 created_at: string; 20 }; 21 repository: { 22 owner: { login: string }; 23 name: string; 24 }; 25}; 26 27export async function handleIssueCommentCreated( 28 payload: IssueCommentCreatedPayload, 29) { 30 const { issue, comment, repository } = payload; 31 32 if (payload.action !== "created") { 33 return; 34 } 35 36 const username = comment.user?.login ?? ""; 37 if (username.endsWith("[bot]")) { 38 return; 39 } 40 41 const integrations = await findAllIntegrationsByRepo( 42 repository.owner.login, 43 repository.name, 44 ); 45 46 for (const integration of integrations) { 47 const existingLink = await findExternalLink( 48 integration.id, 49 "issue", 50 issue.number.toString(), 51 ); 52 53 if (!existingLink) { 54 continue; 55 } 56 57 await db 58 .insert(activityTable) 59 .values({ 60 taskId: existingLink.taskId, 61 type: "comment", 62 content: comment.body, 63 externalUserName: comment.user?.login ?? "Unknown", 64 externalUserAvatar: comment.user?.avatar_url ?? null, 65 externalSource: "github", 66 externalUrl: comment.html_url, 67 }) 68 .onConflictDoNothing({ 69 target: [ 70 activityTable.taskId, 71 activityTable.externalSource, 72 activityTable.externalUrl, 73 ], 74 }); 75 76 return; 77 } 78}