Skip to content

Commit

Permalink
Merge pull request #938 from cloudflare/issue-935
Browse files Browse the repository at this point in the history
Test pint ci on gh
  • Loading branch information
prymitive authored Mar 27, 2024
2 parents 0a36961 + ceb3b65 commit 0c34019
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fixed compatibility with older git releases.
- Fixed `maxComments` defaulting to zero when using GitHub reporter.
- Fixed `maxComments` comment creation on GitHub - #935.

## v0.57.2

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/fatih/color v1.16.0
github.com/gkampitakis/go-snaps v0.5.2
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v57 v57.0.0
github.com/google/go-github/v60 v60.0.0
github.com/hashicorp/hcl/v2 v2.20.0
github.com/klauspost/compress v1.17.7
github.com/neilotoole/slogt v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v57 v57.0.0 h1:L+Y3UPTY8ALM8x+TV0lg+IEBI+upibemtBD8Q9u7zHs=
github.com/google/go-github/v57 v57.0.0/go.mod h1:s0omdnye0hvK/ecLvpsGfJMiRt85PimQh4oygmLIxHw=
github.com/google/go-github/v60 v60.0.0 h1:oLG98PsLauFvvu4D/YPxq374jhSxFYdzQGNCyONLfn8=
github.com/google/go-github/v60 v60.0.0/go.mod h1:ByhX2dP9XT9o/ll2yXAu2VD8l5eNVg8hD4Cr0S/LmQk=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
18 changes: 12 additions & 6 deletions internal/reporter/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/google/go-github/v57/github"
"github.com/google/go-github/v60/github"
"golang.org/x/oauth2"

"github.com/cloudflare/pint/internal/checks"
Expand Down Expand Up @@ -173,7 +173,7 @@ func (gr GithubReporter) addReviewComments(headCommit string, summary Summary) e
added++

if added >= gr.maxComments {
return gr.tooManyComments(headCommit, len(summary.Reports()))
return gr.tooManyComments(len(summary.Reports()))
}
}

Expand Down Expand Up @@ -336,11 +336,17 @@ func reportToGitHubComment(headCommit string, rep Report) *github.PullRequestCom
return &c
}

func (gr GithubReporter) tooManyComments(headCommit string, nrComments int) error {
comment := github.PullRequestComment{
CommitID: github.String(headCommit),
func (gr GithubReporter) tooManyComments(nrComments int) error {
comment := github.IssueComment{
Body: github.String(fmt.Sprintf(`This pint run would create %d comment(s), which is more than %d limit configured for pint.
%d comments were skipped and won't be visibile on this PR.`, nrComments, gr.maxComments, nrComments-gr.maxComments)),
}
return gr.createComment(&comment)

slog.Debug("Creating PR comment", slog.String("body", comment.GetBody()))

ctx, cancel := context.WithTimeout(context.Background(), gr.timeout)
defer cancel()

_, _, err := gr.client.Issues.CreateComment(ctx, gr.owner, gr.repo, gr.prNum, &comment)
return err
}
2 changes: 1 addition & 1 deletion internal/reporter/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ filename %s
switch b {
case `{"body":":stop_sign: [mock1](https://cloudflare.github.io/pint/checks/mock1.html): syntax error1\n\nsyntax details1","path":"","line":2,"side":"RIGHT","commit_id":"fake-commit-id"}`:
case `{"body":":stop_sign: [mock2](https://cloudflare.github.io/pint/checks/mock2.html): syntax error2\n\nsyntax details2","path":"","line":2,"side":"RIGHT","commit_id":"fake-commit-id"}`:
case `{"body":"This pint run would create 4 comment(s), which is more than 2 limit configured for pint.\n2 comments were skipped and won't be visibile on this PR.","commit_id":"fake-commit-id"}`:
case `{"body":"This pint run would create 4 comment(s), which is more than 2 limit configured for pint.\n2 comments were skipped and won't be visibile on this PR."}`:
default:
t.Errorf("Unexpected comment: %s", b)
}
Expand Down

0 comments on commit 0c34019

Please sign in to comment.