toJson method
The report as JSON: the header, the summary, every message with its
code, level, repository, evidence and options
({option, explanation, commandLine}), and what was done.
Implementation
Map<String, Object?> toJson() {
final changedPaths = {for (final d in done) d.repository};
return {
'command': '$tool $command',
'root': root,
'host': host,
'started': started.toIso8601String(),
'options': given,
'exitCode': exitCode,
'summary': {
'repositories': lookedAt.length,
'changed': done.length,
'needsYou': _at(MessageLevel.error).length,
'warnings': _at(MessageLevel.warning).length,
'refused': _at(MessageLevel.refusal).length,
},
'messages': [
for (final m in messages)
{
'code': m.code,
'level': m.level.name,
'repository': m.repository == null
? null
: {
'name': names.nameOf(m.repository!),
'path': _repoLabel(m.repository),
},
'branch': m.branch,
'finding': m.finding,
'evidence': {for (final e in m.evidence) e.kind: e.items},
'state': m.state,
'options': [
for (final o in m.options)
{
'option': _optionToken(m, o),
'explanation': m.explanations[o.name] ?? o.explanation,
'commandLine': commandLine(m, o),
},
],
},
],
'done': [
for (final d in done)
{
'repository': _repoLabel(d.repository),
'actions': d.actions,
'files': d.files,
},
],
'unchanged': [
for (final p in (lookedAt.toList()..sort()))
if (!changedPaths.contains(p)) _repoLabel(p),
],
};
}