Files
orca/src/shared/issue-link-input.ts
T
Neil 583ab1601b refactor(shared): group worktree, github, and linear modules into folders (#14437)
`src/shared` is a flat directory of ~1,150 entries. The worktree, github, and
linear domains accounted for 71 of them, so finding the module you wanted meant
scanning a wall of same-prefixed filenames.

Move each domain into its own folder and drop the now-redundant prefix:

    src/shared/github-pr-types.ts    -> src/shared/github/pull-request-types.ts
    src/shared/worktree-id.ts        -> src/shared/worktree/id.ts
    src/shared/linear-links.ts       -> src/shared/linear/links.ts

This follows the existing `network/` and `new-workspace/` convention in the
same directory, which also drop the prefix inside the folder.

Whole clusters move, including tests. Foldering only part of a domain would be
worse than flat: a reader would have to check both `github/` and the flat
directory, and `github-auth-types.ts` / `github-project-types.ts` are type
modules that belong with the rest. No files with these prefixes remain flat.

Import specifiers were rewritten by resolving each one to an absolute path and
recomputing it, not by string substitution, so the `@/../../shared/...` alias
forms are handled correctly. 501 specifiers across 298 files.

Two things `tsc` cannot catch, handled explicitly:

- `github-project-types.ts` carries its own `max-lines` bypass, so its baseline
  entry is REPOINTED to the new path rather than pruned. Pruning would drop the
  bypass and then flag the new path as a fresh violation. Ratchet stays at 345.
- `mobile/` is outside `pnpm typecheck` and cannot be typechecked here
  (`mobile/node_modules` is empty). Instead every relative specifier in the repo
  was resolved against the filesystem: 174 unresolved before this change and 174
  after — identical, so nothing broke in mobile either.

The pinned `tests/e2e/.cross-version-checkouts` fixtures are deliberately NOT
rewritten; they are a snapshot of an older release and still reference the old
paths.

Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted
first — these projects are `composite: true` and reuse stale caches).
2026-08-13 20:44:16 -07:00

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
}