From 5edc4eb6dbb37670295c2f9cf8c8d7c02b47cd23 Mon Sep 17 00:00:00 2001 From: wangcheng Date: Mon, 19 Feb 2024 12:00:57 +0800 Subject: [PATCH] github support multi-line comment --- github.go | 26 +++++++++++++++++++------- internal/linters/linters.go | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/github.go b/github.go index 86ec2964..84fa9768 100644 --- a/github.go +++ b/github.go @@ -174,13 +174,25 @@ func buildPullRequestCommentBody(linterName string, lintErrs map[string][]linter message := fmt.Sprintf("[%s] %s\n%s", linterName, lintErr.Message, linters.CommentFooter) - comments = append(comments, &github.PullRequestComment{ - Body: github.String(message), - Path: github.String(file), - Line: github.Int(lintErr.Line), - Side: github.String("RIGHT"), - CommitID: github.String(commitID), - }) + if lintErr.Strat_line != 0 { + comments = append(comments, &github.PullRequestComment{ + Body: github.String(message), + Path: github.String(file), + Line: github.Int(lintErr.Line), + StartLine: github.Int(lintErr.Strat_line), + StartSide: github.String("RIGHT"), + Side: github.String("RIGHT"), + CommitID: github.String(commitID), + }) + } else { + comments = append(comments, &github.PullRequestComment{ + Body: github.String(message), + Path: github.String(file), + Line: github.Int(lintErr.Line), + Side: github.String("RIGHT"), + CommitID: github.String(commitID), + }) + } } } } diff --git a/internal/linters/linters.go b/internal/linters/linters.go index 6558444a..39822e8c 100644 --- a/internal/linters/linters.go +++ b/internal/linters/linters.go @@ -89,6 +89,8 @@ type LinterOutput struct { Column int // Message is the staticcheck Message Message string + //Strat_line required when using multi-line comments + StratLine int } // Agent knows necessary information from reviewbot.