diff --git a/service/github/github.go b/service/github/github.go index 055d70f9de..e7240bf1c7 100644 --- a/service/github/github.go +++ b/service/github/github.go @@ -127,11 +127,10 @@ func (g *PullRequest) postAsReviewComment(ctx context.Context) error { postComments := g.postComments g.postComments = nil rawComments := make([]*reviewdog.Comment, 0, len(postComments)) - plainComments := make([]*github.PullRequestComment, 0, len(postComments)) reviewComments := make([]*github.DraftReviewComment, 0, len(postComments)) remaining := make([]*reviewdog.Comment, 0) for _, c := range postComments { - if !c.Result.InDiffFile { + if !c.Result.InDiffContext { // GitHub Review API cannot report results outside diff. If it's running // in GitHub Actions, fallback to GitHub Actions log as report. if cienv.IsInGitHubAction() { @@ -147,14 +146,6 @@ func (g *PullRequest) postAsReviewComment(ctx context.Context) error { continue } - rawComments = append(rawComments, c) - if !c.Result.InDiffContext { - // If the result is outside of diff context, fallback to GitHub Review - // Comment API. - comment := buildPullRequestComment(c, body, g.sha) - plainComments = append(plainComments, comment) - continue - } // Only posts maxCommentsPerRequest comments per 1 request to avoid spammy // review comments. An example GitHub error if we don't limit the # of // review comments. @@ -173,22 +164,6 @@ func (g *PullRequest) postAsReviewComment(ctx context.Context) error { return err } - if len(plainComments) > 0 { - // send pull request comments to GitHub. - for _, c := range plainComments { - _, _, err := g.cli.PullRequests.CreateComment(ctx, g.owner, g.repo, g.pr, c) - if err != nil { - log.Printf("reviewdog: failed to post a pull request comment: %v", err) - // GitHub returns 403 or 404 if we don't have permission to post a review comment. - // fallback to log message in this case. - if isPermissionError(err) && cienv.IsInGitHubAction() { - goto FALLBACK - } - return err - } - } - } - if len(reviewComments) > 0 { // send review comments to GitHub. review := &github.PullRequestReviewRequest{ diff --git a/service/github/github_test.go b/service/github/github_test.go index 5d097242c5..0d4495024c 100644 --- a/service/github/github_test.go +++ b/service/github/github_test.go @@ -202,7 +202,6 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) { listCommentsAPICalled := 0 postCommentsAPICalled := 0 - postCommentAPICalled := 0 mux := http.NewServeMux() mux.HandleFunc("/repos/o/r/pulls/14/comments", func(w http.ResponseWriter, r *http.Request) { switch r.Method { @@ -261,29 +260,6 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) { t.Fatal(err) } } - case http.MethodPost: - defer func() { postCommentAPICalled++ }() - var req github.PullRequestComment - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - t.Error(err) - } - want := []*github.PullRequestComment{ - { - Body: github.String(commentutil.BodyPrefix + "file comment (no-line)"), - CommitID: github.String("sha"), - Path: github.String("reviewdog.go"), - SubjectType: github.String("file"), - }, - { - Body: github.String(commentutil.BodyPrefix + "file comment (outside diff-context)"), - CommitID: github.String("sha"), - Path: github.String("reviewdog.go"), - SubjectType: github.String("file"), - }, - } - if diff := pretty.Compare(want[postCommentAPICalled], req); diff != "" { - t.Errorf("req.Comments diff: (-got +want)\n%s", diff) - } default: t.Errorf("unexpected access: %v %v", r.Method, r.URL) } @@ -1218,9 +1194,6 @@ func TestGitHubPullRequest_Post_Flush_review_api(t *testing.T) { if postCommentsAPICalled != 1 { t.Errorf("GitHub post PullRequest comments API called %v times, want 1 times", postCommentsAPICalled) } - if postCommentAPICalled != 2 { - t.Errorf("GitHub post PullRequest comment API called %v times, want 2 times", postCommentAPICalled) - } } func TestGitHubPullRequest_Post_toomany(t *testing.T) {