diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index fd6f7b2f0a0c..ccbeb8727972 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -467,6 +467,12 @@ describe("IssueService with a standalone tracker", () => { ["github", "github.com"], ["linear", "linear.app"], ]); + expect(result.scopes).toContainEqual({ + projectId: "web", + tracker: "linear", + host: "linear.app", + scope: "ENG", + }); // A reference picks the project's tracker by kind; both are the project's own, so writable. const linearRef = { projectId: "web" as ProjectId, diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index a53aeb698ce8..e2312582dbc1 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -424,6 +424,12 @@ const make = Effect.gen(function* () { entries, errors, nextCursors, + scopes: [...scopes.values()].map((project) => ({ + projectId: project.project.id, + tracker: project.tracker, + host: project.host, + scope: project.scope, + })), }; }); diff --git a/packages/client-runtime/src/issueList.test.ts b/packages/client-runtime/src/issueList.test.ts index 3923519abf06..591c41087656 100644 --- a/packages/client-runtime/src/issueList.test.ts +++ b/packages/client-runtime/src/issueList.test.ts @@ -130,6 +130,19 @@ describe("issueFilterScopes", () => { ]); }); + it("offers a bound tracker's scope the answer names when a search matches nothing", () => { + const scope = { + projectId: api, + tracker: "linear" as IssueTrackerKind, + host: "linear.app", + scope: "ENG", + }; + const held = new Map([ + [environmentId, hold(answer({ trackers: [tracker({})], entries: [], scopes: [scope] }))], + ]); + expect(issueFilterScopes(held, [])).toEqual([{ environmentId, input: scope }]); + }); + it("skips a tracker that cannot be read", () => { const held = new Map([ [ diff --git a/packages/client-runtime/src/issueList.ts b/packages/client-runtime/src/issueList.ts index c1ade3fc9002..34d421231382 100644 --- a/packages/client-runtime/src/issueList.ts +++ b/packages/client-runtime/src/issueList.ts @@ -189,30 +189,32 @@ export function issueFilterScopes( input: { projectId: project.id, tracker: tracker.tracker, host, scope }, }); } - // A tracker bound in settings (a Linear team) is no repository's; its rows name its scope. - for (const entry of page.entries) { + // A tracker bound in settings (a Linear team) is no repository's; the answer names its scope, + // matched or not. Older servers do not, so their rows stand in. + const covered: ReadonlyArray = + page.answer.scopes ?? + page.entries.map(({ projectId, tracker, host, scope }) => ({ + projectId, + tracker, + host, + scope, + })); + for (const input of covered) { + const host = input.host?.toLowerCase(); const tracker = page.answer.trackers.find( - (t) => t.tracker === entry.tracker && t.host.toLowerCase() === entry.host.toLowerCase(), + (t) => t.tracker === input.tracker && t.host.toLowerCase() === host, ); if (!tracker?.configured) continue; if (!tracker.capabilities?.labels && !tracker.capabilities?.assignees) continue; if ( scopes.some( (s) => - s.input.scope.toLowerCase() === entry.scope.toLowerCase() && - s.input.host?.toLowerCase() === entry.host.toLowerCase(), + s.input.scope.toLowerCase() === input.scope.toLowerCase() && + s.input.host?.toLowerCase() === host, ) ) continue; - scopes.push({ - environmentId, - input: { - projectId: entry.projectId, - tracker: entry.tracker, - host: entry.host, - scope: entry.scope, - }, - }); + scopes.push({ environmentId, input }); } } return scopes; diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index b2fc5532dac4..acd0eed54a42 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -308,6 +308,11 @@ export const IssueListResult = Schema.Struct({ errors: Schema.Array(IssueListProjectError), /** Where each scope carries on, sent straight back as `cursors`. Absent once a scope is done. */ nextCursors: IssueListCursors, + /** + * Every scope the listing covers, matched or not, with one project that reads it. A Linear team + * bound in settings is named nowhere else. Absent from servers that predate it. + */ + scopes: Schema.optional(Schema.Array(IssueScopeRef)), }); export type IssueListResult = typeof IssueListResult.Type;