Skip to content

Commit

Permalink
gitlab: Get most specific match for group-mappings
Browse files Browse the repository at this point in the history
We use the count of "/" in the name of the group to get the most
specific match.
This fixes #55
  • Loading branch information
fleaz committed Jul 25, 2020
1 parent e6132d4 commit 6d67174
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions input/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ func contains(mapping map[string][]string, entry string) []string {
}

func prefixContains(mapping map[string][]string, entry string) []string {
// Start with -1 so we can also match a single groupname without sub-groups
length := -1
var target []string
for k := range mapping {
if strings.HasPrefix(entry, k) {
return mapping[k]

if strings.HasPrefix(entry, k) && len(strings.Split(k, "/")) > length {
target = mapping[k]
length = len(strings.Split(k, "/"))
}
}
return nil
if len(target) > 0 {
return target
} else {
return nil
}
}

func (m *GitlabModule) Init(c *viper.Viper, channel *chan IRCMessage) {
Expand Down

0 comments on commit 6d67174

Please sign in to comment.