Skip to content

Commit

Permalink
Update to add icon status to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
seanconroy2021 committed Sep 28, 2023
1 parent cad7ff7 commit c593054
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/applicationsnapshot/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"strconv"
"time"

ecc "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
Expand Down Expand Up @@ -240,8 +241,8 @@ func condensedMsg(results []evaluator.Result) map[string][]string {

func generateMarkdownSummary(r *Report) ([]byte, error) {
var markdownBuffer bytes.Buffer
markdownBuffer.WriteString("| Field | Value |\n")
markdownBuffer.WriteString("|-----------|-------|\n")
markdownBuffer.WriteString("| Field | Value |Status|\n")
markdownBuffer.WriteString("|-----------|-------|-------|\n")

var totalViolations, totalWarnings, totalSuccesses int
pr := r.toSummary()
Expand All @@ -253,7 +254,6 @@ func generateMarkdownSummary(r *Report) ([]byte, error) {
type Field struct {
Name string
Value string
//TODOStatus string tick and x
}
fields := []Field{
{"Time", r.created.UTC().Format("2006-01-02 15:04:05")},
Expand All @@ -270,8 +270,18 @@ func generateMarkdownSummary(r *Report) ([]byte, error) {
return markdownBuffer.Bytes(), nil

Check warning on line 270 in internal/applicationsnapshot/report.go

View check run for this annotation

Codecov / codecov/patch

internal/applicationsnapshot/report.go#L242-L270

Added lines #L242 - L270 were not covered by tests
}

func writeMarkdownField(buffer *bytes.Buffer, fieldName, fieldValue string) {
buffer.WriteString(fmt.Sprintf("| %s | %s |\n", fieldName, fieldValue))
func writeMarkdownField(buffer *bytes.Buffer, name, value string) {
var icon string
intVal, _ := strconv.Atoi(value)
icon = ":x:"
if (name == "Name" || name == "Time") ||
(name == "Successes" && intVal >= 1) ||
(name == "Failures" && intVal == 0) ||
(name == "Warnings" && intVal == 0) ||
(name == "Result" && value == "true") {
icon = ":white_check_mark:"
}
buffer.WriteString(fmt.Sprintf("| %s | %s | %s |\n", name, value, icon))

Check warning on line 284 in internal/applicationsnapshot/report.go

View check run for this annotation

Codecov / codecov/patch

internal/applicationsnapshot/report.go#L273-L284

Added lines #L273 - L284 were not covered by tests
}

// toAppstudioReport returns a version of the report that conforms to the
Expand Down

0 comments on commit c593054

Please sign in to comment.