Skip to content

Commit d77cd16

Browse files
committed
plugin/label: Suggest members to assign label
Provide a breadcrumb to users if they are unable to assign a label *and* there are no allowed_teams configured. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent c3c7e79 commit d77cd16

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

pkg/plugins/label/label.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package label
1818

1919
import (
2020
"fmt"
21+
"math/rand/v2"
2122
"regexp"
2223
"strings"
2324

@@ -335,6 +336,12 @@ func canUserSetLabel(ghc githubClient, org string, user string, label string, re
335336
msg := fmt.Sprintf("The label(s) `%s` cannot be applied or removed, because you are not in one of the allowed teams and are not an allowed user.", label)
336337
if len(config.AllowedTeams) > 0 {
337338
msg += fmt.Sprintf(" Must be a member of one of these teams: %v", strings.Join(config.AllowedTeams, ", "))
339+
} else if len(config.AllowedUsers) > 0 {
340+
randomUsers := []string{}
341+
for userIdx := range rand.Perm(len(config.AllowedUsers))[:min(len(config.AllowedUsers), 3)] {
342+
randomUsers = append(randomUsers, config.AllowedUsers[userIdx])
343+
}
344+
msg += fmt.Sprintf(" Consider assigning one of the following members: %s", strings.Join(randomUsers, ","))
338345
}
339346
return false, msg, nil
340347
}

pkg/plugins/label/label_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ func TestHandleComment(t *testing.T) {
718718
restrictedLabels: map[string][]plugins.RestrictedLabel{"org": {{Label: "restricted-label", AllowedUsers: []string{orgMemberAlt}}}},
719719
action: github.GenericCommentActionCreated,
720720
expectedBotComment: true,
721-
expectedCommentText: "The label(s) `restricted-label` cannot be applied or removed, because you are not in one of the allowed teams and are not an allowed user.",
721+
expectedCommentText: "The label(s) `restricted-label` cannot be applied or removed, because you are not in one of the allowed teams and are not an allowed user. Consider assigning one of the following members: Mallory",
722722
},
723723
{
724724
name: "Restricted label addition, user is in allowed_teams",
@@ -759,7 +759,7 @@ func TestHandleComment(t *testing.T) {
759759
restrictedLabels: map[string][]plugins.RestrictedLabel{"org": {{Label: "restricted-label", AllowedUsers: []string{orgMemberAlt}}}},
760760
action: github.GenericCommentActionCreated,
761761
expectedBotComment: true,
762-
expectedCommentText: "The label(s) `restricted-label` cannot be applied or removed, because you are not in one of the allowed teams and are not an allowed user.",
762+
expectedCommentText: "The label(s) `restricted-label` cannot be applied or removed, because you are not in one of the allowed teams and are not an allowed user. Consider assigning one of the following members: Mallory",
763763
},
764764
{
765765
name: "Restricted label removal, user is in allowed_teams",

0 commit comments

Comments
 (0)