From e52b21db033533a88b1baa8a70b4fbded566b322 Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Tue, 22 Aug 2023 18:14:02 +0200 Subject: [PATCH] Don't add Needs labels to back/forward ports Signed-off-by: Rohit Nayak --- go/pull_request.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/go/pull_request.go b/go/pull_request.go index b06cc77..91a07e0 100644 --- a/go/pull_request.go +++ b/go/pull_request.go @@ -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", @@ -58,6 +59,7 @@ type prInformation struct { repoOwner string repoName string merged bool + labels []string } func getPRInformation(event github.PullRequestEvent) prInformation { @@ -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(), @@ -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)