⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
feat(worker): keep the source's created and updated dates on imported issues (#476)
Thomas Gallaway57fd0902b82b
diff --git a/apps/worker/src/__tests__/integration/import-store.test.ts b/apps/worker/src/__tests__/integration/import-store.test.tsindex 5b0e32a2..e2137544 100644--- a/apps/worker/src/__tests__/integration/import-store.test.ts+++ b/apps/worker/src/__tests__/integration/import-store.test.ts@@ -24,6 +24,7 @@ import {createLocalAttachmentAndRecord,findImportRecord,AttachmentRejectedError,+ type NewLocalIssue,} from '../../import-store';// Nothing here calls resetDb (the worker has no api to reset for), so every@@ -68,6 +69,21 @@ async function makeIssue(projectId: number, columnId: number, title = 'Task'): Preturn row!.id;}+function newIssue(projectId: number, columnId: number, title: string): NewLocalIssue {+ return {+ projectId,+ columnId,+ cycleId: null,+ parentId: null,+ assigneeUserId: null,+ title,+ description: '',+ priority: null,+ startDate: null,+ dueDate: null,+ };+}+describe('claimDueImportJobs', () => {it('claims a due pending job, bumps attempts, and clears a stale last_error', async () => {const { projectId, userId } = await makeProject();@@ -199,6 +215,53 @@ describe('createLocalIssueAndRecord', () => {// The reused issue keeps its own content; the import does not overwrite it.expect(row?.description).toBe('');});++ it("keeps the source's created and updated dates", async () => {+ const { projectId, columnId, userId } = await makeProject();+ const jobId = await makeImportJob(projectId, userId);++ const issueId = await createLocalIssueAndRecord(jobId, 'plane-issue-3', 'ROOMS-3', {+ ...newIssue(projectId, columnId, 'Old work'),+ createdAt: '2024-03-01T09:30:00.000Z',+ updatedAt: '2024-05-20T17:00:00.000Z',+ });++ const [row] = await db.select().from(issue).where(eq(issue.id, issueId));+ expect(row?.createdAt.toISOString()).toBe('2024-03-01T09:30:00.000Z');+ expect(row?.updatedAt.toISOString()).toBe('2024-05-20T17:00:00.000Z');+ });++ it('falls back to now for a missing or unparseable source date', async () => {+ const { projectId, columnId, userId } = await makeProject();+ const jobId = await makeImportJob(projectId, userId);+ const before = Date.now() - 60_000;++ const issueId = await createLocalIssueAndRecord(jobId, 'plane-issue-4', 'ROOMS-4', {+ ...newIssue(projectId, columnId, 'Undated work'),+ createdAt: 'not a date',+ });++ const [row] = await db.select().from(issue).where(eq(issue.id, issueId));+ expect(row!.createdAt.getTime()).toBeGreaterThan(before);+ expect(row!.updatedAt.getTime()).toBeGreaterThan(before);+ });++ it("leaves a reused issue's own dates alone", async () => {+ const { projectId, columnId, userId } = await makeProject();+ const existingId = await makeIssue(projectId, columnId, 'Shared title');+ const [existing] = await db.select().from(issue).where(eq(issue.id, existingId));+ const jobId = await makeImportJob(projectId, userId);++ await createLocalIssueAndRecord(jobId, 'plane-issue-5', 'ROOMS-5', {+ ...newIssue(projectId, columnId, 'Shared title'),+ createdAt: '2020-01-01T00:00:00.000Z',+ updatedAt: '2020-01-02T00:00:00.000Z',+ });++ const [row] = await db.select().from(issue).where(eq(issue.id, existingId));+ expect(row?.createdAt).toEqual(existing!.createdAt);+ expect(row?.updatedAt).toEqual(existing!.updatedAt);+ });});describe('createLocalAttachmentAndRecord', () => {diff --git a/apps/worker/src/import-store.ts b/apps/worker/src/import-store.tsindex 59257949..50d36b73 100644--- a/apps/worker/src/import-store.ts+++ b/apps/worker/src/import-store.ts@@ -534,6 +534,15 @@ export interface NewLocalIssue {priority: string | null;startDate: string | null;dueDate: string | null;+ // The source's own ISO timestamps. Absent or unparseable leaves the column default, now().+ createdAt?: string;+ updatedAt?: string;+}++function sourceTimestamp(value: string | undefined): Date | undefined {+ if (!value) return undefined;+ const date = new Date(value);+ return Number.isNaN(date.getTime()) ? undefined : date;}// An issue whose title matches one already in the project (case- and@@ -612,6 +621,8 @@ export async function createLocalIssueAndRecord(startDate: input.startDate,dueDate: input.dueDate,position: Number(posRow!.pos),+ createdAt: sourceTimestamp(input.createdAt),+ updatedAt: sourceTimestamp(input.updatedAt),}).returning({ id: issue.id });await upsertImportRecordWith(tx, jobId, 'issue', sourceId, 'issue', row!.id, sourceDisplayId);diff --git a/apps/worker/src/import-worker.ts b/apps/worker/src/import-worker.tsindex d1deca23..1202f9ff 100644--- a/apps/worker/src/import-worker.ts+++ b/apps/worker/src/import-worker.ts@@ -290,6 +290,8 @@ async function createOneIssue(priority: canonical.priority,startDate: canonical.startDate,dueDate: canonical.dueDate,+ createdAt: canonical.createdAt,+ updatedAt: canonical.updatedAt,});if (labelIds.length) await setIssueLabels(localId, labelIds);diff --git a/docs/importing-from-plane.md b/docs/importing-from-plane.mdindex 7bcbe62a..8d6f313d 100644--- a/docs/importing-from-plane.md+++ b/docs/importing-from-plane.md@@ -30,7 +30,11 @@ of them affect data you may not notice is missing until later.## What is imported- **Issues** — title, description (converted from Plane's rich text to Markdown), state,- labels, cycle, priority, start date, due date, and the parent issue if it is a sub-issue.+ labels, cycle, priority, start date, due date, the parent issue if it is a sub-issue, and+ the dates the issue was created and last updated in Plane. If the project automatically+ archives issues in completed or canceled columns, an imported issue in a completed or+ canceled column whose last update in Plane is older than that threshold is archived on+ the next sweep.- **Assignees and comment authors** — matched to an existing project member by email. It isnever assigned to the wrong person, and no placeholder account is created; what happenswhen no member has that email is a choice you make in the mapping review step below.