-
Notifications
You must be signed in to change notification settings - Fork 161
Remove a category label needs-* when the user is defining one
#370
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -143,6 +143,23 @@ func getLabelsFromGenericMatches(matches [][]string, labelFilter func(string) bo | |||||||||||||||||||||||||
| return labels | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // getCategoriesFromLabels extracts the categories from `labels` that are also in `needsLabels`. | ||||||||||||||||||||||||||
| // Example: | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| // labels := []string{"triage/unresolved", "area/testing"} | ||||||||||||||||||||||||||
| // needsLabels := []string{"triage"} | ||||||||||||||||||||||||||
| // result := []string{"triage"} | ||||||||||||||||||||||||||
| func getCategoriesFromLabels(labels, needsLabels []string) sets.Set[string] { | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just for you to consider
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weak -1 from me, I'm a fan of private-unless-proven-to-be-necessary-public 😓
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its my bad. I meant internals of the function, my intention was not to propose to make it public. Let me correct that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected, again comment is about internals not about publicity, sorry for the confusion. |
||||||||||||||||||||||||||
| needsLabelsSet := sets.New(needsLabels...) | ||||||||||||||||||||||||||
| categories := sets.New[string]() | ||||||||||||||||||||||||||
| for _, label := range labels { | ||||||||||||||||||||||||||
| if split := strings.Split(label, "/"); len(split) == 2 && needsLabelsSet.Has(split[0]) { | ||||||||||||||||||||||||||
| categories.Insert(split[0]) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return categories | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func handleComment(gc githubClient, log *logrus.Entry, config plugins.Label, e *github.GenericCommentEvent) error { | ||||||||||||||||||||||||||
| if e.Action != github.GenericCommentActionCreated { | ||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||
|
|
@@ -201,13 +218,22 @@ func handleComment(gc githubClient, log *logrus.Entry, config plugins.Label, e * | |||||||||||||||||||||||||
| // Get labels to add and labels to remove from regexp matches | ||||||||||||||||||||||||||
| labelsToAdd = append(getLabelsFromREMatches(labelMatches), getLabelsFromGenericMatches(customLabelMatches, labelFilter, &nonexistent)...) | ||||||||||||||||||||||||||
| labelsToRemove = append(getLabelsFromREMatches(removeLabelMatches), getLabelsFromGenericMatches(customRemoveLabelMatches, labelFilter, &nonexistent)...) | ||||||||||||||||||||||||||
| categoriesToAdd := getCategoriesFromLabels(labelsToAdd, needsLabels) | ||||||||||||||||||||||||||
| issueLabelsSet := sets.New(issueLabels...) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for _, needsCategory := range needsLabels { | ||||||||||||||||||||||||||
| needsLabel := fmt.Sprintf("needs-%s", needsCategory) | ||||||||||||||||||||||||||
| if !RepoLabelsExisting.Has(needsLabel) { | ||||||||||||||||||||||||||
| // Repo doesn't have the needs-* label. | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Remove a category needs-* if any label is defining it. As an example: | ||||||||||||||||||||||||||
| // the issue has `needs-triage` and the user is commenting `/triage unresolved` | ||||||||||||||||||||||||||
| if issueLabelsSet.Has(needsLabel) && categoriesToAdd.Has(needsCategory) { | ||||||||||||||||||||||||||
| labelsToRemove = append(labelsToRemove, needsLabel) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| removed := labelsWithCategory(labelsToRemove, needsCategory) | ||||||||||||||||||||||||||
| if removed.Len() == 0 || labelsWithCategory(labelsToAdd, needsCategory).Len() > 0 { | ||||||||||||||||||||||||||
| // If a category is not being removed, or also being added, don't add needs-* label. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : weird indent