import { useState } from 'react' import { ErrorPanel, PanelNote } from '@/shared/ui' import type { MessageKey } from '@/shared/i18n' import { useAsync } from '@/shared/lib' import { useT } from '@/shared/i18n' import { getPullChecks, type PullRef } from '@/entities/pull-request' import { Copyable } from './parts' type CheckState = { labelKey: MessageKey | null; tone: string } const STATUS_STATE: Record = { pending: { labelKey: 'pull.checks.waiting', tone: 'text-shell-ink-muted' }, success: { labelKey: 'pull.checks.success', tone: 'text-[#1a7f37]' }, failure: { labelKey: 'pull.checks.failed', tone: 'text-[#b42318]' }, error: { labelKey: 'pull.checks.error', tone: 'text-[#b42318]' }, } /** 检查页签:最新 head 的提交状态。 */ export function ChecksTab({ refObj, headSha }: { refObj: PullRef; headSha: string }) { const { t } = useT() const [tick, setTick] = useState(0) const checks = useAsync(() => getPullChecks(refObj), [refObj.space, refObj.repo, refObj.pull, tick]) const failure = checks.error as { code?: number; message?: string } | undefined if (checks.loading && !checks.data) return if (failure) return setTick(tick => tick + 1)} /> const data = checks.data if (!data) return const statuses = data.statuses ?? [] if (!statuses.length) { return } return (

{t('pull.checks.version')}

{statuses.map((status, index) => { const hit = STATUS_STATE[status.state] ?? { labelKey: null, tone: 'text-shell-ink-muted' } return (
{status.context} {hit.labelKey ? t(hit.labelKey) : status.state} {status.description ? {status.description} : null} {status.target_url ? ( ) : null}
) })}
) }