From 78af252f6eea49cdaeb43a3962f69f6fbdb2a1d6 Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Thu, 1 Aug 2024 11:08:38 +0900 Subject: [PATCH] (vup) using details for facts (#16) --- go.mod | 2 +- go.sum | 2 ++ main.go | 40 +++++++++++++++++++++------------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index dfb83f1..d8df1c6 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.3 require ( github.com/glebarez/go-sqlite v1.22.0 github.com/jasonlvhit/gocron v0.0.1 - github.com/kevincobain2000/go-msteams v1.0.1 + github.com/kevincobain2000/go-msteams v1.1.0 github.com/lmittmann/tint v1.0.5 github.com/mattn/go-isatty v0.0.20 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index c41ec3c..7624a0a 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ github.com/kevincobain2000/go-msteams v1.0.0 h1:dp8zIs2PfzsFV1LFFSNFzy1tpEIYJ+X1 github.com/kevincobain2000/go-msteams v1.0.0/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo= github.com/kevincobain2000/go-msteams v1.0.1 h1:EXwMHSrmvV3k6WKL3MotAqkBWta85bq56NBTQi/wbag= github.com/kevincobain2000/go-msteams v1.0.1/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo= +github.com/kevincobain2000/go-msteams v1.1.0 h1:r2Q/Ug2ZGQclDHzIfppyfB4FPjAcDjNIti3WmI91VTo= +github.com/kevincobain2000/go-msteams v1.1.0/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo= github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw= github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= diff --git a/main.go b/main.go index 6d83480..398a4ce 100644 --- a/main.go +++ b/main.go @@ -132,25 +132,27 @@ func watch(filePath string) { } func notify(errorCount int, firstLine, lastLine string) { - if f.msTeamsHook != "" { - teamsMsg := fmt.Sprintf("total errors: %d\n\n", errorCount) - teamsMsg += fmt.Sprintf("first line: %s\n\n", firstLine) - teamsMsg += fmt.Sprintf("last line: %s\n\n", lastLine) - slog.Info("Sending to Teams") - - hostname, _ := os.Hostname() - subject := fmt.Sprintf("match: %s", f.match) - subject += "," // nolint: goconst - subject += fmt.Sprintf("ignore: %s", f.ignore) - subject += "," // nolint: goconst - subject += fmt.Sprintf("min error: %d", f.min) - err := gmt.Send(hostname, f.filePath, subject, teamsMsg, f.msTeamsHook, f.proxy) - if err != nil { - slog.Error("Error sending to Teams", "error", err.Error()) - } else { - slog.Info("Sent to Teams") - slog.Info("Done") - } + if f.msTeamsHook == "" { + return + } + + slog.Info("Sending to MS Teams") + details := map[string]string{ + "Match Pattern": f.match, + "Ignore Pattern": f.ignore, + "Min Errors Threshold": fmt.Sprintf("%d", f.min), + "Total Errors Found": fmt.Sprintf("%d", errorCount), + "First Line": firstLine, + "Last Line": lastLine, + } + + hostname, _ := os.Hostname() + + err := gmt.Send(hostname, details, f.msTeamsHook, f.proxy) + if err != nil { + slog.Error("Error sending to Teams", "error", err.Error()) + } else { + slog.Info("Succesfully sent to MS Teams") } }