From ffebd8a56d3eb47889d5b245b5a545b034e4172a Mon Sep 17 00:00:00 2001 From: Theis Date: Wed, 6 Mar 2024 07:50:36 +0100 Subject: [PATCH] feat: added the grouping feature, currently untested --- src_code/go_src/cocommit.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src_code/go_src/cocommit.go b/src_code/go_src/cocommit.go index eaa202d..1f70c7f 100644 --- a/src_code/go_src/cocommit.go +++ b/src_code/go_src/cocommit.go @@ -24,6 +24,9 @@ var all_flag = false // DefaultExclude -> A list that contains users marked with ex meaning // they should not be included in all and negations var defExclude = []string{} +// Group map for adding people as a group +var groups = make(map[string][]user) + func main() { @@ -50,10 +53,23 @@ func main() { users[info[0]] = usr users[info[1]] = usr // Adds users with the ex tag to the defExclude list - if len(info) > 4 { + if len(info) == 4 { if info[4] == "ex" { defExclude = append(defExclude, info[2]) } + } else if len(info) > 5 { + // Group assignment + for _, group := range info[5:] { + if groups[group] == nil { + groups[group] = []user{usr} + } else { + //TODO: Try and find a cleaner way of doing this + usr_lst := groups[group] + usr_lst = append(usr_lst, usr) + groups[group] = usr_lst + } + + } } } @@ -79,6 +95,10 @@ func main() { if args[1] == "all" || args[1] == "All" { all_flag = true goto skip_loop + } else if groups[args[1]] != nil { + // Selects everybody that isn't the group members and adds them to the defExclude + excludeMode = group_selection(groups[args[1]], excludeMode) + goto skip_loop } // Loop that adds users @@ -132,6 +152,15 @@ func main() { } +func group_selection(group []user, excludeMode []string) []string { + for _, user := range users { + if !(slices.Contains(group, user)) { + excludeMode = append(defExclude, user.username) + } + } + return excludeMode +} + func add_x_users(excludeMode []string) { if len(defExclude) > 0 { excludeMode = append(excludeMode, defExclude...)