Repository navigation
feat(issues): bind projects to multiple Linear teams #38360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
50e68cf
01bc482
04fe2a0
310f8c2
ba7e639
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,8 @@ export class IssueService extends Context.Service< | |
| /** The tracker and container a project's own issues live in. */ | ||
| readonly projectScope: ( | ||
| projectId: ProjectId, | ||
| scope?: string, | ||
| key?: string, | ||
| ) => Effect.Effect<IssueScopeRef & { readonly host: string }, IssueError>; | ||
| /** | ||
| * Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only. | ||
|
|
@@ -192,17 +194,21 @@ const make = Effect.gen(function* () { | |
| // Read per resolution so a binding saved in Settings applies without a restart. | ||
| const resolveStandaloneBinding = ( | ||
| project: OrchestrationProjectShell, | ||
| ): Effect.Effect<ProjectTrackerBinding | null, IssueOperationError> => | ||
| ): Effect.Effect<ReadonlyArray<ProjectTrackerBinding>, IssueOperationError> => | ||
| bindings.list.pipe( | ||
| Effect.map((bound) => { | ||
| const binding = bound.get(project.id); | ||
| const api = binding === undefined ? null : registry.get(binding.tracker); | ||
| if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return null; | ||
| return { | ||
| if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return []; | ||
| const scopes = new Map<string, string>(); | ||
| for (const scope of [binding.scope, ...(binding.additionalScopes ?? [])]) { | ||
| if (!scopes.has(scope.toLowerCase())) scopes.set(scope.toLowerCase(), scope); | ||
| } | ||
| return [...scopes.values()].map((scope) => ({ | ||
| tracker: binding.tracker, | ||
| host: api.standalone.host, | ||
| scope: binding.scope, | ||
| }; | ||
| scope, | ||
| })); | ||
| }), | ||
| // A failed read is not an unbound project: that would list the git host's issues alone. | ||
| Effect.mapError( | ||
|
|
@@ -232,7 +238,11 @@ const make = Effect.gen(function* () { | |
| resolveGitHostBinding({ ...project, repositoryIdentity }), | ||
| ), | ||
| ), | ||
| ]).pipe(Effect.map((resolved) => resolved.filter((binding) => binding !== null))); | ||
| ]).pipe( | ||
| Effect.map(([standalone, gitHost]) => | ||
| gitHost === null ? standalone : [...standalone, gitHost], | ||
| ), | ||
| ); | ||
|
|
||
| const listProjects = (filter: { | ||
| readonly projectId?: IssueListInput["projectId"]; | ||
|
|
@@ -306,7 +316,12 @@ const make = Effect.gen(function* () { | |
| return Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" })); | ||
| } | ||
| const scope = ref.scope.trim(); | ||
| const writable = scope.toLowerCase() === own.scope.toLowerCase(); | ||
| const writable = supported.some( | ||
| (candidate) => | ||
| candidate.tracker === own.tracker && | ||
| candidate.host === own.host && | ||
| candidate.scope.toLowerCase() === scope.toLowerCase(), | ||
| ); | ||
| return Effect.succeed({ ...own, scope, writable }); | ||
| }), | ||
| ); | ||
|
|
@@ -354,7 +369,11 @@ const make = Effect.gen(function* () { | |
| } | ||
|
|
||
| // Every project counts, including worktrees of a scope read once below. | ||
| const countedProjects = new Set<string>(); | ||
| for (const project of supported) { | ||
| const key = `${project.host} ${project.project.id}`; | ||
| if (countedProjects.has(key)) continue; | ||
| countedProjects.add(key); | ||
| const existing = trackers.get(project.host); | ||
| trackers.set( | ||
| project.host, | ||
|
|
@@ -651,12 +670,26 @@ const make = Effect.gen(function* () { | |
|
|
||
| const projectScope: IssueService["Service"]["projectScope"] = Effect.fn( | ||
| "IssueService.projectScope", | ||
| )(function* (projectId) { | ||
| )(function* (projectId, scope, key) { | ||
| const { supported } = yield* listProjects({ projectId }); | ||
| const [own] = supported; | ||
| if (own === undefined) { | ||
| if (supported.length === 0) { | ||
| return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); | ||
| } | ||
| const keyScope = key?.match(/^(.+)-\d+$/)?.[1]?.toLowerCase(); | ||
| const own = | ||
| scope === undefined | ||
| ? (supported.find((candidate) => candidate.scope.toLowerCase() === keyScope) ?? | ||
| supported[0]) | ||
| : supported.find( | ||
| (candidate) => candidate.scope.toLowerCase() === scope.trim().toLowerCase(), | ||
| ); | ||
| if (own === undefined) { | ||
| return yield* new IssueOperationError({ | ||
| operation: "projectScope", | ||
| detail: | ||
| "This project is not bound to that issue scope. Use list_issues to find its bound scopes.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return bound scopes from If OPS has no matching issues, an agent that mistypes
|
||
| }); | ||
| } | ||
| return { projectId, tracker: own.tracker, host: own.host, scope: own.scope }; | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,14 +90,18 @@ const make = Effect.gen(function* () { | |
| /** Where a key-only reference is read: the named project's tracker, or the caller's thread's. */ | ||
| const requireProjectScope = Effect.fn("IssuesToolkit.requireProjectScope")(function* ( | ||
| requested: ProjectId | undefined, | ||
| scope?: string, | ||
| key?: string, | ||
| ) { | ||
| // A named project skips the caller's thread, so the capability is checked here too. | ||
| yield* McpInvocationContext.requireMcpCapability("issues"); | ||
| const projectId = requested ?? (yield* callerThread())?.projectId; | ||
| if (projectId === undefined) return yield* new IssueProjectRequiredError(); | ||
| return yield* issues | ||
| .projectScope(projectId) | ||
| .pipe(Effect.mapError(() => new IssueProjectNotFoundError({ projectId }))); | ||
| return yield* issues.projectScope(projectId, scope, key).pipe( | ||
| Effect.catchTags({ | ||
| IssueUnavailableError: () => Effect.fail(new IssueProjectNotFoundError({ projectId })), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| /** | ||
|
|
@@ -115,7 +119,7 @@ const make = Effect.gen(function* () { | |
| return { ...resolved, url: input.url } satisfies ResolvedTarget; | ||
| } | ||
| if (input.key === undefined) return yield* new IssueTargetIncompleteError(); | ||
| const scope = yield* requireProjectScope(input.projectId); | ||
| const scope = yield* requireProjectScope(input.projectId, undefined, input.key); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key-only For a key-only reference, the target resolves to the default team when the key's team is unbound. Make key-only unlink able to remove a saved link whose scope is unbound. When such a link is removed, report
|
||
| return { | ||
| ...scope, | ||
| key: input.key, | ||
|
|
@@ -230,7 +234,7 @@ const make = Effect.gen(function* () { | |
| ), | ||
| create_issue: McpToolAccess.writesWithCapability((input) => | ||
| Effect.gen(function* () { | ||
| const scope = yield* requireProjectScope(input.projectId); | ||
| const scope = yield* requireProjectScope(input.projectId, input.scope); | ||
| const created = yield* issues.create({ | ||
| ...scope, | ||
| title: input.title, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identify the default team in mobile settings.
If OPS and DEV are both selected, the menu marks both as on and the row lists their names without identifying the default. Users cannot tell which team an agent will use without a
scopeargument. Mark the first bound team as the default in the row or menu, using a localized label. (raw.githubusercontent.com)