Skip to content

Commit

Permalink
feat: write log than team will be renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrMatsko committed Nov 19, 2024
1 parent aa76f59 commit 1a9498b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/cli/teams_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func fillTeamNamesHash(logger moira.Logger, database moira.Database) error {
return fmt.Errorf("failed to group teams by names: %w", err)
}

teamByUniqueName := transformTeamsByNameMap(teamsByNameMap)
teamByUniqueName := transformTeamsByNameMap(logger, teamsByNameMap)

if len(teamByUniqueName) != len(teamsMap) {
return errTeamsCountAndUniqueNamesCountMismatch
Expand All @@ -66,6 +66,8 @@ func fillTeamNamesHash(logger moira.Logger, database moira.Database) error {
return pipeErr
}

logger.Info().Msg("\"moira-teams-by-names\" hash successfully filled")

default:
return makeUnknownDBError(database)
}
Expand Down Expand Up @@ -99,13 +101,14 @@ func groupTeamsByNames(logger moira.Logger, teamsMap map[string]string) (map[str
return teamsByNameMap, nil
}

func transformTeamsByNameMap(teamsByNameMap map[string][]teamWithID) map[string]teamWithID {
func transformTeamsByNameMap(logger moira.Logger, teamsByNameMap map[string][]teamWithID) map[string]teamWithID {
teamByUniqueName := make(map[string]teamWithID, len(teamsByNameMap))

for _, teams := range teamsByNameMap {
for i, team := range teams {
iStr := strconv.FormatInt(int64(i), 10)

oldTeamName := team.Name
if i > 0 {
team.Name += iStr
}
Expand All @@ -125,6 +128,13 @@ func transformTeamsByNameMap(teamsByNameMap map[string][]teamWithID) map[string]
team.Name += "_" + iStr
} else {
teamByUniqueName[lowercasedTeamName] = team
if team.Name != oldTeamName {
logger.Info().
String("team_id", team.ID).
String("old_team_name", oldTeamName).
String("new_team_name", team.Name).
Msg("Would rename team")
}
break
}
}
Expand Down

0 comments on commit 1a9498b

Please sign in to comment.