Skip to content
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

refactor: Adjust type of set structure in team update logic #2675

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions internal/service/team/update_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ func ValidateUsernames(c admin.MongoDBCloudUsersApi, usernames []string) ([]admi
}

func GetChangesForTeamUsers(currentUsers, newUsers []admin.CloudAppUser) (toAdd, toDelete []string, err error) {
// Create two sets to store the elements in A and B
// Create two sets to store the elements of current and new users
currentUsersSet := InitUserSet(currentUsers)
newUsersSet := InitUserSet(newUsers)

// Iterate over the elements in B and add them to the toAdd array if they are not in A
// Iterate over new users and add them to the toAdd array if they are not in current users
for elem := range newUsersSet {
if _, ok := currentUsersSet[elem]; !ok {
if !currentUsersSet[elem] {
toAdd = append(toAdd, elem)
}
}

// Iterate over the elements in A and add them to the toDelete array if they are not in B
// Iterate over current users and add them to the toDelete array if they are not in new users
for elem := range currentUsersSet {
if _, ok := newUsersSet[elem]; !ok {
if !newUsersSet[elem] {
toDelete = append(toDelete, elem)
}
}

return toAdd, toDelete, nil
}

func InitUserSet(users []admin.CloudAppUser) map[string]interface{} {
usersSet := make(map[string]interface{}, len(users))
func InitUserSet(users []admin.CloudAppUser) map[string]bool {
usersSet := make(map[string]bool, len(users))
for i := 0; i < len(users); i++ {
usersSet[users[i].GetId()] = true
}
Expand Down
2 changes: 1 addition & 1 deletion tools/check-changelog-entry-file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var (
skipLabelName = "skip-changelog-check"
skipTitles = []string{"chore", "test", "doc", "ci"} // Dependabot uses chore.
skipTitles = []string{"chore", "test", "doc", "ci", "refactor"} // Dependabot uses chore.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

allowedTypeValues = getValidTypes("scripts/changelog/allowed-types.txt")
typesRequireResourcePrefix = []string{"breaking-change", "enhancement", "bug"}
)
Expand Down