AsString returns ScorecardResult in string format.
(writer io.Writer, checkDocs docChecks.Doc, opt *AsStringResultOption)
| 190 | |
| 191 | // AsString returns ScorecardResult in string format. |
| 192 | func (r *Result) AsString(writer io.Writer, checkDocs docChecks.Doc, opt *AsStringResultOption) error { |
| 193 | if opt == nil { |
| 194 | opt = &AsStringResultOption{ |
| 195 | LogLevel: log.DefaultLevel, |
| 196 | Details: false, |
| 197 | Annotations: false, |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | data := make([][]string, len(r.Checks)) |
| 202 | |
| 203 | for i, row := range r.Checks { |
| 204 | var x []string |
| 205 | |
| 206 | // UPGRADEv2: rename variable. |
| 207 | if row.Score == checker.InconclusiveResultScore { |
| 208 | x = append(x, "?") |
| 209 | } else { |
| 210 | x = append(x, fmt.Sprintf("%d / %d", row.Score, checker.MaxResultScore)) |
| 211 | } |
| 212 | |
| 213 | cdoc, e := checkDocs.GetCheck(row.Name) |
| 214 | if e != nil { |
| 215 | return sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("GetCheck: %s: %v", row.Name, e)) |
| 216 | } |
| 217 | |
| 218 | doc := cdoc.GetDocumentationURL(r.Scorecard.CommitSHA) |
| 219 | x = append(x, row.Name, row.Reason) |
| 220 | if opt.Details { |
| 221 | details, show := detailsToString(row.Details, opt.LogLevel) |
| 222 | if show { |
| 223 | x = append(x, details) |
| 224 | } |
| 225 | } |
| 226 | x = append(x, doc) |
| 227 | if opt.Annotations { |
| 228 | reasons := row.Annotations(r.Config) |
| 229 | x = append(x, strings.Join(reasons, "\n")) |
| 230 | } |
| 231 | data[i] = x |
| 232 | } |
| 233 | |
| 234 | score, err := r.GetAggregateScore(checkDocs) |
| 235 | if err != nil { |
| 236 | return err |
| 237 | } |
| 238 | s := fmt.Sprintf("Aggregate score: %s / %d\n\n", scoreToString(score), checker.MaxResultScore) |
| 239 | if score == checker.InconclusiveResultScore { |
| 240 | s = "Aggregate score: ?\n\n" |
| 241 | } |
| 242 | fmt.Fprint(writer, s) |
| 243 | fmt.Fprintln(writer, "Check scores:") |
| 244 | |
| 245 | cfg := tablewriter.Config{ |
| 246 | Row: tw.CellConfig{ |
| 247 | Alignment: tw.CellAlignment{Global: tw.AlignLeft}, |
| 248 | }, |
| 249 | } |
no test coverage detected