kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import type { PluginContext, TaskCommentCreatedEvent } from "../../types";
2import type { GitHubConfig } from "../config";
3import { findExternalLinkByTaskAndType } from "../services/link-manager";
4import { getGithubApp, getInstallationIdForRepo } from "../utils/github-app";
5
6export async function handleTaskCommentCreated(
7 event: TaskCommentCreatedEvent,
8 context: PluginContext,
9): Promise<void> {
10 const githubApp = getGithubApp();
11 if (!githubApp) {
12 return;
13 }
14
15 const config = context.config as GitHubConfig;
16 const { repositoryOwner, repositoryName } = config;
17
18 const existingLink = await findExternalLinkByTaskAndType(
19 event.taskId,
20 context.integrationId,
21 "issue",
22 );
23
24 if (!existingLink) {
25 return;
26 }
27
28 try {
29 let installationId = config.installationId;
30 if (!installationId) {
31 installationId = await getInstallationIdForRepo(
32 repositoryOwner,
33 repositoryName,
34 );
35 }
36
37 const octokit = await githubApp.getInstallationOctokit(installationId);
38
39 const issueNumber = Number.parseInt(existingLink.externalId, 10);
40
41 await octokit.rest.issues.createComment({
42 owner: repositoryOwner,
43 repo: repositoryName,
44 issue_number: issueNumber,
45 body: event.comment,
46 });
47 } catch (error) {
48 console.error("Failed to create GitHub comment:", error);
49 }
50}