diff --git a/modules/approvals/approvals.go b/modules/approvals/approvals.go index 699aceab8..201cd6120 100644 --- a/modules/approvals/approvals.go +++ b/modules/approvals/approvals.go @@ -15,7 +15,9 @@ import ( "errors" "fmt" "log/slog" + "maps" "net/http" + "slices" "strings" "time" @@ -383,7 +385,7 @@ func answerText(a Answer) string { if a.Approved { verb = "Approved" } - return fmt.Sprintf("%s by %s in the %s.", verb, a.By, a.Via) + return fmt.Sprintf("%s by %s via %s.", verb, a.By, a.Via) } // Summary is what a person is shown about the action they are asked to allow: @@ -393,6 +395,10 @@ func Summary(d judgement.Decision) string { if d.Action.Effect.Summary != "" { s += " " + d.Action.Effect.Summary } + // The exact input is what is approved, so the person sees every value. + if in := inputLine(d.Action.Input); in != "" { + s += "\nWith: " + in + } var held strings.Builder for _, v := range d.Verdicts { if v.Advisory || v.Ceiling != d.Level { @@ -411,6 +417,25 @@ func Summary(d judgement.Decision) string { return s } +// inputLine renders an action's input as "key=value" pairs in key order, or +// the raw JSON when it isn't a flat object. +func inputLine(input jsontext.Value) string { + var fields map[string]jsontext.Value + if err := json.Unmarshal(input, &fields); err != nil || len(fields) == 0 { + return strings.TrimSpace(string(input)) + } + parts := make([]string, 0, len(fields)) + for _, k := range slices.Sorted(maps.Keys(fields)) { + v := string(fields[k]) + var text string + if json.Unmarshal(fields[k], &text) == nil { + v = text + } + parts = append(parts, k+"="+v) + } + return strings.Join(parts, ", ") +} + // requestOf is a stored row as the module's Request. func requestOf(row store.Request, d judgement.Decision) Request { r := Request{