export type DelegatedMergeResult = { merged?: boolean sha?: string | null status?: string message?: string hint?: string workflowId?: string mergeableState?: string | null } | null | undefined /** * Top-level `status` and `reasons` for a delegated `pr/merge` call, so a * `merged: false` result always says why without digging into `result`. */ export function describeMergeOutcome(result: DelegatedMergeResult): { status: string; reasons: Array } { const status = result?.status ?? (result?.merged ? 'merged' : 'unknown') if (result?.merged) return { status, reasons: [] } const parts = [result?.message, result?.hint].filter((part): part is string => typeof part === 'string' && part.trim().length > 0) if (result?.workflowId) parts.push(`workflowId ${result.workflowId}`) if (!parts.length) { const state = result?.mergeableState ? `, mergeable_state=${result.mergeableState}` : '' parts.push(`GitHub pr/merge returned merged:false with no message (status ${status}${state}). Re-run ./merge or check the PR on GitHub.`) } return { status, reasons: [`merge: ${status} (${parts.join(' ')})`] } }