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.

3.5 KB
Raw Blame
import type { MrStateFilter, SmartNameMode } from './mobile-composer-source-types'
import { translate } from '../i18n/mobile-i18n'

// Lucide has no brand icons; provider modes use TaskProviderLogo SVGs.
export type SmartModeIcon =
  | { type: 'lucide'; name: 'sparkles' | 'git-branch' | 'case-sensitive' }
  | { type: 'provider'; provider: 'github' | 'gitlab' | 'linear' | 'jira' }

export type SmartModeOption = {
  id: SmartNameMode
  label: string
  icon: SmartModeIcon
}

export const SMART_MODE_OPTIONS: readonly SmartModeOption[] = [
  {
    id: 'smart',
    get label() {
      return translate('tasks.smartSourceModes.smart', 'Smart')
    },
    icon: { type: 'lucide', name: 'sparkles' }
  },
  { id: 'github', label: 'GitHub', icon: { type: 'provider', provider: 'github' } },
  { id: 'linear', label: 'Linear', icon: { type: 'provider', provider: 'linear' } },
  { id: 'jira', label: 'Jira', icon: { type: 'provider', provider: 'jira' } },
  { id: 'gitlab', label: 'GitLab', icon: { type: 'provider', provider: 'gitlab' } },
  {
    id: 'branches',
    get label() {
      return translate('tasks.smartSourceModes.branch', 'Branch')
    },
    icon: { type: 'lucide', name: 'git-branch' }
  },
  {
    id: 'text',
    get label() {
      return translate('tasks.smartSourceModes.name', 'Name')
    },
    icon: { type: 'lucide', name: 'case-sensitive' }
  }
]

export type SmartModeAvailabilityInput = {
  textOnly: boolean
  tasksSupported: boolean
  hasRepo: boolean
  githubAvailable: boolean
  gitlabAvailable: boolean
  linearAvailable: boolean
  jiraAvailable: boolean
}

export function resolveAvailableSmartModes(input: SmartModeAvailabilityInput): SmartNameMode[] {
  if (input.textOnly) {
    return ['text']
  }
  return SMART_MODE_OPTIONS.filter((option) => {
    switch (option.id) {
      case 'smart':
        return input.tasksSupported
      case 'github':
        return input.tasksSupported && input.hasRepo && input.githubAvailable
      case 'gitlab':
        return input.tasksSupported && input.hasRepo && input.gitlabAvailable
      case 'linear':
        return input.tasksSupported && input.linearAvailable
      case 'jira':
        // Jira is not repo-scoped; it needs no selected repo.
        return input.tasksSupported && input.jiraAvailable
      case 'branches':
        return input.hasRepo
      case 'text':
        return true
    }
  }).map((option) => option.id)
}

export function resolveDefaultSmartMode(input: SmartModeAvailabilityInput): SmartNameMode {
  const available = resolveAvailableSmartModes(input)
  if (available.includes('smart')) {
    return 'smart'
  }
  return available[0] ?? 'text'
}

export function normalizeSmartMode(
  mode: SmartNameMode,
  input: SmartModeAvailabilityInput
): SmartNameMode {
  const available = resolveAvailableSmartModes(input)
  return available.includes(mode) ? mode : resolveDefaultSmartMode(input)
}

export type MrStateFilterOption = { id: MrStateFilter; label: string }

export const MR_STATE_FILTER_OPTIONS: readonly MrStateFilterOption[] = [
  {
    id: 'opened',
    get label() {
      return translate('tasks.smartSourceModes.openState', 'Open')
    }
  },
  {
    id: 'merged',
    get label() {
      return translate('tasks.smartSourceModes.mergedState', 'Merged')
    }
  },
  {
    id: 'closed',
    get label() {
      return translate('tasks.smartSourceModes.closedState', 'Closed')
    }
  },
  {
    id: 'all',
    get label() {
      return translate('tasks.smartSourceModes.allStates', 'All')
    }
  }
]

export const DEFAULT_MR_STATE_FILTER: MrStateFilter = 'opened'