Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.0 KB
Raw Blame
import type { JiraIssue, JiraSite } from '../../../src/shared/jira/jira-types'
import {
  getMatchingJiraSites,
  isResolvedJiraIssueMatch,
  parseJiraIssueUrl
} from '../../../src/shared/jira/jira-issue-url'
import type { RpcOperationSender } from '../transport/rpc-operation-sender'
import { jiraIssueRead } from './mobile-jira-operations'

// Match a connected site before resolving keys that may exist on several sites.
export async function lookupJiraIssueByUrl(
  client: RpcOperationSender,
  value: string,
  sites: readonly JiraSite[]
): Promise<JiraIssue | null> {
  const parsed = parseJiraIssueUrl(value)
  if (!parsed) {
    return null
  }
  for (const site of getMatchingJiraSites(parsed, sites)) {
    // Another connected account for this origin may have access.
    const issue = await jiraIssueRead
      .request(client, { key: parsed.issueKey, siteId: site.id })
      .then((reply) => jiraIssueRead.interpret(reply))
      .catch(() => null)
    if (issue && isResolvedJiraIssueMatch(parsed, site, issue)) {
      return issue
    }
  }
  return null
}