Skip to content

Commit 05801a8

Browse files
authored
Merge pull request #40 from marqeta/add-dismiss-review-type
Adding dismiss review type
2 parents 954817d + 76edab8 commit 05801a8

14 files changed

Lines changed: 125 additions & 9 deletions

cmd/pr-bot/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func downloadOCIArtifacts(svc *prbot.Service, cfg *prbot.Config) {
171171
func setupReviewer(svc *prbot.Service, cfg *prbot.Config, api gh.API) review.Reviewer {
172172
log.Info().Msg("Setting up reviewer")
173173
// mutex -> dedup -> precond -> rate limited -> reviewer
174-
base := review.NewReviewer(api, svc.Metrics)
174+
base := review.NewReviewer(api, svc.Metrics, cfg.GHE.ServiceAccount)
175175
throttler := setupThrottlers(svc, cfg)
176176
rateLimited := review.NewRateLimitedReviewer(base, api, throttler)
177177
precond := review.NewPreCondValidationReviewer(rateLimited)

github/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ More details on PR bot policy evaluation: <a href="%v">link</a>
4545
type API interface {
4646
ListReviews(ctx context.Context, id id.PR) ([]*github.PullRequestReview, error)
4747
AddReview(ctx context.Context, id id.PR, summary, event string) error
48+
DismissReview(ctx context.Context, id id.PR, reviewID int64, message string) error
4849
EnableAutoMerge(ctx context.Context, id id.PR, method githubv4.PullRequestMergeMethod) error
4950
IssueComment(ctx context.Context, id id.PR, comment string) error
5051
IssueCommentForError(ctx context.Context, id id.PR, err pe.APIError) error

github/github.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ func (gh *githubDao) AddReview(ctx context.Context, id id.PR, summary, event str
207207
return nil
208208
}
209209

210+
// DismissReview implements API
211+
func (gh *githubDao) DismissReview(ctx context.Context, id id.PR, reviewID int64, message string) error {
212+
_, resp, err := gh.v3.PullRequests.DismissReview(ctx, id.Owner, id.Repo, id.Number, reviewID,
213+
&github.PullRequestReviewDismissalRequest{
214+
Message: &message,
215+
})
216+
if err != nil {
217+
return err
218+
}
219+
gh.emitTokenExpiration(ctx, resp)
220+
return nil
221+
}
222+
210223
// IssueCommentForError implements Dao
211224
func (gh *githubDao) IssueCommentForError(ctx context.Context, id id.PR, apiError pe.APIError) error {
212225
b, err := json.MarshalIndent(apiError, "", " ")

github/mock_api.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/go-chi/httplog v0.3.2
2020
github.com/go-chi/render v1.0.3
2121
github.com/google/go-github/v50 v50.2.0
22+
github.com/google/uuid v1.6.0
2223
github.com/ilyakaznacheev/cleanenv v1.5.0
2324
github.com/jonboulle/clockwork v0.4.0
2425
github.com/mennanov/limiters v1.2.2
@@ -75,7 +76,6 @@ require (
7576
github.com/gogo/protobuf v1.3.2 // indirect
7677
github.com/golang/protobuf v1.5.4 // indirect
7778
github.com/google/go-querystring v1.1.0 // indirect
78-
github.com/google/uuid v1.6.0 // indirect
7979
github.com/gorilla/mux v1.8.1 // indirect
8080
github.com/hashicorp/consul/api v1.26.1 // indirect
8181
github.com/hashicorp/errwrap v1.1.0 // indirect

opa/types/result.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
Approve
1818
Comment
1919
RequestChanges
20+
Dismiss
2021
)
2122

2223
var (
@@ -25,6 +26,7 @@ var (
2526
1: "APPROVE",
2627
2: "COMMENT",
2728
3: "REQUEST_CHANGES",
29+
4: "DISMISS",
2830
}
2931
reviewTypeValues = reverseMap(reviewTypeNames)
3032

@@ -33,6 +35,7 @@ var (
3335
1: "APPROVED",
3436
2: "COMMENTED",
3537
3: "CHANGES_REQUESTED",
38+
4: "DISMISSED",
3639
}
3740
reviewStateValues = reverseMap(reviewStateNames)
3841
)

pullrequest/event_handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func (eh *eventHandler) EvalAndReview(ctx context.Context, id id.PR, ghe input.G
9494
return eh.reviewer.RequestChanges(ctx, id, opaResult.Review.Body)
9595
case types.Comment:
9696
return eh.reviewer.Comment(ctx, id, opaResult.Review.Body)
97+
case types.Dismiss:
98+
return eh.reviewer.Dismiss(ctx, id, opaResult.Review.Body)
9799
default:
98100
oplog.Info().Msg("skipping review")
99101
}

pullrequest/review/dedup_reviewer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ func (d *DedupReviewer) checkForReview(reviews []*github.PullRequestReview, revi
8989
}
9090
return false
9191
}
92+
93+
func (d *DedupReviewer) Dismiss(ctx context.Context, id id.PR, body string) error {
94+
return d.delegate.Dismiss(ctx, id, body)
95+
}

pullrequest/review/mock_reviewer.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pullrequest/review/mutex_reviewer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ func NewMutexReviewer(delegate Reviewer, locker Locker) Reviewer {
9494
locker: locker,
9595
}
9696
}
97+
98+
func (r *mutexReviewer) Dismiss(ctx context.Context, id id.PR, body string) error {
99+
lock, err := r.acquireLock(ctx, id)
100+
if err != nil {
101+
return err
102+
}
103+
defer r.releaseLock(ctx, lock, id)
104+
return r.delegate.Dismiss(ctx, id, body)
105+
}

0 commit comments

Comments
 (0)