Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

merge: preserve current upstream PR matching and reopen behavior

Tinf37b77617c28
diff --cc apps/api/src/plugins/github/services/task-service.ts
index 2029003b1,7d49daa2c..49629b801
--- a/apps/api/src/plugins/github/services/task-service.ts
+++ b/apps/api/src/plugins/github/services/task-service.ts
@@@ -7,9 -7,8 +7,10 @@@ import
taskTable,
} from "../../../database/schema";
import { type GitHubConfig, hasVerifiedGitHubBinding } from "../config";
+ import { extractTaskLinks } from "../utils/task-references";
+import type { IntegrationDatabase } from "./integration-task-scope";
+
export type TaskRow = InferSelectModel<typeof taskTable>;
export type UpdateTaskStatusResult =
diff --cc apps/api/src/plugins/github/webhooks/issue-reopened.ts
index f61295c05,ffc08b920..11e76dbf6
--- a/apps/api/src/plugins/github/webhooks/issue-reopened.ts
+++ b/apps/api/src/plugins/github/webhooks/issue-reopened.ts
@@@ -49,64 -45,54 +49,67 @@@ export async function handleIssueReopen
continue;
}
- const task = await db.query.taskTable.findFirst({
- where: eq(taskTable.id, externalLink.taskId),
- });
+ await withIntegrationTask(
+ externalLink.taskId,
+ integration,
+ async (db, afterCommit) => {
+ const task = await db.query.taskTable.findFirst({
+ where: linkedTaskScope(externalLink.taskId, integration.projectId),
+ });
- if (!task) {
- continue;
- }
+ if (!task) {
+ return;
+ }
- const existingMetadata = parseLinkMetadata(externalLink.metadata, {
- externalLinkId: externalLink.id,
- source: "issue_reopened",
- });
+ const existingMetadata = parseLinkMetadata(externalLink.metadata, {
+ externalLinkId: externalLink.id,
+ source: "issue_reopened",
+ });
- if (existingMetadata.createdFrom === "kaneo") {
- if (
- existingMetadata.createdFrom === "kaneo" ||
- existingMetadata.state === "open"
- ) {
- continue;
- }
++ if (
++ existingMetadata.createdFrom === "kaneo" ||
++ existingMetadata.state === "open"
++ ) {
+ return;
+ }
- const targetStatus = await resolveTargetStatus(
- task.projectId,
- "issue_reopened",
- "to-do",
- );
+ const targetStatus = await resolveTargetStatus(
+ task.projectId,
+ "issue_reopened",
+ "to-do",
+ db,
+ );
- const statusResult = await updateTaskStatus(task.id, targetStatus);
- if (
- statusResult.applied &&
- statusResult.before.status !== statusResult.after.status
- ) {
- await publishEvent("task.status_changed", {
- taskId: statusResult.after.id,
- projectId: statusResult.after.projectId,
- userId: null,
- oldStatus: statusResult.before.status,
- newStatus: statusResult.after.status,
- title: statusResult.after.title,
- assigneeId: statusResult.after.userId,
- type: "status_changed",
- });
- }
+ const statusResult = await updateTaskStatus(task.id, targetStatus, db);
+ if (
+ statusResult.applied &&
+ statusResult.before.status !== statusResult.after.status
+ ) {
+ afterCommit(() =>
+ publishEvent("task.status_changed", {
+ taskId: statusResult.after.id,
+ projectId: statusResult.after.projectId,
+ userId: null,
+ oldStatus: statusResult.before.status,
+ newStatus: statusResult.after.status,
+ title: statusResult.after.title,
+ assigneeId: statusResult.after.userId,
+ type: "status_changed",
+ }),
+ );
+ }
- await updateExternalLink(externalLink.id, {
- metadata: {
- ...existingMetadata,
- state: "open",
+ await updateExternalLink(
+ externalLink.id,
+ {
+ metadata: {
+ ...existingMetadata,
+ state: "open",
+ },
+ },
+ db,
+ );
},
- });
+ );
}
}
diff --cc tests/api/plugins/github/issue-reopened.test.ts
index 5f0373c47,a65535a44..e80dc3442
--- a/tests/api/plugins/github/issue-reopened.test.ts
+++ b/tests/api/plugins/github/issue-reopened.test.ts
@@@ -96,33 -88,14 +96,44 @@@ it("retains the Kaneo-origin skip rule
expect(m.update).not.toHaveBeenCalled();
expect(m.status).not.toHaveBeenCalled();
});
+
+// Ownership locking is covered by integration-task-scope.test.ts. These cases
+// exercise provider behavior with the transaction's existing database mock.
+vi.mock(
+ "../../../../apps/api/src/plugins/github/services/integration-task-scope",
+ async (importOriginal) => {
+ const actual =
+ await importOriginal<
+ typeof import("../../../../apps/api/src/plugins/github/services/integration-task-scope")
+ >();
+ return {
+ ...actual,
+ withIntegrationTask: async (
+ _taskId: string,
+ _integration: unknown,
+ apply: (
+ database: unknown,
+ afterCommit: (effect: () => Promise<void>) => void,
+ ) => Promise<unknown>,
+ ) => {
+ const database = (await import("../../../../apps/api/src/database"))
+ .default;
+ const effects: Array<() => Promise<void>> = [];
+ const result = await apply(database, (effect) => effects.push(effect));
+ for (const effect of effects) await effect();
+ return result;
+ },
+ };
+ },
+);
+ it("skips a reopen that Kaneo already applied", async () => {
+ m.find.mockResolvedValue([{ id: "integration-1" }]);
+ m.links.mockResolvedValue({
+ id: "first",
+ taskId: "task",
+ metadata: '{"state":"open"}',
+ });
+ await handleIssueReopened(payload);
+ expect(m.update).not.toHaveBeenCalled();
+ expect(m.status).not.toHaveBeenCalled();
+ });