Skip to content

Commit 67ed6f5

Browse files
committed
Added support for getting the pretty-printed JSON of a review summary
1 parent 8db99d4 commit 67ed6f5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

review/review.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,31 @@ func (r *Review) GetAnalysesNotes() ([]analyses.Note, error) {
322322
return analysesNotes, nil
323323
}
324324

325-
// GetJson returns the pretty printed JSON for a review.
326-
func (r *Review) GetJson() (string, error) {
325+
func prettyPrintJson(jsonBytes []byte) (string, error) {
326+
var prettyBytes bytes.Buffer
327+
err := json.Indent(&prettyBytes, jsonBytes, "", " ")
328+
if err != nil {
329+
return "", err
330+
}
331+
return prettyBytes.String(), nil
332+
}
333+
334+
// GetJson returns the pretty printed JSON for a review summary.
335+
func (r *ReviewSummary) GetJson() (string, error) {
327336
jsonBytes, err := json.Marshal(*r)
328337
if err != nil {
329338
return "", err
330339
}
331-
var prettyBytes bytes.Buffer
332-
err = json.Indent(&prettyBytes, jsonBytes, "", " ")
340+
return prettyPrintJson(jsonBytes)
341+
}
342+
343+
// GetJson returns the pretty printed JSON for a review.
344+
func (r *Review) GetJson() (string, error) {
345+
jsonBytes, err := json.Marshal(*r)
333346
if err != nil {
334347
return "", err
335348
}
336-
return prettyBytes.String(), nil
349+
return prettyPrintJson(jsonBytes)
337350
}
338351

339352
// findLastCommit returns the later (newest) commit from the union of the provided commit

0 commit comments

Comments
 (0)