···11+import {
22+ createExternalLink,
33+ findExternalLinkByTaskAndType,
44+} from "../../github/services/link-manager";
55+import type { PluginContext, TaskCreatedEvent } from "../../types";
66+import type { TangledConfig } from "../config";
77+import { getTangledAgent } from "../utils/atproto-agent";
88+99+export async function handleTaskCreated(
1010+ event: TaskCreatedEvent,
1111+ context: PluginContext,
1212+): Promise<void> {
1313+ const config = context.config as TangledConfig;
1414+1515+ if (!config.repoAtUri) return;
1616+1717+ const existingLink = await findExternalLinkByTaskAndType(
1818+ event.taskId,
1919+ context.integrationId,
2020+ "issue",
2121+ );
2222+2323+ if (existingLink) return;
2424+2525+ const agent = await getTangledAgent();
2626+ if (!agent) return;
2727+2828+ try {
2929+ // create the record on the pds
3030+ const result = await agent.com.atproto.repo.createRecord({
3131+ repo: agent.session?.did ?? "",
3232+ collection: "sh.tangled.repo.issue",
3333+ record: {
3434+ $type: "sh.tangled.repo.issue",
3535+ repo: config.repoAtUri,
3636+ title: event.title,
3737+ body: event.description ?? "",
3838+ createdAt: new Date().toISOString(),
3939+ },
4040+ });
4141+4242+ await createExternalLink({
4343+ taskId: event.taskId,
4444+ integrationId: context.integrationId,
4545+ resourceType: "issue",
4646+ externalId: result.data.uri,
4747+ url: result.data.uri,
4848+ title: event.title,
4949+ metadata: {
5050+ cid: result.data.cid,
5151+ state: "open", // new issues are always open
5252+ createdFrom: "kaneo",
5353+ lastOutboundStateSyncAt: Date.now(),
5454+ },
5555+ });
5656+ } catch (error) {
5757+ console.error("Failed to create Tangled issue:", error);
5858+ }
5959+}
+1-1
apps/api/src/plugins/tangled/index.ts
···11import type { IntegrationPlugin } from "../types";
22import { validateTangledConfig } from "./config";
33+import { handleTaskCreated } from "./events/task-created";
3444-export async function handleTaskCreated() {}
55export async function handleTaskStatusChanged() {}
66export async function handleTaskPriorityChanged() {}
77export async function handleTaskTitleChanged() {}