Skip to content
6 changes: 6 additions & 0 deletions apps/server/src/issue/IssueService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/issue/IssueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})),
};
});

Expand Down
13 changes: 13 additions & 0 deletions packages/client-runtime/src/issueList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
[
Expand Down
30 changes: 16 additions & 14 deletions packages/client-runtime/src/issueList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IssueScopeRef> =
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;
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/src/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading