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.

2.9 KB
Raw Blame
import type {
  PRCheckAnnotation,
  PRCheckJob,
  PRCheckRunDetails
} from '../../../../src/shared/github/check-types'
import { resolveStepOutcome, summarizeJobSteps } from '../../../../src/shared/pr-check-step-status'
import { translate } from '../../i18n/mobile-i18n'

// Map check payload to desktop-equivalent summary/annotations/failed jobs without React/RN imports for Node tests.

// Desktop caps the inline lists so a noisy check can't break the layout; match it.
const MAX_ANNOTATIONS = 20
const MAX_JOBS = 100

export type CheckDetailAnnotation = {
  locator: string
  level: string | null
  title: string | null
  message: string
}

export type CheckDetailStep = {
  name: string
  state: string
}

export type CheckDetailJob = {
  name: string
  state: string
  failedSteps: CheckDetailStep[]
  logTail: string | null
}

export type CheckDetailContent = {
  summaryLines: string[]
  annotations: CheckDetailAnnotation[]
  annotationsTruncated: boolean
  jobsLabel: string
  jobs: CheckDetailJob[]
  jobsTruncated: boolean
}

function mapAnnotation(annotation: PRCheckAnnotation): CheckDetailAnnotation {
  const path =
    annotation.path ?? translate('pullRequest.prCheckDetailContent.annotation', 'Annotation')
  const locator = annotation.startLine ? `${path}:${annotation.startLine}` : path
  return {
    locator,
    level: annotation.annotationLevel,
    title: annotation.title,
    message: annotation.message
  }
}

function mapJob(job: PRCheckJob): CheckDetailJob {
  const failedSteps = summarizeJobSteps(job).failed.map((step) => ({
    name: step.name,
    state:
      step.conclusion ??
      step.status ??
      translate('pullRequest.prCheckDetailContent.unknown', 'unknown')
  }))
  return {
    name: job.name,
    state:
      job.conclusion ??
      job.status ??
      translate('pullRequest.prCheckDetailContent.unknown', 'unknown'),
    failedSteps,
    logTail: job.logTail
  }
}

export function presentCheckDetail(details: PRCheckRunDetails): CheckDetailContent {
  const summaryLines = [
    details.conclusion ?? details.status,
    details.title,
    details.summary
  ].filter((line): line is string => typeof line === 'string' && line.trim().length > 0)

  // Prefer actionable failed jobs; show all only when none fail, matching desktop.
  const failedJobs = details.jobs.filter((job) => resolveStepOutcome(job) === 'failure')
  const visibleJobs = failedJobs.length > 0 ? failedJobs : details.jobs

  return {
    summaryLines,
    annotations: details.annotations.slice(0, MAX_ANNOTATIONS).map(mapAnnotation),
    annotationsTruncated: details.annotations.length > MAX_ANNOTATIONS,
    jobsLabel:
      failedJobs.length > 0
        ? translate('pullRequest.prCheckDetailContent.failedJobs', 'Failed jobs')
        : translate('pullRequest.prCheckDetailContent.jobs', 'Jobs'),
    jobs: visibleJobs.slice(0, MAX_JOBS).map(mapJob),
    jobsTruncated: details.jobs.length > MAX_JOBS
  }
}