102 lines
2.9 KiB
Dart
102 lines
2.9 KiB
Dart
import 'pipeline_format.dart';
|
|
import 'pipeline_models.dart';
|
|
|
|
export 'pipeline_filter.dart';
|
|
export 'pipeline_sort.dart';
|
|
|
|
/// One Summary key/value row.
|
|
class PipelineField {
|
|
const PipelineField(this.key, this.value, {this.monospace = false});
|
|
|
|
final String key;
|
|
final String value;
|
|
final bool monospace;
|
|
}
|
|
|
|
/// The last-run values a row displays.
|
|
class RunBadge {
|
|
const RunBadge({
|
|
required this.runId,
|
|
required this.state,
|
|
required this.ranAgo,
|
|
required this.duration,
|
|
});
|
|
|
|
final int runId;
|
|
final String state;
|
|
final String? ranAgo;
|
|
final String? duration;
|
|
|
|
/// `2h ago · 1m 5s · run 42`; missing fragments are omitted.
|
|
String get metaLine => [
|
|
ranAgo,
|
|
duration,
|
|
'run $runId',
|
|
].whereType<String>().where((fragment) => fragment.isNotEmpty).join(' · ');
|
|
}
|
|
|
|
RunBadge runBadge(PipelineRun run, DateTime now) {
|
|
final duration = run.executing
|
|
? _liveDuration(run, now)
|
|
: _finishedDuration(run);
|
|
return RunBadge(
|
|
runId: run.id,
|
|
state: runStateOf(run.status),
|
|
ranAgo: formatRanAgo(run.createdAt, now),
|
|
duration: duration,
|
|
);
|
|
}
|
|
|
|
String? _liveDuration(PipelineRun run, DateTime now) {
|
|
final start = parseInstant(run.createdAt);
|
|
if (start == null) return null;
|
|
final seconds = now.difference(start).inSeconds;
|
|
return formatDuration(seconds < 0 ? 0 : seconds);
|
|
}
|
|
|
|
String? _finishedDuration(PipelineRun run) {
|
|
final seconds = durationSeconds(run.createdAt, run.finishedAt);
|
|
return seconds == null ? null : formatDuration(seconds);
|
|
}
|
|
|
|
/// The web's version label for a pipeline: `v{n}`.
|
|
String pipelineVersionLabel(PipelineSummary pipeline) => 'v${pipeline.version}';
|
|
|
|
/// The row's flow summary: the web's `{N stages}` label for the recorded stage
|
|
/// count. A summary without `stages` falls back to its recorded `shape` flow,
|
|
/// so a count is never taken from an unrecorded flow.
|
|
String pipelineStageSummary(PipelineSummary pipeline) =>
|
|
stageCountText(pipeline.rowStageCount);
|
|
|
|
/// `id {id} · v{version} · {N stages}`.
|
|
String pipelineSubtitle(PipelineSummary pipeline) =>
|
|
'id ${pipeline.id} · ${pipelineVersionLabel(pipeline)} · '
|
|
'${pipelineStageSummary(pipeline)}';
|
|
|
|
/// `updated d MMM HH:mm`, or null when the timestamp is unusable.
|
|
String? pipelineUpdatedLine(PipelineSummary pipeline) {
|
|
final formatted = formatLocalTimestamp(pipeline.updatedAt);
|
|
return formatted == null ? null : 'updated $formatted';
|
|
}
|
|
|
|
/// The Summary tab's rows in the app's order.
|
|
List<PipelineField> pipelineSummaryFields(PipelineDetail detail) => [
|
|
PipelineField('Content hash', detail.contentHash, monospace: true),
|
|
PipelineField(
|
|
'Latest version',
|
|
detail.latestVersion > 0 ? 'v${detail.latestVersion}' : '',
|
|
),
|
|
PipelineField(
|
|
'Version created',
|
|
formatLocalTimestamp(detail.versionCreatedAt) ?? '',
|
|
),
|
|
PipelineField(
|
|
'Pipeline created',
|
|
formatLocalTimestamp(detail.createdAt) ?? '',
|
|
),
|
|
PipelineField(
|
|
'Pipeline updated',
|
|
formatLocalTimestamp(detail.updatedAt) ?? '',
|
|
),
|
|
];
|