package enforcemilestone import ( "github.com/google/go-github/v47/github" "edge-infra.dev/pkg/f8n/devinfra/jack/constants" "edge-infra.dev/pkg/f8n/devinfra/jack/plugin" ) // Check if a milestone was initially added and is valid func openingMilestone(hp plugin.HandlerParams, ie github.IssuesEvent) { milestone := ie.GetIssue().GetMilestone() if milestone == nil { // Milestone isn't there. Need to add label addMilestoneLabel(hp, ie.GetIssue().GetNumber()) return } } // Simple add label func addMilestoneLabel(hp plugin.HandlerParams, num int) { labels := []string{constants.TriageMilestoneLabel} _, _, err := hp.Client.Issues().AddLabelsToIssue(hp.Ctx, hp.Org, hp.Repo, num, labels) if err != nil { hp.Log.Error(err, "Failed to add needs-milestone label") } } // Simple remove label func removeMilestoneLabel(hp plugin.HandlerParams, ie github.IssuesEvent) { hasTriage := false for _, x := range ie.Issue.Labels { if x.GetName() == constants.TriageMilestoneLabel { hasTriage = true break } } // exit if theres no triage label if !hasTriage { hp.Log.Info("no triage milestone label exists, ignoring") return } _, err := hp.Client.Issues().RemoveLabelForIssue(hp.Ctx, hp.Org, hp.Repo, ie.GetIssue().GetNumber(), constants.TriageMilestoneLabel) if err != nil { hp.Log.Error(err, "Failed to remove needs-milestone label") } } // If label added is triage/needs-milestone, if it is and has a valid milestone remove it func checkLabel(hp plugin.HandlerParams, ie github.IssuesEvent) { log := hp.Log log.Info("Check label for milestone") if ie.GetSender().GetType() == constants.Bot { hp.Log.Info("Bot check on addLabel") return } if ie.Label.GetName() == constants.TriageMilestoneLabel { milestone := ie.GetIssue().GetMilestone() if milestone != nil { // You have a valid milestone removeMilestoneLabel(hp, ie) } } } // See if the label removed is triage/needs-milestone, if it is put it back func checkRemoveLabel(hp plugin.HandlerParams, ie github.IssuesEvent) { log := hp.Log log.Info("CHECKING REMOVAL") if ie.GetSender().GetType() == constants.Bot { log.Info("Bot check on addLabel") return } if ie.Label.GetName() == constants.TriageMilestoneLabel { milestone := ie.GetIssue().GetMilestone() if milestone != nil { return // You have a valid milestone } } addMilestoneLabel(hp, ie.GetIssue().GetNumber()) }