Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional CI output to note #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions commands/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package output
import (
"fmt"
"github.com/google/git-appraise/review"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -152,6 +153,13 @@ func printAnalyses(r *review.Review) {
fmt.Println(" analyses: ", r.GetAnalysesMessage())
}

// printBuildStatusOutput prints the static analysis results for the latest commit in the review.
func printBuildStatusOutput(r *review.Review) {
indent := " "
indentRegex := regexp.MustCompile("\n")
fmt.Println(indent + indentRegex.ReplaceAllString(r.GetBuildStatusOutput(), "\n"+indent))
}

// printComments prints all of the comments for the review, with snippets of the preceding source code.
func printComments(r *review.Review) error {
fmt.Printf(commentSummaryTemplate, len(r.Comments))
Expand All @@ -170,6 +178,7 @@ func PrintDetails(r *review.Review) error {
fmt.Printf(reviewDetailsTemplate, r.Request.ReviewRef, r.Request.TargetRef,
strings.Join(r.Request.Reviewers, ", "),
r.Request.Requester, r.GetBuildStatusMessage())
printBuildStatusOutput(r)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably not be displayed by default (that would be very verbose), but rather limited to the case of a user passing in a special flag.

Specifically, I mean something like what we are doing for displaying a diff only if the --diff flag is passed in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably not be displayed by default (that would be very verbose), but rather limited to the case of a user passing in a special flag.

Specifically, I mean something like what we are doing for displaying a diff only if the --diff flag is passed in.

That makes sense, I will add an appropriate flag

printAnalyses(r)
if err := printComments(r); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions review/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Report struct {
URL string `json:"url,omitempty"`
Status string `json:"status,omitempty"`
Agent string `json:"agent,omitempty"`
Output string `json:"output,omitempty"`
// Version represents the version of the metadata format.
Version int `json:"v,omitempty"`
}
Expand Down
7 changes: 7 additions & 0 deletions review/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const testCINote5 = `{
"Status": "success"
}`

const testCINote6 = `{
"Timestamp": "27",
"Status": "success"
"Output": "biz\nbaz"
}`

func TestCIReport(t *testing.T) {
latestReport, err := GetLatestCIReport(ParseAllValid([]repository.Note{
repository.Note(testCINote1),
Expand All @@ -71,6 +77,7 @@ func TestCIReport(t *testing.T) {
repository.Note(testCINote2),
repository.Note(testCINote3),
repository.Note(testCINote4),
repository.Note(testCINote6),
}))
if err != nil {
t.Fatal("Failed to properly fetch the latest report", err)
Expand Down
14 changes: 14 additions & 0 deletions review/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ func (r *Review) GetBuildStatusMessage() string {
return statusMessage
}

// GetBuildStatusOutput returns a string of the current build-and-test output
// of the review, or "unknown" if the build-and-test output cannot be determined.
func (r *Review) GetBuildStatusOutput() string {
statusOutput := ""
ciReport, err := ci.GetLatestCIReport(r.Reports)
if err != nil {
return fmt.Sprintf("unknown: %s", err)
}
if ciReport != nil {
statusOutput = ciReport.Output
}
return statusOutput
}

// GetAnalysesNotes returns all of the notes from the most recent static
// analysis run recorded in the git notes.
func (r *Review) GetAnalysesNotes() ([]analyses.Note, error) {
Expand Down
4 changes: 4 additions & 0 deletions schema/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"type": "string"
},

"output": {
"type": "string"
},

"v": {
"type": "integer",
"enum": [0]
Expand Down