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.

fix(planka-import): explain unmatched assignees, keep dependencies, attribute comments

Andrej15f68683620b
diff --git a/apps/api/src/activity/controllers/create-comment.ts b/apps/api/src/activity/controllers/create-comment.ts
index 035a6a728..a486913b3 100644
--- a/apps/api/src/activity/controllers/create-comment.ts
+++ b/apps/api/src/activity/controllers/create-comment.ts
@@ -11,7 +11,12 @@ import { publishEvent } from "../../events";
import createNotification from "../../notification/controllers/create-notification";
import { parseMentionIds } from "../../utils/parse-mentions";
-async function createComment(taskId: string, userId: string, content: string) {
+async function createComment(
+ taskId: string,
+ userId: string,
+ content: string,
+ external?: { userName: string; source: string },
+) {
const [activity] = await db
.insert(activityTable)
.values({
@@ -19,6 +24,12 @@ async function createComment(taskId: string, userId: string, content: string) {
type: "comment",
userId,
content,
+ ...(external
+ ? {
+ externalUserName: external.userName,
+ externalSource: external.source,
+ }
+ : {}),
})
.returning();
diff --git a/apps/api/src/comment/index.ts b/apps/api/src/comment/index.ts
index 5c5680f68..ca917a3e2 100644
--- a/apps/api/src/comment/index.ts
+++ b/apps/api/src/comment/index.ts
@@ -57,15 +57,25 @@ const comment = new Hono<{
validator("param", v.object({ taskId: v.string() })),
validator(
"json",
- v.object({ content: v.pipe(v.string(), v.minLength(1)) }),
+ v.object({
+ content: v.pipe(v.string(), v.minLength(1)),
+ externalUserName: v.optional(v.pipe(v.string(), v.maxLength(120))),
+ externalSource: v.optional(v.picklist(["planka", "trello", "jira"])),
+ }),
),
workspaceAccess.fromTaskId(),
requireWorkspacePermission({ task: ["update"] }),
async (c) => {
const { taskId } = c.req.valid("param");
- const { content } = c.req.valid("json");
+ const { content, externalUserName, externalSource } = c.req.valid("json");
const userId = c.get("userId");
- const newComment = await createComment(taskId, userId, content);
+ // Both or neither: a name without a source would render as an
+ // unattributed impersonation of a real account.
+ const external =
+ externalUserName && externalSource
+ ? { userName: externalUserName, source: externalSource }
+ : undefined;
+ const newComment = await createComment(taskId, userId, content, external);
return c.json(newComment);
},
)
diff --git a/apps/docs/core/migrations/from-planka.mdx b/apps/docs/core/migrations/from-planka.mdx
index a7475f677..3b1453822 100644
--- a/apps/docs/core/migrations/from-planka.mdx
+++ b/apps/docs/core/migrations/from-planka.mdx
@@ -82,6 +82,7 @@ passing secrets on the command line, where they end up in your shell history.
| Card | Task |
| Card description | Task description |
| Checklists | Markdown checkboxes appended to the description |
+| Checklist items linked to another card | Task relations (subtask), not text |
| Labels | Labels, with their original colors |
| Card members | Assignee, matched by email |
| Due date | Due date |
@@ -97,8 +98,10 @@ resulting Kaneo project is named `Project - Board`.
you need from PLANKA before you switch it off.
- **Archive and trash lists.** Skipped deliberately; only active and closed
lists are migrated.
-- **Comment authorship.** Kaneo attributes imported comments to the owner of the
- API key, so the original author and date are preserved in the comment body.
+- **Comment authorship.** The comment is created by the API key's owner, but the
+ original PLANKA author is recorded on it and shown in Kaneo, the same way
+ imported GitHub comments are. This needs Kaneo 2.17.6 or newer; against older
+ instances the comment still imports, just without the original author.
- **Priorities.** PLANKA has no priority field, so every task starts at
`no-priority`.
- **Custom fields, stopwatches, and card subscriptions.** No Kaneo equivalent.
diff --git a/packages/planka-import/README.md b/packages/planka-import/README.md
index 1e84241c9..ca6b550cf 100644
--- a/packages/planka-import/README.md
+++ b/packages/planka-import/README.md
@@ -37,6 +37,7 @@ Create a Kaneo API key under **Settings → API keys**. Self-hosting? Point
| Card | Task |
| Card description | Task description |
| Checklists (task lists) | Markdown checkboxes appended to the description |
+| Checklist items linked to another card | Task relations (subtask) |
| Labels | Labels, with their original colors |
| Card members | Assignee, matched by email address |
| Due date | Due date |
@@ -51,14 +52,18 @@ named `Project - Board`.
- **Attachments.** Counted and reported, but not transferred.
- **Archive and trash lists.** Skipped by design; only active and closed lists
are migrated.
-- **Comment authorship.** Kaneo attributes every imported comment to the owner
- of the API key, so the original author and date are preserved in the comment
- body instead.
+- **Comment authorship.** The comment is created by the API key's owner, but the
+ original PLANKA author is recorded and displayed alongside it. Requires Kaneo
+ 2.17.6 or newer.
- **Priorities.** PLANKA has no priority field, so every task starts at
`no-priority`.
- **Custom fields, stopwatches, and card subscriptions.** No Kaneo equivalent.
-Assignees only match when the person already exists in the target Kaneo
+**Run the import as a PLANKA admin.** PLANKA hides other users' email addresses
+from non-admin accounts, and assignees are matched by email, so a non-admin
+import leaves every task unassigned.
+
+Assignees also only match when the person already exists in the target Kaneo
workspace with the same email address. Invite your team first, then import, and
assignments come across on the first run.
diff --git a/packages/planka-import/package.json b/packages/planka-import/package.json
index 575bf16a3..12f809978 100644
--- a/packages/planka-import/package.json
+++ b/packages/planka-import/package.json
@@ -1,6 +1,6 @@
{
"name": "@kaneo/planka-import",
- "version": "0.1.2",
+ "version": "0.2.0",
"description": "Migrate PLANKA boards into Kaneo: projects, lists, cards, labels, assignees, checklists and comments, over the public APIs of both",
"license": "MIT",
"author": "Kaneo (https://kaneo.app)",
diff --git a/packages/planka-import/src/kaneo.ts b/packages/planka-import/src/kaneo.ts
index 6de65f03d..f82246a95 100644
--- a/packages/planka-import/src/kaneo.ts
+++ b/packages/planka-import/src/kaneo.ts
@@ -109,10 +109,30 @@ export class KaneoClient {
});
}
- createComment(taskId: string, content: string): Promise<unknown> {
+ createTaskRelation(input: {
+ sourceTaskId: string;
+ targetTaskId: string;
+ relationType: "subtask" | "blocks" | "related";
+ }): Promise<unknown> {
+ return this.request("/api/task-relation", {
+ method: "POST",
+ body: JSON.stringify(input),
+ });
+ }
+
+ createComment(
+ taskId: string,
+ content: string,
+ externalUserName?: string,
+ ): Promise<unknown> {
return this.request(`/api/comment/${encodeURIComponent(taskId)}`, {
method: "POST",
- body: JSON.stringify({ content }),
+ body: JSON.stringify({
+ content,
+ ...(externalUserName
+ ? { externalUserName, externalSource: "planka" }
+ : {}),
+ }),
});
}
diff --git a/packages/planka-import/src/mapping.test.ts b/packages/planka-import/src/mapping.test.ts
index ab55cdd15..b3bda65ab 100644
--- a/packages/planka-import/src/mapping.test.ts
+++ b/packages/planka-import/src/mapping.test.ts
@@ -138,7 +138,7 @@ describe("buildDescription", () => {
});
describe("formatComment", () => {
- it("preserves the original author and date", () => {
+ it("keeps the body clean and notes the original date", () => {
const result = formatComment(
{
id: "c1",
@@ -150,12 +150,10 @@ describe("formatComment", () => {
{ id: "u1", email: "[email protected]", name: "Sam", username: null },
);
- expect(result).toBe(
- "**Sam** on 2026-03-04 (imported from PLANKA)\n\nLooks good",
- );
+ expect(result).toBe("Looks good\n\n_Originally posted on 2026-03-04._");
});
- it("falls back when the author is unknown", () => {
+ it("returns the text unchanged when there is no date", () => {
const result = formatComment(
{
id: "c1",
@@ -167,7 +165,7 @@ describe("formatComment", () => {
undefined,
);
- expect(result).toBe("**Unknown user** (imported from PLANKA)\n\nOrphaned");
+ expect(result).toBe("Orphaned");
});
});
diff --git a/packages/planka-import/src/mapping.ts b/packages/planka-import/src/mapping.ts
index 2e12bfd79..0e4a54896 100644
--- a/packages/planka-import/src/mapping.ts
+++ b/packages/planka-import/src/mapping.ts
@@ -69,8 +69,10 @@ export function buildDescription(
if (description) sections.push(description);
for (const taskList of taskLists) {
+ // Items pointing at another card become task relations instead, so they
+ // are not also flattened into checkbox text.
const items = tasks
- .filter((task) => task.taskListId === taskList.id)
+ .filter((task) => task.taskListId === taskList.id && !task.linkedCardId)
.sort((a, b) => a.position - b.position);
if (items.length === 0) continue;
@@ -98,11 +100,10 @@ export function formatComment(
const date = comment.createdAt
? new Date(comment.createdAt).toISOString().slice(0, 10)
: null;
- const attribution = date
- ? `**${displayName(author)}** on ${date} (imported from PLANKA)`
- : `**${displayName(author)}** (imported from PLANKA)`;
- return `${attribution}\n\n${comment.text}`;
+ return date
+ ? `${comment.text}\n\n_Originally posted on ${date}._`
+ : comment.text;
}
/** PLANKA has no priority field; Kaneo requires one on create. */
diff --git a/packages/planka-import/src/migrate.test.ts b/packages/planka-import/src/migrate.test.ts
index 1751ee352..010df2c4a 100644
--- a/packages/planka-import/src/migrate.test.ts
+++ b/packages/planka-import/src/migrate.test.ts
@@ -48,8 +48,16 @@ function fakeKaneo(calls: Call[]) {
record("createLabel", input);
return { id: "l_1", name: "l", color: "#000000" };
},
- async createComment(taskId: string, content: string) {
- record("createComment", taskId, content);
+ async createTaskRelation(input: unknown) {
+ record("createTaskRelation", input);
+ return {};
+ },
+ async createComment(
+ taskId: string,
+ content: string,
+ externalUserName?: string,
+ ) {
+ record("createComment", taskId, content, externalUserName);
return {};
},
} as unknown as KaneoClient;
@@ -368,4 +376,130 @@ describe("migrate (write)", () => {
expect(reports[0]?.failed).toBe(true);
expect(reports[0]?.error).toBe("boom");
});
+
+ it("warns when PLANKA hid the assignee email instead of failing silently", async () => {
+ const calls: Call[] = [];
+ const [report] = await migrate({
+ planka: fakePlanka(
+ bundleWith({
+ cardMemberships: [{ cardId: "card1", userId: "pu1" }],
+ users: [{ id: "pu1", email: null, name: "Hidden", username: null }],
+ }),
+ ),
+ kaneo: fakeKaneo(calls),
+ workspaceId: "ws_1",
+ targets: [target],
+ dryRun: false,
+ skipComments: false,
+ });
+
+ expect(report?.assignees).toBe(0);
+ expect(report?.warnings.join(" ")).toContain("PLANKA admin account");
+ });
+
+ it("warns when the assignee is not in the target workspace", async () => {
+ const calls: Call[] = [];
+ const [report] = await migrate({
+ planka: fakePlanka(
+ bundleWith({
+ cardMemberships: [{ cardId: "card1", userId: "pu9" }],
+ users: [
+ {
+ id: "pu9",
+ email: "[email protected]",
+ name: "Outsider",
+ username: null,
+ },
+ ],
+ }),
+ ),
+ kaneo: fakeKaneo(calls),
+ workspaceId: "ws_1",
+ targets: [target],
+ dryRun: false,
+ skipComments: false,
+ });
+
+ expect(report?.warnings.join(" ")).toContain("Invite those people");
+ });
+
+ it("turns a linked checklist item into a task relation, not checkbox text", async () => {
+ const calls: Call[] = [];
+ const bundle = bundleWith({
+ taskLists: [{ id: "tl1", cardId: "card1", name: "Depends on" }],
+ tasks: [
+ {
+ id: "t1",
+ taskListId: "tl1",
+ name: "Blocked by card 2",
+ isCompleted: false,
+ position: 1,
+ linkedCardId: "card2",
+ },
+ ],
+ });
+ bundle.included.cards?.push({
+ id: "card2",
+ boardId: "b1",
+ listId: "l1",
+ name: "The dependency",
+ description: null,
+ position: 2,
+ dueDate: null,
+ isDueCompleted: null,
+ isClosed: null,
+ commentsTotal: 0,
+ });
+
+ const [report] = await migrate({
+ planka: fakePlanka(bundle),
+ kaneo: fakeKaneo(calls),
+ workspaceId: "ws_1",
+ targets: [target],
+ dryRun: false,
+ skipComments: false,
+ });
+
+ const relations = calls
+ .filter((call) => call.method === "createTaskRelation")
+ .map((call) => call.args[0]);
+ expect(relations).toEqual([
+ { sourceTaskId: "t_1", targetTaskId: "t_2", relationType: "subtask" },
+ ]);
+ expect(report?.relations).toBe(1);
+
+ const descriptions = calls
+ .filter((call) => call.method === "createTask")
+ .map((call) => (call.args[0] as { description: string }).description);
+ expect(descriptions.join(" ")).not.toContain("Blocked by card 2");
+ });
+
+ it("attributes imported comments to the original PLANKA author", async () => {
+ const calls: Call[] = [];
+ const bundle = bundleWith({
+ users: [{ id: "pu1", email: null, name: "Sam", username: null }],
+ });
+ const [firstCard] = bundle.included.cards ?? [];
+ if (firstCard) firstCard.commentsTotal = 1;
+
+ await migrate({
+ planka: fakePlanka(bundle, [
+ {
+ id: "cm1",
+ cardId: "card1",
+ userId: "pu1",
+ text: "Looks good",
+ createdAt: "2026-03-04T10:00:00.000Z",
+ },
+ ]),
+ kaneo: fakeKaneo(calls),
+ workspaceId: "ws_1",
+ targets: [target],
+ dryRun: false,
+ skipComments: false,
+ });
+
+ const comment = calls.find((call) => call.method === "createComment");
+ expect(comment?.args[2]).toBe("Sam");
+ });
});
diff --git a/packages/planka-import/src/migrate.ts b/packages/planka-import/src/migrate.ts
index 530813c48..9dea643b9 100644
--- a/packages/planka-import/src/migrate.ts
+++ b/packages/planka-import/src/migrate.ts
@@ -5,6 +5,7 @@ import {
boardProjectName,
buildDescription,
DEFAULT_PRIORITY,
+ displayName,
formatComment,
planColumns,
sortCards,
@@ -36,6 +37,7 @@ export type BoardReport = {
comments: number;
assignees: number;
checklistItems: number;
+ relations: number;
skippedLists: string[];
skippedAttachments: number;
warnings: string[];
@@ -100,6 +102,7 @@ export async function migrate(options: MigrateOptions): Promise<BoardReport[]> {
comments: 0,
assignees: 0,
checklistItems: 0,
+ relations: 0,
skippedLists: [],
skippedAttachments: 0,
warnings: [],
@@ -256,6 +259,10 @@ async function migrateBoard(context: {
labelIdByPlankaId.set(label.id, { name, color });
}
+ const taskIdByCardId = new Map<string, string>();
+ let noEmailFromPlanka = 0;
+ let notAWorkspaceMember = 0;
+
let taskIndex = 0;
for (const card of cards) {
taskIndex++;
@@ -269,13 +276,19 @@ async function migrateBoard(context: {
const cardChecklists = taskLists.filter((tl) => tl.cardId === card.id);
const description = buildDescription(card, cardChecklists, checklistItems);
- const assigneeId = resolveAssignee(
+ const assignee = resolveAssignee(
card.id,
cardMemberships,
usersById,
membersByEmail,
);
- if (assigneeId) report.assignees++;
+ if (assignee.userId) {
+ report.assignees++;
+ } else if (assignee.reason === "no_email") {
+ noEmailFromPlanka++;
+ } else if (assignee.reason === "not_a_member") {
+ notAWorkspaceMember++;
+ }
const dueDate = toDueDate(card);
@@ -285,9 +298,11 @@ async function migrateBoard(context: {
status,
priority: DEFAULT_PRIORITY,
...(dueDate ? { dueDate } : {}),
- ...(assigneeId ? { userId: assigneeId } : {}),
+ ...(assignee.userId ? { userId: assignee.userId } : {}),
});
+ taskIdByCardId.set(card.id, task.id);
+
for (const link of cardLabels) {
if (link.cardId !== card.id) continue;
const label = labelIdByPlankaId.get(link.labelId);
@@ -308,28 +323,85 @@ async function migrateBoard(context: {
for (const comment of comments) {
const author = comment.userId ? usersById.get(comment.userId) : undefined;
- await kaneo.createComment(task.id, formatComment(comment, author));
+ await kaneo.createComment(
+ task.id,
+ formatComment(comment, author),
+ displayName(author),
+ );
report.comments++;
}
}
+
+ // Relations need every task to exist first, so they run after the card loop.
+ for (const item of checklistItems) {
+ if (!item.linkedCardId) continue;
+
+ const parentCardId = taskLists.find(
+ (list) => list.id === item.taskListId,
+ )?.cardId;
+ if (!parentCardId) continue;
+
+ const sourceTaskId = taskIdByCardId.get(parentCardId);
+ const targetTaskId = taskIdByCardId.get(item.linkedCardId);
+ if (!sourceTaskId || !targetTaskId || sourceTaskId === targetTaskId) {
+ continue;
+ }
+
+ try {
+ await kaneo.createTaskRelation({
+ sourceTaskId,
+ targetTaskId,
+ relationType: "subtask",
+ });
+ report.relations++;
+ } catch (error) {
+ report.warnings.push(
+ `Could not link "${item.name}" as a subtask: ${
+ error instanceof Error ? error.message : String(error)
+ }`,
+ );
+ }
+ }
+
+ if (noEmailFromPlanka > 0) {
+ report.warnings.push(
+ `${noEmailFromPlanka} card assignment(s) were skipped because PLANKA did not return an email for those users. PLANKA only exposes email addresses to admins, so run the import with a PLANKA admin account to match assignees.`,
+ );
+ }
+ if (notAWorkspaceMember > 0) {
+ report.warnings.push(
+ `${notAWorkspaceMember} card assignment(s) were skipped because no member of this Kaneo workspace has a matching email. Invite those people to the workspace first, then re-run.`,
+ );
+ }
}
+type AssigneeResolution = {
+ userId?: string;
+ reason?: "no_email" | "not_a_member";
+};
+
function resolveAssignee(
cardId: string,
memberships: { cardId: string; userId: string }[],
usersById: Map<string, PlankaUser>,
membersByEmail: Map<string, string>,
-): string | undefined {
+): AssigneeResolution {
// Kaneo has a single assignee; take the first member present in the workspace.
+ let reason: AssigneeResolution["reason"];
+
for (const membership of memberships) {
if (membership.cardId !== cardId) continue;
const email = usersById.get(membership.userId)?.email?.toLowerCase();
- if (!email) continue;
+ if (!email) {
+ reason ??= "no_email";
+ continue;
+ }
const kaneoUserId = membersByEmail.get(email);
- if (kaneoUserId) return kaneoUserId;
+ if (kaneoUserId) return { userId: kaneoUserId };
+ reason = "not_a_member";
}
- return undefined;
+ return reason ? { reason } : {};
}
diff --git a/packages/planka-import/src/planka.ts b/packages/planka-import/src/planka.ts
index 15c24a3ba..2e88e44e6 100644
--- a/packages/planka-import/src/planka.ts
+++ b/packages/planka-import/src/planka.ts
@@ -1,6 +1,7 @@
export type PlankaUser = {
id: string;
- email: string;
+ // PLANKA omits email unless the caller is an admin or the user themselves.
+ email?: string | null;
name: string | null;
username: string | null;
};
@@ -59,6 +60,7 @@ export type PlankaTask = {
name: string;
isCompleted: boolean | null;
position: number;
+ linkedCardId?: string | null;
};
export type PlankaAttachment = { id: string; cardId: string };
export type PlankaComment = {
diff --git a/tests/api-integration/comment.test.ts b/tests/api-integration/comment.test.ts
index 981456a59..9955410fb 100644
--- a/tests/api-integration/comment.test.ts
+++ b/tests/api-integration/comment.test.ts
@@ -94,4 +94,112 @@ describe("API integration: task comments", () => {
.where(eq(schema.commentTable.taskId, task.id));
expect(legacyComments).toHaveLength(0);
});
+
+ it("records an external author when both name and source are given", async () => {
+ const member = await createWorkspaceMember();
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Imported",
+ status: "to-do",
+ columnId: columns.todo.id,
+ priority: "medium",
+ number: 1,
+ position: 1,
+ })
+ .returning();
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const attributed = await app.request(`/api/comment/${task.id}`, {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ content: "From PLANKA",
+ externalUserName: "Sam",
+ externalSource: "planka",
+ }),
+ });
+ expect(attributed.status).toBe(200);
+
+ const [row] = await db
+ .select()
+ .from(schema.activityTable)
+ .where(eq(schema.activityTable.taskId, task.id));
+ expect(row?.externalUserName).toBe("Sam");
+ expect(row?.externalSource).toBe("planka");
+ });
+
+ it("ignores an external name with no source, so it cannot look like a real user", async () => {
+ const member = await createWorkspaceMember();
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Unattributed",
+ status: "to-do",
+ columnId: columns.todo.id,
+ priority: "medium",
+ number: 1,
+ position: 1,
+ })
+ .returning();
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ await app.request(`/api/comment/${task.id}`, {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ content: "Nice try", externalUserName: "Andrej" }),
+ });
+
+ const [row] = await db
+ .select()
+ .from(schema.activityTable)
+ .where(eq(schema.activityTable.taskId, task.id));
+ expect(row?.externalUserName).toBeNull();
+ });
+
+ it("rejects an unknown external source", async () => {
+ const member = await createWorkspaceMember();
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Bad source",
+ status: "to-do",
+ columnId: columns.todo.id,
+ priority: "medium",
+ number: 1,
+ position: 1,
+ })
+ .returning();
+
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+
+ const response = await app.request(`/api/comment/${task.id}`, {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ content: "Spoof",
+ externalUserName: "Andrej",
+ externalSource: "definitely-real",
+ }),
+ });
+
+ expect(response.status).toBeGreaterThanOrEqual(400);
+ });
});