From 5cb7c13fe1e326474a5379938f36d83ad62e97e6 Mon Sep 17 00:00:00 2001 From: azjezz Date: Sun, 15 Dec 2024 22:01:48 +0100 Subject: [PATCH] feat(reporting): improve codespan and github reporting messages Signed-off-by: azjezz --- .../src/internal/emitter/codespan.rs | 4 +-- .../reporting/src/internal/emitter/github.rs | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/reporting/src/internal/emitter/codespan.rs b/crates/reporting/src/internal/emitter/codespan.rs index 7eb7864..6274970 100644 --- a/crates/reporting/src/internal/emitter/codespan.rs +++ b/crates/reporting/src/internal/emitter/codespan.rs @@ -249,11 +249,11 @@ impl From for Diagnostic { } if let Some(help) = issue.help { - diagnostic.notes.push(format!("help: {}", help)); + diagnostic.notes.push(format!("Help: {}", help)); } if let Some(link) = issue.link { - diagnostic.notes.push(format!("see: {}", link)); + diagnostic.notes.push(format!("See: {}", link)); } diagnostic diff --git a/crates/reporting/src/internal/emitter/github.rs b/crates/reporting/src/internal/emitter/github.rs index 9958a50..d0f30ef 100644 --- a/crates/reporting/src/internal/emitter/github.rs +++ b/crates/reporting/src/internal/emitter/github.rs @@ -46,7 +46,31 @@ pub fn github_format( } }; - writeln!(writer, "::{} {}::{}", level, properties, issue.message.as_str())?; + let mut message = issue.message.clone(); + + // we must use `%0A` instead of `\n`. + // + // see: https://github.com/actions/toolkit/issues/193 + if !issue.notes.is_empty() { + message.push_str("%0A"); + + for note in issue.notes.iter() { + message.push_str("%0A"); + message.push_str(note.as_str()); + } + } + + if let Some(help) = issue.help.as_ref() { + message.push_str("%0A%0AHelp: "); + message.push_str(help.as_str()); + } + + if let Some(link) = issue.link.as_ref() { + message.push_str("%0A%0AMore information: "); + message.push_str(link.as_str()); + } + + writeln!(writer, "::{} {}::{}", level, properties, message)?; } Ok(highest_level)