void postResultComment()

in github-label-notifier/symbolizer/lib/bot.dart [283:381]


  void postResultComment(
      RepositorySlug repo,
      Issue issue,
      Map<int, _Comment> comments,
      Map<int, SymbolizationResult> symbolized) async {
    if (symbolized.isEmpty) {
      return;
    }

    final successes = symbolized.onlySuccesses;
    final failures = symbolized.onlyFailures;

    final buf = StringBuffer();
    for (var entry in successes.entries) {
      for (var result in entry.value.results) {
        buf.write('''
crash from ${comments[entry.key].url} symbolized using symbols for `${result.engineBuild.engineHash}` `${result.engineBuild.variant.os}-${result.engineBuild.variant.arch}-${result.engineBuild.variant.mode}`
```
${result.symbolized}
```
''');
        for (var note in result.notes) {
          buf.write('_(${noteMessage[note.kind]}');
          if ((note.message ?? '').isNotEmpty) {
            buf.write(': ');
            buf.write(note.message);
          }
          buf.write(')_');
        }
        buf.writeln();
      }
    }

    if (failures.isNotEmpty) {
      buf.writeln();
      // GitHub allows <details> HTML elements
      // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
      buf.writeln('''
<details>
<summary>There were failures processing the request</summary>
''');

      void appendNote(SymbolizationNote note) {
        buf.write('* ${noteMessage[note.kind]}');
        if (note.message != null && note.message.isNotEmpty) {
          if (note.message.contains('\n')) {
            buf.writeln(':');
            buf.write('''
```
${note.message}
```'''
                .indentBy('    '));
          } else {
            buf.writeln(': `${note.message}`');
          }
        }
        buf.writeln('');
      }

      for (var entry in failures.entries) {
        entry.value.when(ok: (results) {
          for (var result in results) {
            buf.writeln('''
When processing ${comments[entry.key].url} I found crash

```
${result.crash}
```

but failed to symbolize it with the following notes:
''');
            result.notes.forEach(appendNote);
          }
        }, error: (note) {
          buf.writeln('''
When processing ${comments[entry.key].url} I encountered the following error:
''');
          appendNote(note);
        });
      }

      buf.writeln('''

See [my documentation](https://github.com/flutter-symbolizer-bot/flutter-symbolizer-bot/blob/main/README.md#commands) for more details.
</details>
''');
    }

    // Append information about symbolized comments to the bot's comment so that
    // we could skip them later.
    buf.writeln(
        '<!-- ${jsonEncode({'symbolized': successes.keys.toList()})} -->');

    if (dryRun) {
      print(buf);
    } else {
      await github.issues.createComment(repo, issue.number, buf.toString());
    }
  }