Skip to content

Commit

Permalink
Merge pull request #51 from vitessio/rohit/no-needs-labels-on-backports
Browse files Browse the repository at this point in the history
  • Loading branch information
frouioui authored Aug 22, 2023
2 parents 3c6520b + e52b21d commit 60dbc91
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions go/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
)

var (
// these labels are added to PRs that are opened on vitess/vitess, and are not backports or forwardports
alwaysAddLabels = []string{
"NeedsWebsiteDocsUpdate",
"NeedsDescriptionUpdate",
Expand All @@ -58,6 +59,7 @@ type prInformation struct {
repoOwner string
repoName string
merged bool
labels []string
}

func getPRInformation(event github.PullRequestEvent) prInformation {
Expand All @@ -67,6 +69,13 @@ func getPRInformation(event github.PullRequestEvent) prInformation {
if pr != nil {
merged = pr.GetMerged()
}
var labels []string
for _, label := range event.GetPullRequest().Labels {
if label == nil {
continue
}
labels = append(labels, label.GetName())
}
return prInformation{
repo: repo,
num: event.GetNumber(),
Expand Down Expand Up @@ -146,14 +155,21 @@ func (h *PullRequestHandler) addReviewChecklist(ctx context.Context, event githu

func (h *PullRequestHandler) addLabels(ctx context.Context, event github.PullRequestEvent, prInfo prInformation) error {
installationID := githubapp.GetInstallationIDFromEvent(&event)
ctx, logger := githubapp.PreparePRContext(ctx, installationID, prInfo.repo, event.GetNumber())

for _, label := range prInfo.labels {
if strings.EqualFold(label, backport) || strings.EqualFold(label, forwardport) {
logger.Debug().Msgf("Pull Request %s/%s#%d has label %s, skipping adding initial labels",
prInfo.repoOwner, prInfo.repoName, prInfo.num, label)
return nil
}
}

client, err := h.NewInstallationClient(installationID)
if err != nil {
return err
}

ctx, logger := githubapp.PreparePRContext(ctx, installationID, prInfo.repo, event.GetNumber())

logger.Debug().Msgf("Adding initial labels to Pull Request %s/%s#%d", prInfo.repoOwner, prInfo.repoName, prInfo.num)
if _, _, err := client.Issues.AddLabelsToIssue(ctx, prInfo.repoOwner, prInfo.repoName, prInfo.num, alwaysAddLabels); err != nil {
logger.Error().Err(err).Msgf("Failed to add initial labels to Pull Request %s/%s#%d", prInfo.repoOwner, prInfo.repoName, prInfo.num)
Expand Down

0 comments on commit 60dbc91

Please sign in to comment.