Skip to content

Commit

Permalink
Revert #1572: Support --filter-mode=[file/nofilter] in github-pr-review
Browse files Browse the repository at this point in the history
Fix #1645
  • Loading branch information
haya14busa committed Jan 25, 2024
1 parent 48b25a0 commit d854609
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
27 changes: 1 addition & 26 deletions service/github/github.go
Expand Up @@ -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() {
Expand All @@ -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.
Expand All @@ -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{
Expand Down
27 changes: 0 additions & 27 deletions service/github/github_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d854609

Please sign in to comment.