import '../../../core/api_gateway.dart'; import '../../pipelines/pipeline_format.dart'; import 'run_detail_visit_facts.dart'; /// One recorded Summary row: the web run summary's key/value shape. /// /// [monospace] marks a value the web renders as a code identifier (the content /// hash); [block] marks a multi-line recorded document (the diagnostic) that is /// drawn as its own block rather than a short row. typedef DetailSummaryRow = ({ String label, String value, bool monospace, bool block, }); /// The run Summary's rows, in the web summary's order: Pipeline, Stage, /// Workspace, Content hash, Started, Finished, Duration, Retry of and the /// Diagnostic block. /// /// Only values the server actually recorded are rows: a blank field is omitted /// rather than drawn as an empty or invented placeholder, exactly as /// `summaryRows` in the web client does. A run with no pipeline id shows its /// recorded pipeline name, and shows no Pipeline row at all when it recorded /// neither. List detailSummaryRows(JsonMap run) { final rows = []; void add( String label, String? value, { bool monospace = false, bool block = false, }) { final text = value?.trim() ?? ''; if (text.isEmpty) return; rows.add((label: label, value: text, monospace: monospace, block: block)); } final pipelineId = _number(run['pipeline_id'])?.toInt() ?? 0; if (pipelineId > 0) { final version = _number(run['version'])?.toInt() ?? 0; add('Pipeline', 'id $pipelineId · v$version'); } else { add('Pipeline', _text(run['name'])); } add('Stage', _text(run['current_stage'])); add('Workspace', _text(run['workspace'])); add('Content hash', _text(run['content_hash']), monospace: true); add('Started', formatLocalTimestamp(_text(run['created_at']))); add('Finished', formatLocalTimestamp(_text(run['finished_at']))); final seconds = durationSeconds( _text(run['created_at']), _text(run['finished_at']), ); if (seconds != null) add('Duration', formatDuration(seconds)); final retryOf = _number(run['retry_of'])?.toInt() ?? 0; if (retryOf > 0) add('Retry of', 'run $retryOf'); // A diagnostic is a recorded document: its own whitespace is preserved, but a // blank one is not a row. final diagnostic = '${run['diagnostic'] ?? ''}'; if (diagnostic.trim().isNotEmpty) { rows.add(( label: 'Diagnostic', value: diagnostic, monospace: false, block: true, )); } return rows; } /// The run's identity line: `run {id} · {n} recorded visits · {m} completed /// visits`, the same recorded/completed vocabulary the web summary and the /// server use. String detailSummaryIdentity(JsonMap run) { final recorded = detailRunSteps(run).length; final completedValue = _number(run['completed_steps'])?.toInt() ?? 0; final completed = completedValue < 0 ? 0 : completedValue; String visits(int count, String adjective) => '$count $adjective ${count == 1 ? 'visit' : 'visits'}'; return 'run ${run['id'] ?? ''} · ${visits(recorded, 'recorded')} · ' '${visits(completed, 'completed')}'; } String? _text(dynamic value) { if (value == null) return null; final text = '$value'.trim(); return text.isEmpty ? null : text; } num? _number(dynamic value) => value is num ? value : num.tryParse('${value ?? ''}'.trim());