mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 16:02:43 +00:00
* feat(sidebar): link Linear issues from Edit Worktree Details The Issue field only accepted GitHub numbers, so a workspace tracking a Linear issue had no way to say so from the dialog — the link could only be set at creation time or through `orca worktree set --linear-issue`. Replaces the field with one provider-aware row: a chip suffix inside the input selects GitHub or Linear, and pasting a URL flips the chip to match. A bare key never steers the provider — Linear and Jira issue keys are byte-identical in shape, so shape alone cannot decide one. One issue per workspace. A changed field displaces the other provider's slot and the row names what Save is about to unlink. GitLab and Jira links are left alone: the row cannot display them, and nothing else in the UI could restore one it dropped. - Folder workspaces read-only (their link is creation-time only) - Remote runtimes assert the capability before writing or clearing, since `worktree.set` parses in strip mode and would silently drop the keys - `updateWorktreeMeta` now reports failure so the dialog can stay open instead of closing over a save that refetch reverted - Parses are length-bounded — `matchGitHubItemPath` strips trailing slashes with an unanchored regex that is quadratic on a large paste * fix(sidebar): respect one-issue-per-workspace rule conditionally Only clear displaced issue links when they actually existed, preventing unnecessary Linear keys in GitHub-only workspaces. Skip comment updates when unchanged to avoid workspace reordering. Add accessibility to displacement messages and improve folder workspace error handling. * fix(sidebar): resolve workspace ambiguity and improve Linear issue linki The same workspace ID can exist under multiple hosts — the owner index reports this as ambiguous rather than guessing. Dialog callers now pass their repoId so lookups are unambiguous. Linear identifiers without an org key are resolved across all workspaces (not just the active organization). Added race-condition protection for async issue lookups and better change detection to avoid clearing work-item titles when re-saving an identifier in different spelling.
76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
import { parseGitHubIssueOrPRLink } from './github-links'
|
|
import { parseLinearIssueInput } from './linear-links'
|
|
import type { WorkspaceSourceProvider } from './new-workspace/workspace-source'
|
|
|
|
// Why: narrows the canonical provider union instead of minting a parallel one,
|
|
// so adding Jira here is a one-entry change rather than a new axis.
|
|
export const ISSUE_LINK_PROVIDERS = [
|
|
'github',
|
|
'linear'
|
|
] as const satisfies readonly WorkspaceSourceProvider[]
|
|
|
|
export type IssueLinkProvider = (typeof ISSUE_LINK_PROVIDERS)[number]
|
|
|
|
export function isIssueLinkProvider(value: unknown): value is IssueLinkProvider {
|
|
return ISSUE_LINK_PROVIDERS.includes(value as IssueLinkProvider)
|
|
}
|
|
|
|
/** URL input only. Linear and Jira issue keys are byte-identical in shape, so a
|
|
* bare `STA-335` can never decide a provider — it would override the chip. */
|
|
export function getIssueLinkProviderFromUrl(input: string): IssueLinkProvider | null {
|
|
const trimmed = input.trim()
|
|
if (!/^https?:\/\//i.test(trimmed)) {
|
|
return null
|
|
}
|
|
|
|
// Why: a URL is decisive only if it names that provider's *issue*. A GitHub
|
|
// pull URL is a valid GitHub link but not an issue, and must not flip the
|
|
// provider into a state where the field then refuses to save it.
|
|
if (parseGitHubIssueOrPRLink(trimmed)?.type === 'issue') {
|
|
return 'github'
|
|
}
|
|
if (parseLinearIssueInput(trimmed)) {
|
|
return 'linear'
|
|
}
|
|
return null
|
|
}
|
|
|
|
export type ParsedIssueLinkInput =
|
|
| { provider: 'github'; number: number }
|
|
| { provider: 'linear'; identifier: string; organizationUrlKey?: string }
|
|
|
|
/**
|
|
* Single parse shared by the dialog's save gate and its payload builder, so a
|
|
* value that enables Save is always the value that gets written.
|
|
*/
|
|
export function parseIssueLinkInput(
|
|
input: string,
|
|
provider: IssueLinkProvider
|
|
): ParsedIssueLinkInput | null {
|
|
const trimmed = input.trim()
|
|
if (!trimmed) {
|
|
return null
|
|
}
|
|
|
|
if (provider === 'linear') {
|
|
const parsed = parseLinearIssueInput(trimmed)
|
|
return parsed ? { provider: 'linear', ...parsed } : null
|
|
}
|
|
|
|
const link = parseGitHubIssueOrPRLink(trimmed)
|
|
if (link) {
|
|
// Why: issue and PR numbers live in separate GitHub namespaces for refs; a
|
|
// pull URL pasted here must not silently become an issue link.
|
|
return link.type === 'issue' ? { provider: 'github', number: link.number } : null
|
|
}
|
|
|
|
const numeric = trimmed.startsWith('#') ? trimmed.slice(1) : trimmed
|
|
if (!/^\d+$/.test(numeric)) {
|
|
return null
|
|
}
|
|
const parsed = Number.parseInt(numeric, 10)
|
|
// Why: `/^\d+$/` happily accepts 400 digits, which parseInt turns into
|
|
// Infinity — Save would enable and JSON.stringify would persist `null`.
|
|
return Number.isSafeInteger(parsed) && parsed > 0 ? { provider: 'github', number: parsed } : null
|
|
}
|