Skip to content

Add a review to a PR instead of a comment (issue #14) #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions ghutil/ghutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
LabelClaYes = "cla: yes"
LabelClaNo = "cla: no"
LabelClaExternal = "cla: external"

ReviewRequestChanges = "REQUEST_CHANGES"
)

// OrganizationsService is the subset of `github.OrganizationsService` used by
Expand All @@ -61,6 +63,7 @@ type IssuesService interface {
// PullRequestsService is the subset of `github.PullRequestsService` used by
// this module.
type PullRequestsService interface {
CreateReview(ctx context.Context, owner string, repo string, number int, review *github.PullRequestReviewRequest) (*github.PullRequestReview, *github.Response, error)
List(ctx context.Context, owner string, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error)
ListCommits(ctx context.Context, owner string, repo string, number int, opt *github.ListOptions) ([]*github.RepositoryCommit, *github.Response, error)
}
Expand Down Expand Up @@ -369,15 +372,16 @@ func (ghc *GitHubClient) ProcessPullRequest(ctx context.Context, orgName string,
}
}

addComment := func(comment string) {
logging.Infof(" Adding comment to repo '%s/%s/ PR %d: %s", orgName, repoName, *pull.Number, comment)
addReview := func(review string, event string) {
logging.Infof(" Adding review to repo '%s/%s/ PR %d: %s", orgName, repoName, *pull.Number, review)
if updateRepo {
issueComment := github.IssueComment{
Body: &comment,
prReview := github.PullRequestReviewRequest{
Body: &review,
Event: &event,
}
_, _, err := ghc.Issues.CreateComment(ctx, orgName, repoName, *pull.Number, &issueComment)
_, _, err := ghc.PullRequests.CreateReview(ctx, orgName, repoName, *pull.Number, &prReview)
if err != nil {
logging.Errorf(" Error leaving comment on PR %d: %v", *pull.Number, err)
logging.Errorf(" Error leaving review on PR %d: %v", *pull.Number, err)
}
} else {
logging.Info(" ... but -update-repo flag is disabled; skipping")
Expand Down Expand Up @@ -416,7 +420,7 @@ func (ghc *GitHubClient) ProcessPullRequest(ctx context.Context, orgName string,
}

if labelsUpdatedForNonCompliance {
addComment(pullRequestNonComplianceReason)
addReview(pullRequestNonComplianceReason, ReviewRequestChanges)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the tool resolve its own review if the user updates their PR such that next time, it's a compliant PR?

}
}
}
Expand Down