🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(linear): import issues that belong to no Linear project (#22301)
Rdmclin2cf3f3d635e14
diff --git a/apps/server/src/routers/lambda/__tests__/linear.test.ts b/apps/server/src/routers/lambda/__tests__/linear.test.tsindex ee5c1817a6a..24d81059060 100644--- a/apps/server/src/routers/lambda/__tests__/linear.test.ts+++ b/apps/server/src/routers/lambda/__tests__/linear.test.ts@@ -1,5 +1,6 @@// @vitest-environment nodeimport { getTestDB } from '@lobechat/database/test-utils';+import { LINEAR_NO_PROJECT_ID } from '@lobechat/types';import { TRPCClientError } from '@trpc/client';import { eq } from 'drizzle-orm';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -290,6 +291,36 @@ describe('linearRouter', () => {expect(saved.lastRunAt).toBeInstanceOf(Date);});+ it('saves and runs a rule for the team’s issues without a Linear project', async () => {+ const connection = await connect({ userId });+ mocks.getToken.mockResolvedValue('token');+ mocks.runSync.mockResolvedValue({ ok: true });+ mocks.syncByFilter.mockResolvedValue(syncResult);++ const rule = await caller({ userId }).createSyncRule({+ connectionId: connection.id,+ linearProjectId: LINEAR_NO_PROJECT_ID,+ linearProjectName: 'ignored',+ projectId,+ stateTypes: ['backlog'],+ teamId: 'team-1',+ teamName: 'Engineering',+ });+ expect(rule).toMatchObject({+ linearProjectId: LINEAR_NO_PROJECT_ID,+ linearProjectName: null,+ });++ const { id } = await caller({ userId }).startRuleSync({ ruleId: rule.id });+ await new LinearSyncJobService(serverDB, userId).run(id);++ expect(mocks.syncByFilter).toHaveBeenCalledWith(+ 'token',+ { linearProjectId: LINEAR_NO_PROJECT_ID, stateTypes: ['backlog'], teamId: 'team-1' },+ { targetProjectId: projectId },+ );+ });+describe('when a rule matches more issues than one round creates', () => {const round = (created: number,diff --git a/apps/server/src/routers/lambda/linear.ts b/apps/server/src/routers/lambda/linear.tsindex 3dfbf9b3142..2107ef24f99 100644--- a/apps/server/src/routers/lambda/linear.ts+++ b/apps/server/src/routers/lambda/linear.ts@@ -1,5 +1,5 @@import type { LinearSyncJobMetadata } from '@lobechat/types';-import { LINEAR_ISSUE_STATE_TYPES } from '@lobechat/types';+import { isLinearNoProject, LINEAR_ISSUE_STATE_TYPES } from '@lobechat/types';import { TRPCError } from '@trpc/server';import { z } from 'zod';@@ -230,7 +230,11 @@ export const linearRouter = router({const row = await LinearSyncRuleModel.create(ctx.serverDB, {connectionId: input.connectionId,linearProjectId: input.linearProjectId ?? null,- linearProjectName: input.linearProjectId ? (input.linearProjectName ?? null) : null,+ // "No project" is labelled by the client; there is no Linear name to keep.+ linearProjectName:+ input.linearProjectId && !isLinearNoProject(input.linearProjectId)+ ? (input.linearProjectName ?? null)+ : null,projectId: input.projectId,stateTypes: input.stateTypes,teamId: input.teamId,diff --git a/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts b/apps/server/src/services/linear/__tests__/issueSync.integration.test.tsindex 12117a0ad89..bf6d952c3b4 100644--- a/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts+++ b/apps/server/src/services/linear/__tests__/issueSync.integration.test.ts@@ -1,7 +1,11 @@// @vitest-environment nodeimport { 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 {+ LINEAR_DEFAULT_IMPORT_STATE_TYPES,+ LINEAR_NO_PROJECT_ID,+ LINEAR_OPEN_ISSUE_STATE_TYPES,+} from '@lobechat/types';import { eq } from 'drizzle-orm';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -190,6 +194,32 @@ describe('LinearIssueSyncService (real PostgreSQL)', () => {).rejects.toThrow('timeout');});+ it('syncs a team’s issues without a project, never looking No project up as a project', async () => {+ const noProjectFilter = {+ linearProjectId: LINEAR_NO_PROJECT_ID,+ stateTypes: [...filter.stateTypes],+ teamId: TEAM,+ };+ serve([issue({ id: '1' })]);+ const service = new LinearIssueSyncService(db, userId);+ expect((await service.syncByFilter(TOKEN, noProjectFilter)).created).toBe(1);++ // Moved into a project and closed there: the team-wide closing pass still closes it.+ linear.listLinearIssues.mockResolvedValue({ hasMore: false, issues: [] });+ linear.getLinearIssuesByIds.mockResolvedValue([+ issue({+ id: '1',+ project: { id: 'project-1', name: 'Later' },+ state: { name: 'Done', type: 'completed' },+ }),+ ]);+ const result = await service.syncByFilter(TOKEN, noProjectFilter);++ expect(linear.getLinearProjectTeamIds).not.toHaveBeenCalled();+ expect(result.closed).toBe(1);+ expect((await linkedTask('1'))?.status).toBe('completed');+ });+it('does not interrupt a running task when its issue is closed', async () => {serve([issue({ id: '1' })]);const service = new LinearIssueSyncService(db, userId);diff --git a/apps/server/src/services/linear/__tests__/issues.test.ts b/apps/server/src/services/linear/__tests__/issues.test.tsindex 1bc048c1420..7240ed005f3 100644--- a/apps/server/src/services/linear/__tests__/issues.test.ts+++ b/apps/server/src/services/linear/__tests__/issues.test.ts@@ -1,4 +1,5 @@// @vitest-environment node+import { LINEAR_NO_PROJECT_ID } from '@lobechat/types';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { countLinearIssues, getLinearProjectTeamIds, listLinearIssues } from '../issues';@@ -50,6 +51,21 @@ describe('listLinearIssues filter', () => {state: { type: { in: ['unstarted', 'started'] } },});});+ it('keeps the team and drops issues with a project when No project is chosen', async () => {+ fetchMock.mockResolvedValue(reply(emptyIssues));++ await countLinearIssues('token', {+ linearProjectId: LINEAR_NO_PROJECT_ID,+ stateTypes: ['backlog'],+ teamId: 'team-pkg',+ });++ expect(requestBody(fetchMock.mock.calls[0]).variables.filter).toEqual({+ project: { null: true },+ state: { type: { in: ['backlog'] } },+ team: { id: { eq: 'team-pkg' } },+ });+ });});describe('getLinearProjectTeamIds', () => {diff --git a/apps/server/src/services/linear/issueSync.ts b/apps/server/src/services/linear/issueSync.tsindex 98933ddec9b..a5e2338c564 100644--- a/apps/server/src/services/linear/issueSync.ts+++ b/apps/server/src/services/linear/issueSync.ts@@ -8,6 +8,7 @@ import type {LinearSyncSkipReason,TaskItem,} from '@lobechat/types';+import { isLinearNoProject } from '@lobechat/types';import debug from 'debug';import pMap from 'p-map';@@ -325,7 +326,7 @@ export class LinearIssueSyncService {// can be any team the project belongs to, not just the filter's team.const seen = new Set(issues.map((issue) => issue.id));const teamIds = new Set([filter.teamId, ...issues.map((issue) => issue.team.id)]);- if (filter.linearProjectId) {+ if (filter.linearProjectId && !isLinearNoProject(filter.linearProjectId)) {// Let a failed lookup fail the run: skipping the project's other teams// would leave their closed issues' tasks open without any sign of it.for (const id of await getLinearProjectTeamIds(accessToken, filter.linearProjectId)) {diff --git a/apps/server/src/services/linear/issues.ts b/apps/server/src/services/linear/issues.tsindex b6359420562..9571ae92980 100644--- a/apps/server/src/services/linear/issues.ts+++ b/apps/server/src/services/linear/issues.ts@@ -4,6 +4,7 @@ import type {LinearProjectSummary,LinearTeamSummary,} from '@lobechat/types';+import { isLinearNoProject } from '@lobechat/types';import { linearGraphql } from './client';@@ -91,6 +92,7 @@ export const listLinearProjects = async (};export interface LinearIssueFilter {+ /** A Linear project, `LINEAR_NO_PROJECT_ID` for issues in none, or empty for the whole team. */linearProjectId?: string | null;stateTypes: LinearIssueStateType[];teamId: string;@@ -99,13 +101,15 @@ export interface LinearIssueFilter {/*** A project filters by project alone: a Linear project can belong to several* teams, and its issues may all live in a team other than the chosen one.+ * "No project" keeps the team and drops every issue that has a project.*/-const toIssueFilter = ({ linearProjectId, stateTypes, teamId }: LinearIssueFilter) => ({- state: { type: { in: stateTypes } },- ...(linearProjectId- ? { project: { id: { eq: linearProjectId } } }- : { team: { id: { eq: teamId } } }),-});+const toIssueFilter = ({ linearProjectId, stateTypes, teamId }: LinearIssueFilter) => {+ const state = { type: { in: stateTypes } };+ const team = { id: { eq: teamId } };+ if (isLinearNoProject(linearProjectId)) return { project: { null: true }, state, team };+ if (linearProjectId) return { project: { id: { eq: linearProjectId } }, state };+ return { state, team };+};/** Ids of every team a project belongs to; none when the project does not exist. */export const getLinearProjectTeamIds = async (diff --git a/locales/en-US/integration.json b/locales/en-US/integration.jsonindex 58c3d53adb5..a1f4bbfd961 100644--- a/locales/en-US/integration.json+++ b/locales/en-US/integration.json@@ -69,8 +69,9 @@"linear.sync.error.generic": "Linear sync failed. Please try again.","linear.sync.error.reconnect": "The Linear connection has expired. Reconnect the workspace, then try again.","linear.sync.filter.allProjects": "All projects",+ "linear.sync.filter.noProject": "No project","linear.sync.filter.project": "Linear project",- "linear.sync.filter.projectHint": "Keep All projects to include every issue in the team.",+ "linear.sync.filter.projectHint": "Keep All projects to include every issue in the team, or pick No project for issues not in any project.","linear.sync.filter.states": "Issue states to sync","linear.sync.filter.statesHint": "Canceled issues are left out by default.","linear.sync.filter.statesSummary": "{{count}} states",diff --git a/locales/zh-CN/integration.json b/locales/zh-CN/integration.jsonindex d952208f91e..a824893e721 100644--- a/locales/zh-CN/integration.json+++ b/locales/zh-CN/integration.json@@ -69,8 +69,9 @@"linear.sync.error.generic": "Linear 同步失败,请重试。","linear.sync.error.reconnect": "Linear 连接已失效,请重新连接工作区后再试。","linear.sync.filter.allProjects": "全部项目",+ "linear.sync.filter.noProject": "无项目","linear.sync.filter.project": "Linear 项目",- "linear.sync.filter.projectHint": "保持「全部项目」即包含团队内的所有 Issue。",+ "linear.sync.filter.projectHint": "保持「全部项目」即包含团队内的所有 Issue;选「无项目」只看未关联任何项目的 Issue。","linear.sync.filter.states": "同步的 Issue 状态","linear.sync.filter.statesHint": "默认不包含已取消的 Issue。","linear.sync.filter.statesSummary": "{{count}} 种状态",diff --git a/packages/locales/src/default/integration.ts b/packages/locales/src/default/integration.tsindex 1030f319be2..b92405486a6 100644--- a/packages/locales/src/default/integration.ts+++ b/packages/locales/src/default/integration.ts@@ -90,8 +90,10 @@ export default {'linear.sync.error.reconnect':'The Linear connection has expired. Reconnect the workspace, then try again.','linear.sync.filter.allProjects': 'All projects',+ 'linear.sync.filter.noProject': 'No project','linear.sync.filter.project': 'Linear project',- 'linear.sync.filter.projectHint': 'Keep All projects to include every issue in the team.',+ 'linear.sync.filter.projectHint':+ 'Keep All projects to include every issue in the team, or pick No project for issues not in any project.','linear.sync.filter.states': 'Issue states to sync','linear.sync.filter.statesHint': 'Canceled issues are left out by default.','linear.sync.filter.statesSummary': '{{count}} states',diff --git a/packages/types/src/linear.ts b/packages/types/src/linear.tsindex ef93e107e0f..e03a06a6786 100644--- a/packages/types/src/linear.ts+++ b/packages/types/src/linear.ts@@ -62,6 +62,16 @@ export const LINEAR_DEFAULT_IMPORT_STATE_TYPES: LinearIssueStateType[] = ['completed',];+/**+ * `linearProjectId` value that scopes a filter or rule to the team's issues+ * that belong to no Linear project. Linear project ids are UUIDs, so it never+ * names a real project.+ */+export const LINEAR_NO_PROJECT_ID = 'none';++export const isLinearNoProject = (linearProjectId: string | null | undefined): boolean =>+ linearProjectId === LINEAR_NO_PROJECT_ID;+/** Providers a task can be linked to through `task_external_links`. */export type TaskExternalProvider = 'linear';diff --git a/src/features/Projects/LinearSync/ImportIssuesContent.tsx b/src/features/Projects/LinearSync/ImportIssuesContent.tsxindex 6c7031ef54b..0c9cb6a331b 100644--- a/src/features/Projects/LinearSync/ImportIssuesContent.tsx+++ b/src/features/Projects/LinearSync/ImportIssuesContent.tsx@@ -20,7 +20,12 @@ import {type LinearIssueImportModalOptions,} from './types';import { jobsShownInDialog, useLinearSyncJobs } from './useLinearSyncJobs';-import { isActiveLinearSyncJob, linearSyncErrorMessage } from './utils';+import {+ canLeaveLinearScopeStep,+ isActiveLinearSyncJob,+ linearScopeProjectLabel,+ linearSyncErrorMessage,+} from './utils';type Step = 'scope' | 'issues' | 'run';@@ -131,7 +136,7 @@ const ImportIssuesContent = memo<LinearIssueImportModalOptions>(const scopeLabel = [filter.teamName,- filter.linearProjectName ?? t('linear.sync.filter.allProjects'),+ linearScopeProjectLabel(filter, t, { withAll: true }),t('linear.sync.filter.statesSummary', { count: filter.stateTypes.length }),].join(' · ');@@ -139,8 +144,13 @@ const ImportIssuesContent = memo<LinearIssueImportModalOptions>(if (step === 'scope') {return (<Button- disabled={!filter.teamId || projectsLoading || !!projectsError}type={'primary'}+ disabled={+ !canLeaveLinearScopeStep(filter, {+ error: projectsError,+ isLoading: projectsLoading,+ })+ }onClick={() => setStep('issues')}>{t('linear.sync.wizard.next')}diff --git a/src/features/Projects/LinearSync/ScopeStep.tsx b/src/features/Projects/LinearSync/ScopeStep.tsxindex 29e751269e4..783badf2b9b 100644--- a/src/features/Projects/LinearSync/ScopeStep.tsx+++ b/src/features/Projects/LinearSync/ScopeStep.tsx@@ -1,7 +1,7 @@'use client';import type { LinearIssueStateType } from '@lobechat/types';-import { LINEAR_ISSUE_STATE_TYPES } from '@lobechat/types';+import { LINEAR_ISSUE_STATE_TYPES, LINEAR_NO_PROJECT_ID } from '@lobechat/types';import { Flexbox, Select, Text } from '@lobehub/ui';import { Form, useForm } from '@lobehub/ui/form';import { memo } from 'react';@@ -94,12 +94,17 @@ const ScopeStep = memo<ScopeStepProps>(({ connectionId, onChange, value }) => {variant={'filled'}options={[{ label: t('linear.sync.filter.allProjects'), value: ALL_PROJECTS },+ { label: t('linear.sync.filter.noProject'), value: LINEAR_NO_PROJECT_ID },...(projects.data ?? []).map((project) => ({label: project.name,value: project.id,})),]}onChange={(projectId) => {+ if (projectId === LINEAR_NO_PROJECT_ID) {+ onChange({ linearProjectId: LINEAR_NO_PROJECT_ID, linearProjectName: null });+ return;+ }const project = projects.data?.find((item) => item.id === projectId);onChange({linearProjectId: project?.id ?? null,diff --git a/src/features/Projects/LinearSync/SyncJobs.tsx b/src/features/Projects/LinearSync/SyncJobs.tsxindex f5a7bc3b216..ea1b362c536 100644--- a/src/features/Projects/LinearSync/SyncJobs.tsx+++ b/src/features/Projects/LinearSync/SyncJobs.tsx@@ -13,6 +13,7 @@ import { linearService } from '@/services/linear';import {formatLinearSyncResult,isActiveLinearSyncJob,+ linearScopeProjectLabel,linearSyncJobErrorMessage,linearSyncJobProgress,} from './utils';@@ -78,7 +79,7 @@ const SyncJobs = memo<SyncJobsProps>(({ canStop, jobs, onChanged, projectId, rulconst rule = rules.find((item) => item.id === job.ruleId);return rule? t('linear.sync.job.titleRule', {- rule: [rule.teamName, rule.linearProjectName].filter(Boolean).join(' › '),+ rule: [rule.teamName, linearScopeProjectLabel(rule, t)].filter(Boolean).join(' › '),}): t('linear.sync.job.titleRuleDeleted');};diff --git a/src/features/Projects/LinearSync/SyncRules.tsx b/src/features/Projects/LinearSync/SyncRules.tsxindex 220a702df0b..ead11fc558a 100644--- a/src/features/Projects/LinearSync/SyncRules.tsx+++ b/src/features/Projects/LinearSync/SyncRules.tsx@@ -23,7 +23,12 @@ import AsyncError from '@/components/AsyncError';import { linearKeys } from '@/features/Integrations/Linear/swrKeys';import { linearService } from '@/services/linear';-import { formatLinearSyncResult, isActiveLinearSyncJob, linearSyncErrorMessage } from './utils';+import {+ formatLinearSyncResult,+ isActiveLinearSyncJob,+ linearScopeProjectLabel,+ linearSyncErrorMessage,+} from './utils';const styles = stylex.create({list: {@@ -157,7 +162,7 @@ const SyncRules = memo<SyncRulesProps>(({ connections, jobs, onJobStarted, proje><Flexbox flex={1} gap={4} style={{ minWidth: 0 }}><Text ellipsis weight={500}>- {[organizationOf(rule), rule.teamName, rule.linearProjectName]+ {[organizationOf(rule), rule.teamName, linearScopeProjectLabel(rule, t)].filter(Boolean).join(' › ')}</Text>diff --git a/src/features/Projects/LinearSync/utils.test.ts b/src/features/Projects/LinearSync/utils.test.tsindex ae574763a1a..40372281336 100644--- a/src/features/Projects/LinearSync/utils.test.ts+++ b/src/features/Projects/LinearSync/utils.test.ts@@ -1,11 +1,14 @@import type { LinearSyncResult } from '@lobechat/types';+import { LINEAR_NO_PROJECT_ID } from '@lobechat/types';import type { TFunction } from 'i18next';import { describe, expect, it } from 'vitest';import {+ canLeaveLinearScopeStep,formatLinearSyncResult,isActiveLinearSyncJob,linearIssueListCounts,+ linearScopeProjectLabel,linearSyncJobErrorMessage,linearSyncJobProgress,} from './utils';@@ -132,3 +135,43 @@ describe('linearIssueListCounts', () => {).toBe('linear.sync.list.countAtLeast:100');});});++describe('linearScopeProjectLabel', () => {+ it('names the project, says No project, or falls back to All projects only when asked', () => {+ const scope = (linearProjectId: string | null, linearProjectName: string | null = null) => ({+ linearProjectId,+ linearProjectName,+ });++ expect(linearScopeProjectLabel(scope('p-1', 'Mobile'), t)).toBe('Mobile');+ expect(linearScopeProjectLabel(scope(LINEAR_NO_PROJECT_ID), t)).toBe(+ 'linear.sync.filter.noProject',+ );+ expect(linearScopeProjectLabel(scope(null), t)).toBeUndefined();+ expect(linearScopeProjectLabel(scope(null), t, { withAll: true })).toBe(+ 'linear.sync.filter.allProjects',+ );+ });+});++describe('canLeaveLinearScopeStep', () => {+ const loaded = { isLoading: false };+ const failed = { error: new Error('projects failed'), isLoading: false };++ it('needs a team', () => {+ expect(canLeaveLinearScopeStep({ linearProjectId: null, teamId: null }, loaded)).toBe(false);+ });++ it('holds All projects until the project list loads without error', () => {+ const all = { linearProjectId: null, teamId: 'team-1' };+ expect(canLeaveLinearScopeStep(all, loaded)).toBe(true);+ expect(canLeaveLinearScopeStep(all, { isLoading: true })).toBe(false);+ expect(canLeaveLinearScopeStep(all, failed)).toBe(false);+ });++ it('lets No project through when the project list is loading or failed', () => {+ const none = { linearProjectId: LINEAR_NO_PROJECT_ID, teamId: 'team-1' };+ expect(canLeaveLinearScopeStep(none, { isLoading: true })).toBe(true);+ expect(canLeaveLinearScopeStep(none, failed)).toBe(true);+ });+});diff --git a/src/features/Projects/LinearSync/utils.ts b/src/features/Projects/LinearSync/utils.tsindex 9ef8bfaca60..45b07cb5359 100644--- a/src/features/Projects/LinearSync/utils.ts+++ b/src/features/Projects/LinearSync/utils.ts@@ -4,6 +4,7 @@ import type {LinearSyncJobView,LinearSyncResult,} from '@lobechat/types';+import { isLinearNoProject } from '@lobechat/types';import { TRPCClientError } from '@trpc/client';import type { TFunction } from 'i18next';@@ -15,6 +16,32 @@ export const linearSyncErrorMessage = (error: unknown, t: TFunction<'integration? t('linear.sync.error.reconnect'): t('linear.sync.error.generic');+/**+ * How a scope's Linear project reads: its name, "No project", or — for a+ * whole-team scope — `allLabel` when given (a rule omits it, showing the team alone).+ */+export const linearScopeProjectLabel = (+ scope: { linearProjectId: string | null; linearProjectName: string | null },+ t: TFunction<'integration'>,+ options: { withAll?: boolean } = {},+): string | undefined => {+ if (isLinearNoProject(scope.linearProjectId)) return t('linear.sync.filter.noProject');+ if (scope.linearProjectId) return scope.linearProjectName ?? undefined;+ return options.withAll ? t('linear.sync.filter.allProjects') : undefined;+};++/**+ * Whether the scope step may move on. "All projects" waits for the team's+ * project list, since without it the choice may be a mistake; "No project"+ * needs only the team, so a failed or slow list does not block it.+ */+export const canLeaveLinearScopeStep = (+ filter: { linearProjectId: string | null; teamId: string | null },+ projects: { error?: unknown; isLoading: boolean },+): boolean =>+ !!filter.teamId &&+ (isLinearNoProject(filter.linearProjectId) || (!projects.isLoading && !projects.error));+/** All skipped issues; the stored list stops at its cap, and older results lack the count. */export const linearSyncSkippedCount = (result: LinearSyncResult): number =>result.skippedCount ?? result.skipped?.length ?? 0;