Skip to content
Snippets Groups Projects
Commit 4e16566d authored by Kevin Daudt's avatar Kevin Daudt :computer:
Browse files

merge: fix(AutoMaintainer): do not fail is there are several emails found

Instead, try to look for the associated users, and only send a warning
if there's more than one!

See merge request !92
parents 936230af 0d0e1c9e
No related branches found
No related tags found
1 merge request!92fix(AutoMaintainer): do not fail is there are several emails found
Pipeline #280527 passed
......@@ -159,6 +159,7 @@ func (s Service) Process(payload *gitlab.MergeEvent, log *zerolog.Logger) {
}
// List of maintainers that have been found
// This is a "set"
maintainersFound := make(map[string]bool)
for _, diff := range diffs {
......@@ -187,7 +188,9 @@ func (s Service) Process(payload *gitlab.MergeEvent, log *zerolog.Logger) {
continue
}
for _, maintainer := range maintainerSlice {
// Add the maintainerEmail we found from the APKBUILD into the map
// Add the maintainerEmail we found from the APKBUILD
// We add all of them (with and without tags), since we
// are not sure which might have the user used!
maintainersFound[maintainer.GetEmail()] = true
}
}
......@@ -200,20 +203,22 @@ func (s Service) Process(payload *gitlab.MergeEvent, log *zerolog.Logger) {
return
}
if len(maintainersFound) > 1 {
sLog.Warn().Msg("too many maintainers found to assign")
return
}
for k := range maintainersFound {
assigned := false
for email := range maintainersFound {
// Transform the email into the user
maintainerUser, err := hasUser(s.gitlabClient, k)
maintainerUser, err := hasUser(s.gitlabClient, email)
if err != nil {
sLog.Error().
Err(err).
Msg("failed to convert APKBUILD maintainer to GitLab user")
sLog.Info().
Str("email", email).
Msg("No user associated with this email")
continue
}
return
if assigned {
sLog.Warn().
Str("email", email).
Msg("Maintainer already assigned, but new one found")
continue
}
// Try to get Username via its ID
......@@ -237,6 +242,7 @@ func (s Service) Process(payload *gitlab.MergeEvent, log *zerolog.Logger) {
}
sLog.Info().Str("user", maintainerUser.Username).Msg("assigning")
assigned = true
if !s.dryRun {
_, _, err = s.gitlabClient.MergeRequests.UpdateMergeRequest(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment