toMarkdown method

String toMarkdown()

生成 PR comment 友好的 markdown。

Implementation

String toMarkdown() {
  final b = StringBuffer();
  b.writeln('# Eval diff: `${current.runName}` vs `${baseline.runName}`');
  b.writeln();
  b.writeln(
    '- Suite: **${current.suite.name}** (${_kindLabel(current.suite.kind)})',
  );
  b.writeln(
    '- Tasks: ${current.trialsByTask().length} '
    '(was ${baseline.trialsByTask().length})',
  );
  b.writeln();

  b.writeln('## Top-line metrics');
  b.writeln();
  b.writeln('| Metric | This run | Baseline | Δ |');
  b.writeln('|---|---|---|---|');
  for (final entry in metricDeltas.entries) {
    final deltaStr = _delta(entry.value);
    final marker =
        current.suite.kind == SuiteKind.regression &&
            entry.value < 0 &&
            entry.key.contains('pass_rate')
        ? ' 🚨'
        : '';
    b.writeln(
      '| ${entry.key} | '
      '${_metricCurrent(entry.key)} | '
      '${_metricBaseline(entry.key)} | '
      '$deltaStr$marker |',
    );
  }
  b.writeln();

  final regressed = transitions
      .where((t) => t.kind == TaskTransitionKind.regressed)
      .toList();
  if (regressed.isNotEmpty) {
    b.writeln('## 🚨 Regressed tasks (${regressed.length})');
    b.writeln();
    for (final t in regressed) {
      b.writeln(
        '- `${t.taskId}`: '
        'baseline ${_pct(t.baselinePassRate)} → '
        'current ${_pct(t.currentPassRate)}',
      );
    }
    b.writeln();
  }

  final improved = transitions
      .where((t) => t.kind == TaskTransitionKind.improved)
      .toList();
  if (improved.isNotEmpty) {
    b.writeln('## ⬆️ Improved tasks (${improved.length})');
    b.writeln();
    for (final t in improved) {
      b.writeln(
        '- `${t.taskId}`: '
        '${_pct(t.baselinePassRate)} → ${_pct(t.currentPassRate)}',
      );
    }
    b.writeln();
  }

  if (addedTaskIds.isNotEmpty) {
    b.writeln('## ➕ Added tasks');
    b.writeln();
    for (final id in addedTaskIds) {
      b.writeln('- `$id`');
    }
    b.writeln();
  }

  if (removedTaskIds.isNotEmpty) {
    b.writeln('## ➖ Removed tasks');
    b.writeln();
    for (final id in removedTaskIds) {
      b.writeln('- `$id`');
    }
    b.writeln();
  }

  return b.toString();
}