Files
orca/src/shared/task-source-context.ts
T
Jinjing 74563b6498 feat(jira): link Jira issues from the workspace create dialog (#11296)
* Link Jira issues from workspace create dialog

Add Jira issue linking to workspace creation, matching existing GitHub and Linear workflows. Users can paste Jira issue URLs in the smart name field to auto-populate workspace names and link the issue to the created workspace/worktree.

Linked Jira issues appear on workspace cards via the new 'jira-issue' card property. Implements cancellable searches and summary reads to prevent stalled requests from blocking the shared Jira pool. Persists paired issue + source context metadata with validation of provider/site identity.

Fixes git-username rate-limit handling to reject malformed JSON responses so garbage never becomes branch prefixes.

* feat(jira): link issues during workspace creation

- Display linked Jira issues on worktree cards
- Fetch issue summaries and timestamps via Jira API
- Gate Jira linking behind runtime capability check
- Preserve user-typed names during async lookups

* Enforce git check-ref-format rules in login validation

Extend isBranchSafeHostedLogin to reject usernames that git rejects as
invalid branch components: trailing dots, consecutive dots, and .lock
suffix. Prevents invalid branch names from login usernames.

* Enforce filesystem filename cap for branch-safe logins

Loose refs store logins as single filenames, so the real constraint is the
255-byte filesystem cap, not git check-ref-format rules. This allows longer
provider-agnostic logins while staying platform-safe.
2026-07-29 19:50:18 -07:00

241 lines
7.0 KiB
TypeScript

import {
LOCAL_EXECUTION_HOST_ID,
type ExecutionHostId,
normalizeExecutionHostId,
parseExecutionHostId,
toRuntimeExecutionHostId,
toSshExecutionHostId
} from './execution-host'
import {
areTaskProviderIdentitiesEqual,
isStoredTaskProviderIdentity,
normalizeTaskProviderIdentity,
taskProviderIdentityCachePart,
type TaskProviderIdentity
} from './task-provider-identity'
import type { TaskProvider } from './task-providers'
import type { GlobalSettings, Repo } from './types'
export type {
GitHubTaskProviderIdentity,
GitLabTaskProviderIdentity,
JiraTaskProviderIdentity,
LinearTaskProviderIdentity,
TaskProviderIdentity
} from './task-provider-identity'
export type { TaskProvider } from './task-providers'
export type TaskSourceContext = {
kind: 'task-source'
provider: TaskProvider
projectId: string
hostId: ExecutionHostId
projectHostSetupId?: string | null
repoId?: string | null
providerIdentity?: TaskProviderIdentity | null
accountLabel?: string | null
}
export type WorkspaceRunContext = {
kind: 'workspace-run'
projectId: string
hostId: ExecutionHostId
projectHostSetupId: string
repoId: string
path: string
}
export type TaskSourceContextInput = Omit<TaskSourceContext, 'kind' | 'hostId'> & {
kind?: 'task-source'
hostId?: string | null
}
export function normalizeTaskSourceContext(
input: TaskSourceContextInput
): TaskSourceContext | null {
const projectId = normalizeNonEmptyString(input.projectId)
if (!projectId) {
return null
}
const provider = normalizeTaskProvider(input.provider)
if (!provider) {
return null
}
return {
kind: 'task-source',
provider,
projectId,
hostId: normalizeExecutionHostId(input.hostId) ?? LOCAL_EXECUTION_HOST_ID,
projectHostSetupId: normalizeNonEmptyString(input.projectHostSetupId),
repoId: normalizeNonEmptyString(input.repoId),
providerIdentity: normalizeTaskProviderIdentity(provider, input.providerIdentity),
accountLabel: normalizeNonEmptyString(input.accountLabel)
}
}
export function normalizeStoredTaskSourceContext(value: unknown): TaskSourceContext | null {
if (!value || typeof value !== 'object') {
return null
}
const input = value as Record<string, unknown>
const provider = normalizeTaskProvider(input.provider)
if (
!provider ||
typeof input.projectId !== 'string' ||
(input.kind !== undefined && input.kind !== 'task-source') ||
!isNullableOptionalString(input.hostId) ||
!isNullableOptionalString(input.projectHostSetupId) ||
!isNullableOptionalString(input.repoId) ||
!isNullableOptionalString(input.accountLabel) ||
!isStoredTaskProviderIdentity(provider, input.providerIdentity)
) {
return null
}
if (
typeof input.hostId === 'string' &&
input.hostId.trim().length > 0 &&
normalizeExecutionHostId(input.hostId) === null
) {
return null
}
return normalizeTaskSourceContext(input as TaskSourceContextInput)
}
export function buildTaskSourceContextFromRepo(args: {
provider: TaskProvider
projectId: string
repo: Pick<Repo, 'id' | 'connectionId' | 'executionHostId'>
projectHostSetupId?: string | null
providerIdentity?: TaskProviderIdentity | null
accountLabel?: string | null
}): TaskSourceContext | null {
return normalizeTaskSourceContext({
provider: args.provider,
projectId: args.projectId,
hostId: getRepoHostId(args.repo),
repoId: args.repo.id,
projectHostSetupId: args.projectHostSetupId,
providerIdentity: args.providerIdentity,
accountLabel: args.accountLabel
})
}
export function areTaskSourceContextsEqual(
a: TaskSourceContext | null | undefined,
b: TaskSourceContext | null | undefined
): boolean {
if (a === b) {
return true
}
if (!a || !b) {
return !a && !b
}
return (
a.provider === b.provider &&
a.projectId === b.projectId &&
a.hostId === b.hostId &&
(a.projectHostSetupId ?? null) === (b.projectHostSetupId ?? null) &&
(a.repoId ?? null) === (b.repoId ?? null) &&
(a.accountLabel ?? null) === (b.accountLabel ?? null) &&
areTaskProviderIdentitiesEqual(a.providerIdentity, b.providerIdentity)
)
}
export function getTaskSourceRuntimeSettings(
context: Pick<TaskSourceContext, 'hostId'> | null | undefined
): Pick<GlobalSettings, 'activeRuntimeEnvironmentId'> {
const parsed = parseExecutionHostId(context?.hostId)
return {
activeRuntimeEnvironmentId: parsed?.kind === 'runtime' ? parsed.environmentId : null
}
}
export function getTaskSourceCacheScope(
context: Pick<TaskSourceContext, 'provider' | 'hostId' | 'projectId' | 'projectHostSetupId'> & {
providerIdentity?: TaskProviderIdentity | null
repoId?: string | null
}
): string {
return [
context.provider,
context.hostId,
context.projectId,
context.projectHostSetupId ?? '',
context.repoId ?? '',
taskProviderIdentityCachePart(context.providerIdentity)
]
.map(encodeCachePart)
.join(':')
}
export function buildWorkspaceRunContext(args: {
projectId: string
hostId: string | null | undefined
projectHostSetupId: string
repoId: string
path: string
}): WorkspaceRunContext | null {
const projectId = normalizeNonEmptyString(args.projectId)
const projectHostSetupId = normalizeNonEmptyString(args.projectHostSetupId)
const repoId = normalizeNonEmptyString(args.repoId)
const repoPath = normalizeNonEmptyString(args.path)
if (!projectId || !projectHostSetupId || !repoId || !repoPath) {
return null
}
return {
kind: 'workspace-run',
projectId,
hostId: normalizeExecutionHostId(args.hostId) ?? LOCAL_EXECUTION_HOST_ID,
projectHostSetupId,
repoId,
path: repoPath
}
}
export function getWorkspaceRunRuntimeSettings(
context: Pick<WorkspaceRunContext, 'hostId'> | null | undefined
): Pick<GlobalSettings, 'activeRuntimeEnvironmentId'> {
return getTaskSourceRuntimeSettings(context ? { hostId: context.hostId } : null)
}
function getRepoHostId(repo: Pick<Repo, 'connectionId' | 'executionHostId'>): ExecutionHostId {
const explicit = normalizeExecutionHostId(repo.executionHostId)
if (explicit) {
return explicit
}
const connectionId = normalizeNonEmptyString(repo.connectionId)
return connectionId ? toSshExecutionHostId(connectionId) : LOCAL_EXECUTION_HOST_ID
}
function normalizeTaskProvider(value: unknown): TaskProvider | null {
switch (value) {
case 'github':
case 'gitlab':
case 'linear':
case 'jira':
return value
default:
return null
}
}
function normalizeNonEmptyString(value: unknown): string | null {
const trimmed = typeof value === 'string' ? value.trim() : ''
return trimmed ? trimmed : null
}
function isNullableOptionalString(value: unknown): boolean {
return value === undefined || value === null || typeof value === 'string'
}
function encodeCachePart(value: string): string {
return encodeURIComponent(value)
}
export function runtimeHostIdFromEnvironmentId(
environmentId: string | null | undefined
): ExecutionHostId {
const trimmed = normalizeNonEmptyString(environmentId)
return trimmed ? toRuntimeExecutionHostId(trimmed) : LOCAL_EXECUTION_HOST_ID
}