Skip to content

Commit

Permalink
Merge pull request #697 from reviewdog/comment-body
Browse files Browse the repository at this point in the history
Remove reviewdog.Comment.Body
  • Loading branch information
haya14busa committed Jul 25, 2020
2 parents d20b8bb + a109e12 commit b5ffd14
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion comment_iowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (mc *UnifiedCommentWriter) Post(_ context.Context, c *Comment) error {
s += fmt.Sprintf(":%d", start.GetColumn())
}
}
s += fmt.Sprintf(": [%s] %s", c.ToolName, c.Body)
s += fmt.Sprintf(": [%s] %s", c.ToolName, c.Result.Diagnostic.GetMessage())
_, err := fmt.Fprintln(mc.w, s)
return err
}
56 changes: 32 additions & 24 deletions comment_iowriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,64 @@ func TestUnifiedCommentWriter_Post(t *testing.T) {
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{Location: &rdf.Location{Path: "/path/to/file"}},
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
},
},
ToolName: "tool name",
Body: "message",
},
want: `/path/to/file: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Column: 14,
}},
}},
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Column: 14,
}},
},
Message: "message",
},
},
ToolName: "tool name",
Body: "message",
},
want: `/path/to/file: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
}},
}},
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
}},
},
Message: "message",
},
},
ToolName: "tool name",
Body: "message",
},
want: `/path/to/file:14: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
Column: 7,
}},
}},
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
Column: 7,
}},
},
Message: "line1\nline2",
},
},
ToolName: "tool name",
Body: "line1\nline2",
},
want: `/path/to/file:14:7: [tool name] line1
line2`,
Expand Down
2 changes: 0 additions & 2 deletions reviewdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func RunFromResult(ctx context.Context, c CommentService, results []*rdf.Diagnos
type Comment struct {
Result *filter.FilteredDiagnostic
ToolName string
Body string
}

// CommentService is an interface which posts Comment.
Expand Down Expand Up @@ -77,7 +76,6 @@ func (w *Reviewdog) runFromResult(ctx context.Context, results []*rdf.Diagnostic
}
comment := &Comment{
Result: check,
Body: check.Diagnostic.GetMessage(),
ToolName: w.toolname,
}
if err := w.c.Post(ctx, comment); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion service/commentutil/commentutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ func CommentBody(c *reviewdog.Comment) string {
if c.ToolName != "" {
tool = fmt.Sprintf("**[%s]** ", c.ToolName)
}
return tool + BodyPrefix + "\n" + c.Body
return tool + BodyPrefix + "\n" + c.Result.Diagnostic.GetMessage()
}
2 changes: 1 addition & 1 deletion service/gerrit/change_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (g *ChangeReviewCommenter) postAllComments(ctx context.Context) error {
path := loc.GetPath()
review.Comments[path] = append(review.Comments[path], gerrit.CommentInput{
Line: int(loc.GetRange().GetStart().GetLine()),
Message: c.Body,
Message: c.Result.Diagnostic.GetMessage(),
})
}

Expand Down
12 changes: 7 additions & 5 deletions service/gerrit/change_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func TestChangeReviewCommenter_Post_Flush(t *testing.T) {
Line: int32(newLnum1),
}},
},
Message: "new comment",
},
InDiffFile: true,
},
Body: "new comment",
}
newLnum2 := 15
newComment2 := &reviewdog.Comment{
Expand All @@ -53,10 +53,10 @@ func TestChangeReviewCommenter_Post_Flush(t *testing.T) {
Line: int32(newLnum2),
}},
},
Message: "new comment 2",
},
InDiffFile: true,
},
Body: "new comment 2",
}
commentOutsideDiff := &reviewdog.Comment{
Result: &filter.FilteredDiagnostic{
Expand All @@ -67,10 +67,10 @@ func TestChangeReviewCommenter_Post_Flush(t *testing.T) {
Line: 14,
}},
},
Message: "comment outside diff",
},
InDiffFile: false,
},
Body: "comment outside diff",
}

comments := []*reviewdog.Comment{
Expand All @@ -93,13 +93,15 @@ func TestChangeReviewCommenter_Post_Flush(t *testing.T) {
}

line1 := int(newComment1.Result.Diagnostic.GetLocation().GetRange().GetStart().GetLine())
want := []gerrit.CommentInput{{Line: line1, Message: newComment1.Body}}
want := []gerrit.CommentInput{{
Line: line1, Message: newComment1.Result.Diagnostic.GetMessage()}}
if diff := cmp.Diff(got.Comments["file.go"], want); diff != "" {
t.Error(diff)
}

line2 := int(newComment2.Result.Diagnostic.GetLocation().GetRange().GetStart().GetLine())
want = []gerrit.CommentInput{{Line: line2, Message: newComment2.Body}}
want = []gerrit.CommentInput{{
Line: line2, Message: newComment2.Result.Diagnostic.GetMessage()}}
if diff := cmp.Diff(got.Comments["file2.go"], want); diff != "" {
t.Error(diff)
}
Expand Down
26 changes: 13 additions & 13 deletions service/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func TestGitHubPullRequest_Post(t *testing.T) {
Location: &rdf.Location{
Path: "watchdogs.go",
},
Message: "[reviewdog] test",
},
InDiffContext: true,
},
Body: "[reviewdog] test",
}
// https://github.com/reviewdog/reviewdog/pull/2/files#diff-ed1d019a10f54464cfaeaf6a736b7d27L20
if err := g.Post(context.Background(), comment); err != nil {
Expand Down Expand Up @@ -353,10 +353,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "already commented",
},
InDiffContext: true,
},
Body: "already commented",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -369,10 +369,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "already commented 2",
},
InDiffContext: true,
},
Body: "already commented 2",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -385,10 +385,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "new comment",
},
InDiffContext: true,
},
Body: "new comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -404,10 +404,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "multiline existing comment",
},
InDiffContext: true,
},
Body: "multiline existing comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -425,10 +425,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "multiline existing comment (line-break)",
},
InDiffContext: true,
},
Body: "multiline existing comment (line-break)",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -444,10 +444,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
},
},
},
Message: "multiline new comment",
},
InDiffContext: true,
},
Body: "multiline new comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -456,9 +456,9 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
Path: "reviewdog.go",
// No Line
},
Message: "should not be reported via GitHub Review API",
},
},
Body: "should not be reported via GitHub Review API",
},
{
Result: &filter.FilteredDiagnostic{
Expand Down Expand Up @@ -487,10 +487,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
Text: "line1\nline2\nline3",
},
},
Message: "multiline suggestion comment",
},
InDiffContext: true,
},
Body: "multiline suggestion comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -513,10 +513,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
Text: "line1\nline2",
},
},
Message: "singleline suggestion comment",
},
InDiffContext: true,
},
Body: "singleline suggestion comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand Down Expand Up @@ -545,10 +545,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
Text: "line1\nline2\nline3",
},
},
Message: "invalid lines suggestion comment",
},
InDiffContext: true,
},
Body: "invalid lines suggestion comment",
},
{
Result: &filter.FilteredDiagnostic{
Expand Down Expand Up @@ -579,10 +579,10 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) {
Text: "replacement",
},
},
Message: "non-line based suggestion comment",
},
InDiffContext: true,
},
Body: "non-line based suggestion comment",
},
}
for _, c := range comments {
Expand Down Expand Up @@ -647,10 +647,10 @@ func TestGitHubPullRequest_Post_toomany(t *testing.T) {
Line: int32(i),
}},
},
Message: "comment",
},
InDiffContext: true,
},
Body: "comment",
ToolName: "tool",
})
}
Expand Down
4 changes: 2 additions & 2 deletions service/gitlab/gitlab_mr_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func TestGitLabMergeRequestCommitCommenter_Post_Flush_review_api(t *testing.T) {
Line: 1,
}},
},
Message: "already commented",
},
InDiffFile: true,
},
Body: "already commented",
},
{
Result: &filter.FilteredDiagnostic{
Expand All @@ -115,10 +115,10 @@ func TestGitLabMergeRequestCommitCommenter_Post_Flush_review_api(t *testing.T) {
Line: 14,
}},
},
Message: "new comment",
},
InDiffFile: true,
},
Body: "new comment",
},
}
for _, c := range comments {
Expand Down

0 comments on commit b5ffd14

Please sign in to comment.