⭐️⭐️⭐️ 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
fix(api): progress and burnup leave out issues archived unfinished (#801)
Ilya Shkuradea6db702c3f
diff --git a/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts b/apps/api/src/modules/analytics/__tests__/integration/analytics.test.tsindex 926b5d61..d1e227a3 100644--- a/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts+++ b/apps/api/src/modules/analytics/__tests__/integration/analytics.test.ts@@ -1,4 +1,6 @@import { describe, it, expect, beforeEach } from 'bun:test';+import { db, issue, issueStatus } from '@repo/db';+import { eq, sql } from 'drizzle-orm';import { authedApi, type Api, createProject } from '#tests/helpers/app';import { signUpTestUser, type TestUser } from '#tests/helpers/auth';import { resetDb } from '#tests/helpers/db';@@ -533,6 +535,42 @@ describe('analytics', () => {expect(res.data?.forecast).toMatchObject({ remaining: 1, projectedDate: null });});+ it('drops an issue archived unfinished from the scope and keeps an archived closed one', async () => {+ const { asOwner, col } = await setupProject();+ await createIssue(asOwner, col.backlog);+ const open = await createIssue(asOwner, col.started);+ const done = await createIssue(asOwner, col.started);+ await moveIssue(asOwner, done.id, col.completed);+ await asOwner.issues({ issueId: open.id }).archive.post();+ await asOwner.issues({ issueId: done.id }).archive.post();++ const res = await burnup(asOwner);+ expect(res.status).toBe(200);+ expect(res.data?.days.at(-1)).toMatchObject({ scope: 2, started: 1, completed: 1 });+ expect(res.data?.forecast.remaining).toBe(1);+ });++ it('keeps an issue archived unfinished in the scope of the days before it was archived', async () => {+ const { asOwner, col } = await setupProject();+ const open = await createIssue(asOwner, col.started);+ await asOwner.issues({ issueId: open.id }).archive.post();+ // No route moves a status stretch or an archive into the past, so both are set+ // directly.+ await db+ .update(issueStatus)+ .set({ enteredAt: sql`now() - interval '3 days'` })+ .where(eq(issueStatus.issueId, open.id));+ await db+ .update(issue)+ .set({ archivedAt: sql`now() - interval '1 day'` })+ .where(eq(issue.id, open.id));++ const days = (await burnup(asOwner)).data!.days;+ expect(days.at(-3)).toMatchObject({ scope: 1, started: 1, completed: 0 });+ expect(days.at(-2)).toMatchObject({ scope: 0, started: 0 });+ expect(days.at(-1)).toMatchObject({ scope: 0, started: 0 });+ });+it('limits the series to one initiative and returns its target date', async () => {const { asOwner, col } = await setupProject();const created = await asOwnerdiff --git a/apps/api/src/modules/analytics/service.ts b/apps/api/src/modules/analytics/service.tsindex ec4e760a..a841f35d 100644--- a/apps/api/src/modules/analytics/service.ts+++ b/apps/api/src/modules/analytics/service.ts@@ -386,7 +386,9 @@ export interface BurnupParams {// burnup asks what state every issue was in at the end of each day: the status row// whose stretch covers that midnight. So an issue that was reopened leaves the// completed line for the days it was open again, and a canceled issue leaves the-// scope line — the chart is a history of the project, not of the events.+// scope line — the chart is a history of the project, not of the events. An issue+// archived unfinished leaves the scope from the day it was archived, as a canceled+// one does; an archived finished one stays completed.export async function getBurnup(projectId: number, params: BurnupParams): Promise<BurnupDto> {const targetDate = await initiativeTargetDate(projectId, params.initiativeId);const initiativeFilter =@@ -401,12 +403,13 @@ export async function getBurnup(projectId: number, params: BurnupParams): Promis(count(s.issue_id) FILTER (WHERE s.state_type = 'completed'))::int AS completedFROM dLEFT JOIN (- SELECT s.issue_id, s.state_type, s.entered_at, s.left_at+ SELECT s.issue_id, s.state_type, s.entered_at, s.left_at, i.archived_atFROM issue_status sJOIN issue i ON i.id = s.issue_idWHERE i.project_id = ${projectId} ${initiativeFilter}) s ON s.entered_at < d.day + 1AND (s.left_at IS NULL OR s.left_at >= d.day + 1)+ AND (s.archived_at IS NULL OR s.archived_at >= d.day + 1 OR s.state_type = 'completed')GROUP BY d.dayORDER BY d.day`)) as unknown as BurnupDay[];const days = rows.map((r) => ({diff --git a/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts b/apps/api/src/modules/cycles/__tests__/integration/cycles.test.tsindex d4009a66..59b38d36 100644--- a/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts+++ b/apps/api/src/modules/cycles/__tests__/integration/cycles.test.ts@@ -209,6 +209,19 @@ describe('cycles', () => {const read = await asOwner.cycles({ cycleId: cycle.id }).get();expect(read.data!.progress).toMatchObject({ total: 3, completed: 1, canceled: 0 });});++ it('leaves out an issue archived unfinished and keeps an archived finished one', async () => {+ const { asOwner, columnId, doneColumnId } = await setup();+ const cycle = (await createCycle(asOwner, {})).data!;+ await createIssue(asOwner, columnId, { cycleId: cycle.id });+ const open = (await createIssue(asOwner, columnId, { cycleId: cycle.id })).data!;+ const done = (await createIssue(asOwner, doneColumnId, { cycleId: cycle.id })).data!;+ await asOwner.issues({ issueId: open.id }).archive.post();+ await asOwner.issues({ issueId: done.id }).archive.post();++ const read = await asOwner.cycles({ cycleId: cycle.id }).get();+ expect(read.data!.progress).toMatchObject({ total: 2, completed: 1, canceled: 0 });+ });});describe('update', () => {diff --git a/apps/api/src/modules/cycles/service.ts b/apps/api/src/modules/cycles/service.tsindex 9e9fef8b..678bf2ef 100644--- a/apps/api/src/modules/cycles/service.ts+++ b/apps/api/src/modules/cycles/service.ts@@ -71,7 +71,9 @@ function selectCycles(where: SQL | undefined) {return db.select({row: cycle,- total: sql<number>`count(${issue.id})`,+ // An archived issue left unfinished is off the board and is not carried over,+ // so it is not work the cycle still has to do; a finished one still counts.+ total: sql<number>`count(${issue.id}) filter (where ${issue.archivedAt} is null or ${projectColumn.stateType} in ('completed', 'canceled'))`,completed: sql<number>`count(*) filter (where ${projectColumn.stateType} = 'completed')`,canceled: sql<number>`count(*) filter (where ${projectColumn.stateType} = 'canceled')`,})diff --git a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.tsindex 3f189e9a..101ab500 100644--- a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts+++ b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts@@ -324,6 +324,22 @@ describe('initiatives', () => {expect(typeof got.data?.health).toBe('string');});+ it('leaves out an issue archived unfinished and keeps an archived finished one', async () => {+ const { asOwner, columnId, doneColumnId } = await setup();+ const initiative = (await createInitiative(asOwner, { title: 'Q3' })).data!;+ const scope = asOwner.projects({ projectKey: 'MKT' }).issues;+ await scope.post({ columnId, title: 'A', initiativeId: initiative.id });+ const open = (await scope.post({ columnId, title: 'B', initiativeId: initiative.id })).data!;+ const done = (+ await scope.post({ columnId: doneColumnId, title: 'C', initiativeId: initiative.id })+ ).data!;+ await asOwner.issues({ issueId: open.id }).archive.post();+ await asOwner.issues({ issueId: done.id }).archive.post();++ const got = await asOwner.initiatives({ initiativeId: initiative.id }).get();+ expect(got.data?.progress).toMatchObject({ completed: 1, total: 2, canceled: 0 });+ });+it('links and unlinks an issue through update_issue', async () => {const { asOwner, columnId } = await setup();const initiative = (await createInitiative(asOwner, { title: 'Q3' })).data!;diff --git a/apps/api/src/modules/initiatives/service.ts b/apps/api/src/modules/initiatives/service.tsindex 1043b5be..50bd28a9 100644--- a/apps/api/src/modules/initiatives/service.ts+++ b/apps/api/src/modules/initiatives/service.ts@@ -43,7 +43,9 @@ async function countsFor(initiativeIds: number[]): Promise<Map<number, Initiativconst rows = await db.select({initiativeId: issue.initiativeId,- total: sql<number>`count(*)`,+ // An archived issue left unfinished is off the board, so it is not work the+ // initiative still has to do; a finished one still counts.+ total: sql<number>`count(*) filter (where ${issue.archivedAt} is null or ${projectColumn.stateType} in ('completed', 'canceled'))`,completed: sql<number>`count(*) filter (where ${projectColumn.stateType} = 'completed')`,canceled: sql<number>`count(*) filter (where ${projectColumn.stateType} = 'canceled')`,})