Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions apps/server/src/issue/IssueService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,18 +583,25 @@ describe("IssueService with a standalone tracker", () => {
expect(
yield* service.resolveUrl("https://linear.app/acme/issue/ENG-1/old-title"),
).toMatchObject({ key: "ENG-1", writable: true });
const refused = yield* service
.resolveUrl("https://linear.app/other-workspace/issue/ENG-1/old-title")
.pipe(Effect.result);
expect(refused).toMatchObject({
const otherWorkspace = "https://linear.app/other-workspace/issue/ENG-1/old-title";
// Bound or not, the link must name the workspace the environment's credential reaches.
const unbound = yield* makeService({
projects: [project({ id: "notes" })],
trackers: [fakeStandaloneTracker()],
});
const refusal = {
_tag: "Failure",
failure: {
_tag: "IssueOperationError",
operation: "resolveUrl",
reason: "not-found",
detail: "This issue URL does not belong to the connected workspace.",
},
});
};
expect(yield* service.resolveUrl(otherWorkspace).pipe(Effect.result)).toMatchObject(refusal);
expect(
yield* unbound.resolveUrl(otherWorkspace, "notes" as ProjectId).pipe(Effect.result),
).toMatchObject(refusal);
}),
);

Expand Down Expand Up @@ -682,17 +689,38 @@ describe("IssueService with a standalone tracker", () => {
},
});

// Unbound, the standalone scope is gone and its references are unsupported.
// Another team on the bound tracker is served by the project, read-only.
const otherTeam = { ...linearRef, scope: "OPS", key: "OPS-1" };
expect(yield* bound.detail(otherTeam)).toMatchObject({ scope: "OPS", writable: false });
expect(yield* Effect.flip(bound.update({ ...otherTeam, title: "Renamed" }))).toMatchObject({
_tag: "IssueOperationError",
reason: "read-only",
});

// Unbound, the standalone scope leaves the listing, but the environment's credential still
// serves references, from a project with no repository (No project) too.
listed.length = 0;
const unbound = yield* makeService({ projects, trackers });
const after = yield* unbound.list({ state: "open" });
expect(listed).toEqual(["github github.com acme/web"]);
expect(after.trackers.map((tracker) => tracker.tracker)).toEqual(["github"]);
const refused = yield* Effect.flip(unbound.detail(linearRef));
expect(refused).toMatchObject({
_tag: "IssueUnavailableError",
reason: "tracker-unsupported",
const noProjectRef = { ...linearRef, projectId: "notes" as ProjectId };
expect(yield* unbound.detail(noProjectRef)).toMatchObject({
projectId: "notes",
host: "linear.app",
writable: true,
});
yield* unbound.comment({ ...noProjectRef, body: "Follow-up" });
yield* unbound.setState({ ...noProjectRef, state: "Done" });
expect(
yield* unbound.resolveUrl(
"https://linear.app/acme/issue/ENG-1/issue-title",
"notes" as ProjectId,
),
).toMatchObject({ projectId: "notes", host: "linear.app", key: "ENG-1", writable: true });
expect(
yield* Effect.flip(unbound.detail({ ...noProjectRef, host: "linear.example" })),
).toMatchObject({ _tag: "IssueUnavailableError", reason: "tracker-unsupported" });

// A project with no remote at all can still be bound, and then has only the standalone one.
const standaloneOnly = yield* makeService({
Expand Down
88 changes: 68 additions & 20 deletions apps/server/src/issue/IssueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export class IssueService extends Context.Service<
) => Effect.Effect<IssueScopeRef & { readonly host: string }, IssueError>;
/**
* Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only.
* Standalone links must match the workspace in the issue's canonical URL from the connected
* tracker; that read comes back as `issue`, so callers need not read it again.
* A standalone link with no project bound to its tracker resolves through `preferredProjectId`,
* and must match the workspace in the issue's canonical URL from the connected tracker; that
* read comes back as `issue`, so callers need not read it again.
*/
readonly resolveUrl: (
url: string,
Expand Down Expand Up @@ -288,21 +289,63 @@ const make = Effect.gen(function* () {
}),
);

/**
* A project with no binding for a standalone tracker, the No project included, serves its
* references with the environment's credential. The tracker decides what the account may change.
*/
const requireStandaloneProject = (
ref: IssueScopeRef,
api: StandaloneIssueTrackerApi,
): Effect.Effect<SupportedProject & { readonly writable: boolean }, IssueError> => {
const host = ref.host?.trim().toLowerCase();
if (host !== undefined && host !== api.standalone.host) {
return Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" }));
}
return projects.getShell(ref.projectId).pipe(
Effect.mapError(
(cause) =>
new IssueOperationError({
operation: "listProjects",
detail: "The project list could not be read.",
cause,
}),
),
Effect.flatMap(
Option.match({
onNone: () => Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" })),
onSome: (project) =>
Effect.succeed({
project,
api,
tracker: ref.tracker,
host: api.standalone.host,
scope: ref.scope.trim(),
writable: true,
}),
}),
),
);
};

/**
* The project whose checkout and credentials serve a reference, and whether the reference is
* one of the project's own scopes. A reference naming another scope on the same tracker and
* host is served by the project but marked read-only. A project with two trackers serves the
* one the reference names.
* one the reference names, and one with no binding for a standalone tracker still serves it.
*/
const requireProject = (
ref: IssueScopeRef,
): Effect.Effect<SupportedProject & { readonly writable: boolean }, IssueError> =>
listProjects({ projectId: ref.projectId }).pipe(
Effect.flatMap(({ supported }) => {
const host = ref.host?.trim().toLowerCase();
const onHost = supported.filter(
(candidate) =>
candidate.tracker === ref.tracker && (host === undefined || candidate.host === host),
const onTracker = supported.filter((candidate) => candidate.tracker === ref.tracker);
const api = registry.get(ref.tracker);
if (onTracker.length === 0 && api !== null && isStandaloneIssueTracker(api)) {
return requireStandaloneProject(ref, api);
}
const onHost = onTracker.filter(
(candidate) => host === undefined || candidate.host === host,
);
const scope = ref.scope.trim();
const own = onHost.find(
Expand Down Expand Up @@ -730,28 +773,33 @@ const make = Effect.gen(function* () {
onTracker.filter((project) => project.scope.toLowerCase() === gitHost?.link.scopeAlias),
);
const lender = own ?? preferFirst(onTracker);
if (lender === undefined) {
return yield* new IssueUnavailableError({ reason: "tracker-unsupported" });
}
const served = {
...lender,
scope: own === undefined ? link.scope : lender.scope,
writable: own !== undefined,
};
const served =
lender !== undefined
? {
...lender,
scope: own === undefined ? link.scope : lender.scope,
writable: own !== undefined,
}
: standalone !== null && preferredProjectId !== undefined
? yield* requireStandaloneProject(
{ projectId: preferredProjectId, tracker, scope: link.scope },
standalone.api,
)
: yield* new IssueUnavailableError({ reason: "tracker-unsupported" });
const resolved = {
projectId: lender.project.id,
tracker: lender.tracker,
host: lender.host,
projectId: served.project.id,
tracker: served.tracker,
host: served.host,
scope: served.scope,
key: link.key,
writable: served.writable,
};
if (standalone === null) return resolved;
// Team keys repeat across workspaces; only the credential's canonical issue URL identifies one.
const issue = yield* lender.api
const issue = yield* served.api
.getIssue({
cwd: lender.project.workspaceRoot,
host: lender.host,
cwd: served.project.workspaceRoot,
host: served.host,
scope: link.scope,
key: link.key,
})
Expand Down
16 changes: 12 additions & 4 deletions docs/user/source-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,12 @@ The **Views** menu saves and restores a search, filter, and sort setup, as it do
requests.

To list a Linear team's issues beside a project's, connect Linear with an API key under
Settings → Source control & issues, then choose the team for that project there.
Settings → Source control & issues, then choose the team for that project there. The team sets
what the Issues page lists for the project, and where agents in its threads look up an issue by its
key alone or file a new one. An issue linked by its full URL needs no team: once Linear is
connected, an issue from that Linear workspace linked to any thread, No project threads included,
opens beside it.
While no project has a team, you can also change it as far as your Linear account allows.

Select an issue to open it beside the list: description, comments, state changes, linked pull
requests, labels, assignees, and reactions. Linked pull requests open in the same panel. You can
Expand All @@ -386,9 +391,12 @@ allow it. An issue read through a project that does not own its repository is sh

An issue can be kept with a thread the way a pull request can: open it beside the thread (issue
links in the conversation open there) and use **Link to this thread** in its header; **Unlink**
undoes it. Click the issue badge in the thread sidebar to see its issues and pull requests in
**Linked items**. Select an issue there to open it beside the thread. Agents link the issues they
work on with the `link_issue` tool.
undoes it. A Linear link in the conversation opens beside the thread only when a project in the
environment is bound to a Linear team; otherwise it opens in the browser. Click the issue badge in
the thread sidebar to see its issues and pull requests in **Linked items**. Select an issue there
to open it beside the thread. Agents link the issues they work on with the `link_issue` tool, which
takes the URL of any issue in the connected Linear workspace, bound or not. A URL from another Linear
workspace is refused.

Writing to a tracker over a remote connection requires the `source-control:write` scope.

Expand Down
Loading