Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(linear): import completed issues by default (#22086)

Rdmclin24e3f6721a059
diff --git a/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts b/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts
index 42defe06f0d..331d80c9bc4 100644
--- a/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts
+++ b/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts
@@ -1,6 +1,7 @@
// @vitest-environment node
import { type LobeChatDatabase } from '@lobechat/database';
import { getTestDB } from '@lobechat/database/test-utils';
+import { LINEAR_DEFAULT_IMPORT_STATE_TYPES, LINEAR_OPEN_ISSUE_STATE_TYPES } from '@lobechat/types';
import { eq } from 'drizzle-orm';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -167,6 +168,37 @@ describe('LinearIssueSyncService (real PostgreSQL)', () => {
expect((await linkedTask('1'))?.status).toBe('completed');
});
+ it('imports completed issues as completed tasks when the filter includes completed', async () => {
+ serve([
+ issue({ id: '1', state: { name: 'Done', type: 'completed' } }),
+ issue({ id: '2', state: { name: 'In Progress', type: 'started' } }),
+ ]);
+ const service = new LinearIssueSyncService(db, userId);
+
+ const result = await service.syncByFilter(TOKEN, {
+ stateTypes: [...LINEAR_DEFAULT_IMPORT_STATE_TYPES],
+ teamId: TEAM,
+ });
+
+ expect(result).toMatchObject({ created: 2, skipped: [] });
+ expect((await linkedTask('1'))?.status).toBe('completed');
+ expect((await linkedTask('2'))?.status).toBe('backlog');
+ });
+
+ it('skips completed issues when the filter only asks for open states', async () => {
+ serve([issue({ id: '1', state: { name: 'Done', type: 'completed' } })]);
+ const service = new LinearIssueSyncService(db, userId);
+
+ const result = await service.syncByFilter(TOKEN, {
+ stateTypes: [...LINEAR_OPEN_ISSUE_STATE_TYPES],
+ teamId: TEAM,
+ });
+
+ expect(result.created).toBe(0);
+ expect(result.skipped).toEqual([{ identifier: 'ENG-1', reason: 'closed' }]);
+ expect(await linkedTask('1')).toBeNull();
+ });
+
it('nests a sub-issue under the task of its parent issue', async () => {
serve([issue({ id: 'child', parent: { id: 'parent' } }), issue({ id: 'parent' })]);
const service = new LinearIssueSyncService(db, userId);
diff --git a/locales/en-US/integration.json b/locales/en-US/integration.json
index 4906e1ebc3a..776f05b2aa9 100644
--- a/locales/en-US/integration.json
+++ b/locales/en-US/integration.json
@@ -72,7 +72,7 @@
"linear.sync.filter.project": "Linear project",
"linear.sync.filter.projectHint": "Keep All projects to include every issue in the team.",
"linear.sync.filter.states": "Issue states to sync",
- "linear.sync.filter.statesHint": "Completed and canceled issues are left out by default.",
+ "linear.sync.filter.statesHint": "Canceled issues are left out by default.",
"linear.sync.filter.statesSummary": "{{count}} states",
"linear.sync.filter.team": "Linear team",
"linear.sync.filter.teamPlaceholder": "Choose a team",
diff --git a/locales/zh-CN/integration.json b/locales/zh-CN/integration.json
index 1d217ed641e..b05e0239fb6 100644
--- a/locales/zh-CN/integration.json
+++ b/locales/zh-CN/integration.json
@@ -72,7 +72,7 @@
"linear.sync.filter.project": "Linear 项目",
"linear.sync.filter.projectHint": "保持「全部项目」即包含团队内的所有 Issue。",
"linear.sync.filter.states": "同步的 Issue 状态",
- "linear.sync.filter.statesHint": "默认不包含已完成和已取消的 Issue。",
+ "linear.sync.filter.statesHint": "默认不包含已取消的 Issue。",
"linear.sync.filter.statesSummary": "{{count}} 种状态",
"linear.sync.filter.team": "Linear 团队",
"linear.sync.filter.teamPlaceholder": "选择团队",
diff --git a/packages/locales/src/default/integration.ts b/packages/locales/src/default/integration.ts
index 4aaa5e2637d..d49d72fab02 100644
--- a/packages/locales/src/default/integration.ts
+++ b/packages/locales/src/default/integration.ts
@@ -93,7 +93,7 @@ export default {
'linear.sync.filter.project': 'Linear project',
'linear.sync.filter.projectHint': 'Keep All projects to include every issue in the team.',
'linear.sync.filter.states': 'Issue states to sync',
- 'linear.sync.filter.statesHint': 'Completed and canceled issues are left out by default.',
+ 'linear.sync.filter.statesHint': 'Canceled issues are left out by default.',
'linear.sync.filter.statesSummary': '{{count}} states',
'linear.sync.filter.team': 'Linear team',
'linear.sync.filter.teamPlaceholder': 'Choose a team',
diff --git a/packages/types/src/linear.ts b/packages/types/src/linear.ts
index 9d909038aad..79c14111e07 100644
--- a/packages/types/src/linear.ts
+++ b/packages/types/src/linear.ts
@@ -53,6 +53,15 @@ export const LINEAR_OPEN_ISSUE_STATE_TYPES: LinearIssueStateType[] = [
'started',
];
+/**
+ * States the import dialog starts with: open issues plus completed ones, so a
+ * team moving over keeps its history. Canceled issues stay out by default.
+ */
+export const LINEAR_DEFAULT_IMPORT_STATE_TYPES: LinearIssueStateType[] = [
+ ...LINEAR_OPEN_ISSUE_STATE_TYPES,
+ 'completed',
+];
+
/** Providers a task can be linked to through `task_external_links`. */
export type TaskExternalProvider = 'linear';
diff --git a/src/features/Projects/LinearSync/types.test.ts b/src/features/Projects/LinearSync/types.test.ts
new file mode 100644
index 00000000000..84db143016b
--- /dev/null
+++ b/src/features/Projects/LinearSync/types.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest';
+
+import { initialImportFilter } from './types';
+
+describe('initialImportFilter', () => {
+ it('imports open and completed issues by default, but not canceled ones', () => {
+ expect(initialImportFilter().stateTypes).toEqual([
+ 'triage',
+ 'backlog',
+ 'unstarted',
+ 'started',
+ 'completed',
+ ]);
+ });
+
+ it('returns a fresh state list each time, so edits do not leak into the next dialog', () => {
+ const first = initialImportFilter();
+ first.stateTypes.pop();
+
+ expect(initialImportFilter().stateTypes).toContain('completed');
+ });
+});
diff --git a/src/features/Projects/LinearSync/types.ts b/src/features/Projects/LinearSync/types.ts
index e6c37f29a4e..88d5bc9642f 100644
--- a/src/features/Projects/LinearSync/types.ts
+++ b/src/features/Projects/LinearSync/types.ts
@@ -1,5 +1,5 @@
import type { LinearConnectionView, LinearIssueStateType } from '@lobechat/types';
-import { LINEAR_OPEN_ISSUE_STATE_TYPES } from '@lobechat/types';
+import { LINEAR_DEFAULT_IMPORT_STATE_TYPES } from '@lobechat/types';
/** What the import picker is filtered to. */
export interface LinearImportFilter {
@@ -13,7 +13,7 @@ export interface LinearImportFilter {
export const initialImportFilter = (): LinearImportFilter => ({
linearProjectId: null,
linearProjectName: null,
- stateTypes: [...LINEAR_OPEN_ISSUE_STATE_TYPES],
+ stateTypes: [...LINEAR_DEFAULT_IMPORT_STATE_TYPES],
teamId: null,
teamName: null,
});