package pr import ( "github.com/google/go-github/v47/github" "edge-infra.dev/pkg/f8n/devinfra/jack/constants" "edge-infra.dev/pkg/f8n/devinfra/jack/plugin" ) func init() { plugin.RegisterReviewEventHandler(constants.PluginPR, handleReviewEvent) } func handleReviewEvent(hp plugin.HandlerParams, event github.PullRequestReviewEvent) { hp.Log.WithName(constants.PluginPR) log := hp.Log ctx := hp.Ctx client := hp.Client //gets the reviewer sender := []string{event.GetReview().GetUser().GetLogin()} senderString := event.GetReview().GetUser().GetLogin() log.Info("Running PR plugin") //bounces out if the reviewer is the author of the PR if event.GetPullRequest().GetUser().GetLogin() == senderString { log.Info("reviewer is author") return } //bounces out of the PR is a draft isDraft := event.GetPullRequest().GetDraft() if isDraft { log.Info("PR is draft, not assigning users") return } authorAssociation := event.GetReview().GetAuthorAssociation() requestedReviewers := event.GetPullRequest().RequestedReviewers repo := event.GetRepo() repoName := repo.GetName() repoOwner := repo.GetOwner().GetLogin() issueNumber := event.GetPullRequest().GetNumber() inRequestedReviewers := false //bounces out of the reviewer is not in the requested reviewers, otherwise bounces out is the reviewer is a contributor, owner, or collaborator if len(requestedReviewers) != 0 { for _, v := range requestedReviewers { if senderString == v.GetLogin() { inRequestedReviewers = true } } if !inRequestedReviewers { log.Info("Reviewer is not in requested review list") return } } else if authorAssociation != "CONTRIBUTOR" && authorAssociation != "OWNER" && authorAssociation != "COLLABORATOR" { log.Info("Ignoring review from non contributor, non owner, or non collaborator") return } //Adds the commentor to the list if they are an owner or conrtributor _, _, err := client.Issues().AddAssignees(ctx, repoOwner, repoName, issueNumber, sender) if err != nil { log.Error(err, "Failed to add assigner") // return err } log.Info("Added assignment from review") // return nil }