github-pr-review: fix multiline comments
# >8
# reviewdog results
@@ -108,21 +108,7 @@ func (g *GitHubPullRequest) postAsReviewComment(ctx context.Context) error {
remaining = append(remaining, c)
continue
}
- cbody := commentutil.CommentBody(c)
- // Document: https://docs.github.com/en/rest/reference/pulls#create-a-review-comment-for-a-pull-request
- loc := c.Result.Diagnostic.GetLocation()
- comment := &github.DraftReviewComment{
- Path: github.String(loc.GetPath()),
- Side: github.String("RIGHT"),
- Body: github.String(cbody),
- Line: github.Int(int(loc.GetRange().GetStart().GetLine())),
- }
- if loc.GetRange().GetEnd().GetLine() > 0 {
- comment.StartSide = github.String("RIGHT")
- comment.StartLine = github.Int(int(loc.GetRange().GetStart().GetLine()))
- comment.Line = github.Int(int(loc.GetRange().GetEnd().GetLine()))
- }
- comments = append(comments, comment)
+ comments = append(comments, buildDraftReviewComment(c))
}
if len(comments) == 0 {
@@ -139,6 +125,32 @@ func (g *GitHubPullRequest) postAsReviewComment(ctx context.Context) error {
return err
}
+// Document: https://docs.github.com/en/rest/reference/pulls#create-a-review-comment-for-a-pull-request
+func buildDraftReviewComment(c *reviewdog.Comment) *github.DraftReviewComment {
+ cbody := commentutil.CommentBody(c)
+ loc := c.Result.Diagnostic.GetLocation()
+ startLine := int(loc.GetRange().GetStart().GetLine())
+ endLine := int(loc.GetRange().GetEnd().GetLine())
+ // End position with column == 1 means range to the end of the previous lines
+ // including line-break.
+ if loc.GetRange().GetEnd().GetColumn() == 1 {
+ endLine--
+ }
+ r := &github.DraftReviewComment{
+ Path: github.String(loc.GetPath()),
+ Side: github.String("RIGHT"),
+ Body: github.String(cbody),
+ Line: github.Int(startLine),
+ }
+ // GitHub API: Start line must precede the end line.
+ if startLine < endLine {
+ r.StartSide = github.String("RIGHT")
+ r.StartLine = github.Int(startLine)
+ r.Line = github.Int(endLine)
+ }
+ return r
+}
+
func (g *GitHubPullRequest) remainingCommentsSummary(remaining []*reviewdog.Comment) string {
if len(remaining) == 0 {
return ""
