⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(integrations): refresh imported task details after committed pages
Tincf2b030ca56b
diff --git a/apps/api/src/github-integration/controllers/import-issues.ts b/apps/api/src/github-integration/controllers/import-issues.tsindex 1b1fb9dca..8c98ca101 100644--- a/apps/api/src/github-integration/controllers/import-issues.ts+++ b/apps/api/src/github-integration/controllers/import-issues.ts@@ -46,6 +46,7 @@ import {initialImportState,} from "../import-state";+type ImportEvent = "task.updated" | "task.labels_updated" | "comment.updated";type Transaction = Parameters<Parameters<typeof db.transaction>[0]>[0];async function resolveImportedStatus(tx: Transaction,@@ -173,6 +174,10 @@ export async function importIssues(projectId: string, runId?: string) {});}const currentRun: typeof githubImportTable.$inferSelect = run;+ const notifications = new Map<+ string,+ { type: ImportEvent; taskId: string }+ >();run = await db.transaction(async (tx) => {const [currentProject] = await tx.select()@@ -199,7 +204,18 @@ export async function importIssues(projectId: string, runId?: string) {)throw conflict();const state = structuredClone(currentRun.state);- await applyPage(tx, payload, state, integration.id, project, config);+ await applyPage(+ tx,+ payload,+ state,+ integration.id,+ project,+ config,+ (taskId, ...types) => {+ for (const type of types)+ notifications.set(`${type}:${taskId}`, { type, taskId });+ },+ );const [saved] = await tx.update(githubImportTable).set({ state })@@ -215,6 +231,8 @@ export async function importIssues(projectId: string, runId?: string) {});// Each bounded page is durable before other clients refresh, including// continuation pages that change labels, comments or linked resources.+ for (const { type, taskId } of notifications.values())+ await publishEvent(type, { projectId, taskId });await publishEvent("project.updated", { projectId });}return importProgress(run.runId, run.state);@@ -258,6 +276,7 @@ async function applyPage(integrationId: string,project: typeof projectTable.$inferSelect,config: GitHubConfig,+ announce: (taskId: string, ...types: ImportEvent[]) => void,) {if (state.phase === "issues") {const parsed = issuesPageSchema.safeParse(payload);@@ -298,6 +317,7 @@ async function applyPage(};await importLabels(tx, issue.labels.nodes, task.id, project.workspaceId);await importComments(tx, issue.comments.nodes, task.id, state.startedAt);+ announce(task.id, "task.updated", "task.labels_updated", "comment.updated");nextIssuePart(state);return;}@@ -312,7 +332,8 @@ async function applyPage(state.phase = "complete";return;}- await linkPull(tx, pull, integrationId, project, config);+ const taskId = await linkPull(tx, pull, integrationId, project, config);+ if (taskId) announce(taskId, "task.updated");}if (!page.pageInfo.hasNextPage || page.nodes.length === 0)state.phase = "complete";@@ -384,6 +405,7 @@ async function applyPage(label.name.startsWith("status:"),);await importLabels(tx, labels, task.id, project.workspaceId);+ announce(task.id, "task.updated", "task.labels_updated");nextIssuePart(state);} else if (state.phase === "comments") {const parsed = commentsPageSchema.safeParse(payload);@@ -403,6 +425,7 @@ async function applyPage();current.moreComments = page.pageInfo.hasNextPage && comments.length > 0;await importComments(tx, comments, task.id, state.startedAt);+ announce(task.id, "comment.updated");nextIssuePart(state);}}@@ -597,4 +620,5 @@ async function linkPull(author: pull.author?.login,}),});+ return task.id;}diff --git a/tests/api-integration/github-import-bounds.test.ts b/tests/api-integration/github-import-bounds.test.tsindex 4acd1b6e3..5af1751cf 100644--- a/tests/api-integration/github-import-bounds.test.ts+++ b/tests/api-integration/github-import-bounds.test.ts@@ -163,9 +163,16 @@ describe("bounded resumable GitHub import", () => {serveIssues(9);const observedCounts: number[] = [];mocks.publish.mockImplementation(async (name, payload) => {- expect(name).toBe("project.updated");- expect(payload).toEqual({ projectId: project.id });- observedCounts.push((await db.query.taskTable.findMany()).length);+ if (name === "project.updated") {+ expect(payload).toEqual({ projectId: project.id });+ observedCounts.push((await db.query.taskTable.findMany()).length);+ } else {+ expect(+ await db.query.taskTable.findFirst({+ where: eq(schema.taskTable.id, payload.taskId!),+ }),+ ).toBeDefined();+ }});const first = await request();expect(first.status).toBe(202);@@ -280,6 +287,24 @@ describe("bounded resumable GitHub import", () => {return emptyPulls();},);+ const delivered: Array<{+ name: string;+ priority?: string;+ labels: number;+ comments: number;+ }> = [];+ mocks.publish.mockImplementation(async (name, payload) => {+ if (!payload.taskId) return;+ const committed = await db.query.taskTable.findFirst({+ where: eq(schema.taskTable.id, payload.taskId),+ });+ delivered.push({+ name,+ priority: committed?.priority,+ labels: (await db.query.labelTable.findMany()).length,+ comments: (await db.query.activityTable.findMany()).length,+ });+ });let result = await importIssues(project.id);expect(result.pending).toBe(true);expect((await saved())?.state).toMatchObject({@@ -290,6 +315,16 @@ describe("bounded resumable GitHub import", () => {expect(result.pending).toBe(false);expect(await db.query.labelTable.findMany()).toHaveLength(25);expect(await db.query.activityTable.findMany()).toHaveLength(82);+ expect(delivered).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ name: "task.labels_updated",+ priority: "urgent",+ labels: 25,+ }),+ expect.objectContaining({ name: "comment.updated", comments: 82 }),+ ]),+ );expect(await db.query.taskTable.findFirst()).toMatchObject({priority: "urgent",status: "in-progress",