From 73ee788e8b0558524c63c8da710b4031fe70382d Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Fri, 1 Nov 2024 08:32:10 +0100 Subject: [PATCH] chore: rename src folder --- .gitignore | 1 + {src_code/go_src => src}/LICENSE | 0 {src_code/go_src => src}/author.txt | 0 {src_code/go_src => src}/cmd/cmd_test.go | 0 {src_code/go_src => src}/cmd/cz.go | 0 {src_code/go_src => src}/cmd/root.go | 0 {src_code/go_src => src}/cmd/tui/README.md | 0 .../go_src => src}/cmd/tui/tui_author.go | 0 .../cmd/tui/tui_commit_message.go | 0 {src_code/go_src => src}/cmd/tui/tui_list.go | 0 .../go_src => src}/cmd/tui/tui_show_users.go | 0 {src_code/go_src => src}/cmd/tui/tui_test.go | 0 {src_code/go_src => src}/cmd/users.go | 0 .../cmd/utils/author_file_utils.go | 0 {src_code/go_src => src}/cmd/utils/commit.go | 0 .../go_src => src}/cmd/utils/cz_utils.go | 0 .../go_src => src}/cmd/utils/user_util.go | 0 .../go_src => src}/cmd/utils/util_test.go | 0 {src_code/go_src => src}/main.go | 0 src_code/go_src/author_file | 4 - src_code/go_src/deprecated/cocommit.go | 309 ------------------ src_code/go_src/deprecated/cocommit_test.go | 126 ------- 22 files changed, 1 insertion(+), 439 deletions(-) rename {src_code/go_src => src}/LICENSE (100%) rename {src_code/go_src => src}/author.txt (100%) rename {src_code/go_src => src}/cmd/cmd_test.go (100%) rename {src_code/go_src => src}/cmd/cz.go (100%) rename {src_code/go_src => src}/cmd/root.go (100%) rename {src_code/go_src => src}/cmd/tui/README.md (100%) rename {src_code/go_src => src}/cmd/tui/tui_author.go (100%) rename {src_code/go_src => src}/cmd/tui/tui_commit_message.go (100%) rename {src_code/go_src => src}/cmd/tui/tui_list.go (100%) rename {src_code/go_src => src}/cmd/tui/tui_show_users.go (100%) rename {src_code/go_src => src}/cmd/tui/tui_test.go (100%) rename {src_code/go_src => src}/cmd/users.go (100%) rename {src_code/go_src => src}/cmd/utils/author_file_utils.go (100%) rename {src_code/go_src => src}/cmd/utils/commit.go (100%) rename {src_code/go_src => src}/cmd/utils/cz_utils.go (100%) rename {src_code/go_src => src}/cmd/utils/user_util.go (100%) rename {src_code/go_src => src}/cmd/utils/util_test.go (100%) rename {src_code/go_src => src}/main.go (100%) delete mode 100644 src_code/go_src/author_file delete mode 100644 src_code/go_src/deprecated/cocommit.go delete mode 100644 src_code/go_src/deprecated/cocommit_test.go diff --git a/.gitignore b/.gitignore index 28f8353..a28581a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Custom dist +author_file go.work go.sum diff --git a/src_code/go_src/LICENSE b/src/LICENSE similarity index 100% rename from src_code/go_src/LICENSE rename to src/LICENSE diff --git a/src_code/go_src/author.txt b/src/author.txt similarity index 100% rename from src_code/go_src/author.txt rename to src/author.txt diff --git a/src_code/go_src/cmd/cmd_test.go b/src/cmd/cmd_test.go similarity index 100% rename from src_code/go_src/cmd/cmd_test.go rename to src/cmd/cmd_test.go diff --git a/src_code/go_src/cmd/cz.go b/src/cmd/cz.go similarity index 100% rename from src_code/go_src/cmd/cz.go rename to src/cmd/cz.go diff --git a/src_code/go_src/cmd/root.go b/src/cmd/root.go similarity index 100% rename from src_code/go_src/cmd/root.go rename to src/cmd/root.go diff --git a/src_code/go_src/cmd/tui/README.md b/src/cmd/tui/README.md similarity index 100% rename from src_code/go_src/cmd/tui/README.md rename to src/cmd/tui/README.md diff --git a/src_code/go_src/cmd/tui/tui_author.go b/src/cmd/tui/tui_author.go similarity index 100% rename from src_code/go_src/cmd/tui/tui_author.go rename to src/cmd/tui/tui_author.go diff --git a/src_code/go_src/cmd/tui/tui_commit_message.go b/src/cmd/tui/tui_commit_message.go similarity index 100% rename from src_code/go_src/cmd/tui/tui_commit_message.go rename to src/cmd/tui/tui_commit_message.go diff --git a/src_code/go_src/cmd/tui/tui_list.go b/src/cmd/tui/tui_list.go similarity index 100% rename from src_code/go_src/cmd/tui/tui_list.go rename to src/cmd/tui/tui_list.go diff --git a/src_code/go_src/cmd/tui/tui_show_users.go b/src/cmd/tui/tui_show_users.go similarity index 100% rename from src_code/go_src/cmd/tui/tui_show_users.go rename to src/cmd/tui/tui_show_users.go diff --git a/src_code/go_src/cmd/tui/tui_test.go b/src/cmd/tui/tui_test.go similarity index 100% rename from src_code/go_src/cmd/tui/tui_test.go rename to src/cmd/tui/tui_test.go diff --git a/src_code/go_src/cmd/users.go b/src/cmd/users.go similarity index 100% rename from src_code/go_src/cmd/users.go rename to src/cmd/users.go diff --git a/src_code/go_src/cmd/utils/author_file_utils.go b/src/cmd/utils/author_file_utils.go similarity index 100% rename from src_code/go_src/cmd/utils/author_file_utils.go rename to src/cmd/utils/author_file_utils.go diff --git a/src_code/go_src/cmd/utils/commit.go b/src/cmd/utils/commit.go similarity index 100% rename from src_code/go_src/cmd/utils/commit.go rename to src/cmd/utils/commit.go diff --git a/src_code/go_src/cmd/utils/cz_utils.go b/src/cmd/utils/cz_utils.go similarity index 100% rename from src_code/go_src/cmd/utils/cz_utils.go rename to src/cmd/utils/cz_utils.go diff --git a/src_code/go_src/cmd/utils/user_util.go b/src/cmd/utils/user_util.go similarity index 100% rename from src_code/go_src/cmd/utils/user_util.go rename to src/cmd/utils/user_util.go diff --git a/src_code/go_src/cmd/utils/util_test.go b/src/cmd/utils/util_test.go similarity index 100% rename from src_code/go_src/cmd/utils/util_test.go rename to src/cmd/utils/util_test.go diff --git a/src_code/go_src/main.go b/src/main.go similarity index 100% rename from src_code/go_src/main.go rename to src/main.go diff --git a/src_code/go_src/author_file b/src_code/go_src/author_file deleted file mode 100644 index 7a65fb8..0000000 --- a/src_code/go_src/author_file +++ /dev/null @@ -1,4 +0,0 @@ -Syntax for authorfile -test|test|test|test|ex;;test -tet|tessadsat|teta|asdadad|ex;;adsadas -teadsajdma|asdasdasda|adsdadasd|addsadasd;;adsadsadadas \ No newline at end of file diff --git a/src_code/go_src/deprecated/cocommit.go b/src_code/go_src/deprecated/cocommit.go deleted file mode 100644 index f0a4c7f..0000000 --- a/src_code/go_src/deprecated/cocommit.go +++ /dev/null @@ -1,309 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "os" - "os/exec" - "regexp" - "slices" - "sort" - "strings" -) - -type user struct { - username string - email string - names string -} -//TODO: Remove later once everything is up and running with the new version - -// Map of all th users in the author file -var users = make(map[string]user) - -// String builder for building the commit message -var sb strings.Builder - -// Flag that can be toggled to include all users in a commit message (excluding defExclude) -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() { - - // Reads a shell env variable :: author_file - var authors string - envVar := os.Getenv("author_file") - if envVar == "" { - var err error - authors, err = os.UserConfigDir() - authors += "/cocommit/authors" - if err != nil { - println("Error: ", err) - os.Exit(1) - } - } else { - authors = envVar - } - - file, err := os.Open(authors) - if err != nil { - authors, _ = os.UserConfigDir() - authors += "/cocommit/authors" - println("Authors file cannot be found. Please check the path to the file. \nEither set the author_file env variable or place the file in the default location. \nDefault location: " + authors) - println("If you want to create a blank template file at the default location type y|yes or cancel with n|no") - var input string - fmt.Scanln(&input) - if input == "y" || input == "yes" { - create_author_file("yes") - os.Exit(1) - } else { - println("Cancelled") - os.Exit(1) - } - } - defer file.Close() - - scanner := bufio.NewScanner(file) - - // eat a single input - scanner.Scan() - - // reads the input of authors file and formats accordingly - for scanner.Scan() { - input_str := scanner.Text() - group_info := []string{} - if strings.Contains(input_str, ";;") { - input := strings.Split(input_str, ";;") - input_str = input[0] - group_info = append(group_info, strings.Split(input[1], "|")...) - } - info := strings.Split(input_str, "|") - usr := user{username: info[2], email: info[3], names: info[0] + "/" + info[1]} - users[info[0]] = usr - users[info[1]] = usr - // Adds users with the ex tag to the defExclude list - if len(info) == 5 { - if info[4] == "ex" { - defExclude = append(defExclude, info[2]) - } - } else if len(group_info) > 0 { - // Group assignment - for _, group := range group_info { - 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 - } - } - } - } - - check_err(scanner.Err()) - // Removes the call command for the program - args := os.Args[1:] - - // Checks if the user called the program with any inputs or with non commit args - NoInput(args, users) - - // This list is used when doing negations and for removing duplicate users during string building - excludeMode := []string{} - - // builds the commit message with the selected authors - sb.WriteString(string(args[0]) + "\n") - - // Regex that catches one off authors - reg, _ := regexp.Compile("([^:]+):([^:]+)") - - 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 - for _, committer := range args[1:] { - if _, ok := users[committer]; ok { - sb_author(committer) - } else if match := reg.MatchString(committer); match { - str := strings.Split(committer, ":") - - sb.WriteString("\nCo-authored-by: ") - sb.WriteString(str[0]) - sb.WriteString(" <") - sb.WriteString(str[1]) - sb.WriteRune('>') - - } else if committer[0] == '^' { // Negations - excludeMode = append(excludeMode, users[committer[1:]].username) - - } else { - println(committer, " was unknown. User either not defined or name typed wrong") - } - } - - // Skip label for adding all -skip_loop: - - if len(excludeMode) > 0 || all_flag { - // adds all users not in the excludeMode list - add_x_users(excludeMode) - } - - // commit msg built - commit := sb_build() - - print(commit) - - //NOTE: Uncomment for testing - //print(commit) - - // commit shell command - cmd := exec.Command("git", "commit", "-m", commit) - - // https://stackoverflow.com/questions/18159704/how-to-debug-exit-status-1-error-when-running-exec-command-in-golang - - cmd_output, err := cmd.CombinedOutput() - - if err != nil { - println(fmt.Sprint(err) + " : " + string(cmd_output)) - } else { - println(string(cmd_output)) - } - -} - -func group_selection(group []user, excludeMode []string) []string { - for _, user := range users { - if !(slices.Contains(group, user)) { - excludeMode = append(excludeMode, user.username) - } - } - - return excludeMode -} - -func add_x_users(excludeMode []string) { - if len(defExclude) > 0 { - excludeMode = append(excludeMode, defExclude...) - } - for key, user := range users { - if !slices.Contains(excludeMode, user.username) { - sb_author(key) - excludeMode = append(excludeMode, user.username) - } - } -} - -func sb_build() string { - return sb.String() -} - -func sb_author(committer string) { - sb.WriteString("\nCo-authored-by: ") - sb.WriteString(users[committer].username) - sb.WriteString(" <") - sb.WriteString(users[committer].email) - sb.WriteRune('>') -} - -// TODO: move half this into another function and call before building users to improve performance -func NoInput(args []string, users map[string]user) { - if len(args) < 2 { - // If you call binary with users prints users - if len(args) == 1 && args[0] == "users" { - println("List of users:\nFormat: / -> Username: Email: ") - seen_users := []user{} - user_sb := []string{} - for name, usr := range users { - if !slices.Contains(seen_users, usr) { - user_sb = append(user_sb, users[name].names+" ->"+" Username: "+usr.username+" Email: "+usr.email+"\n") - seen_users = append(seen_users, usr) - } - } - sort.Strings(user_sb) - println(strings.Join(user_sb, "")) - os.Exit(1) - } else if len(args) == 1 && args[0] == "config" { - create_author_file() - } - // if calling binary with nothing or only string - command_options := []string{ - "cocommit [co-author2] [co-author3]", - "cocommit [co-author2:email] [co-author3:email]", - "cocommit all", - "cocommit ^ ^[co-author2]", - "cocommit ", - "cocommit users", - } - println("Usage:") - for _, v := range command_options { - print(v) - println(" ||") - } - println("Mixes of both") - - os.Exit(1) - } -} - -func create_author_file(param ...string) { - var input string - authors, err := os.UserConfigDir() - - if err != nil { - println("Error: ", err) - os.Exit(1) - } - if len(param) > 0 { - input = "yes" - goto skip - } - println("This command will create a blank template auhtor file in the default location. \nDefault location: " + authors + "\nConfirm by typing y|yes or cancel with n|no") - fmt.Scanln(&input) - if err != nil { - println("Error: ", err) - os.Exit(1) - } -skip: - if input == "y" || input == "yes" { - // create folder cocommit in .config - authors += "/cocommit" - err := os.MkdirAll(authors, 0755) - if err != nil { - println("Error in dir creation: ", err.Error()) - os.Exit(1) - } - authors += "/authors" - file, err := os.Create(authors) - if err != nil { - println("Error: ", err.Error()) - os.Exit(1) - } - defer file.Close() - file.WriteString("name_short|Name|Username|email (opt: |ex) (opt: ;;group1 or ;;group1|group2|group3...)\n") - println("File created successfully at: " + authors) - os.Exit(1) - } else { - println("Cancelled") - os.Exit(1) - } -} - -func check_err(e error) { - if e != nil { - fmt.Println(e.Error()) - os.Exit(2) - } -} \ No newline at end of file diff --git a/src_code/go_src/deprecated/cocommit_test.go b/src_code/go_src/deprecated/cocommit_test.go deleted file mode 100644 index 5c62140..0000000 --- a/src_code/go_src/deprecated/cocommit_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package main - -import ( - "os" - "os/exec" - "strings" - "testing" -) - -func Test_emptyInput(t *testing.T) { - authors := make(map[string]user) - authors["test"] = user{username: "test", email: "test"} - if os.Getenv("BE_CRASHER") == "1" { - NoInput([]string{}, authors) - return - } - cmd := exec.Command(os.Args[0], "-test.run=Test_emptyInput") - cmd.Env = append(os.Environ(), "BE_CRASHER=1") - err := cmd.Run() - if e, ok := err.(*exec.ExitError); ok && !e.Success() { - return - } - t.Fatalf("process ran with err %v, want exit status 1", err) -} - -func Test_usersInput(t *testing.T) { - authors := make(map[string]user) - authors["test"] = user{username: "test", email: "test"} - if os.Getenv("BE_CRASHER") == "1" { - NoInput([]string{"users"}, authors) - return - } - cmd := exec.Command(os.Args[0], "-test.run=Test_usersInput") - cmd.Env = append(os.Environ(), "BE_CRASHER=1") - err := cmd.Run() - if e, ok := err.(*exec.ExitError); ok && !e.Success() { - return - } - t.Fatalf("process ran with err %v, want exit status 1", err) -} -//TODO: Turn this into a fuzz test - -func Test_commit_message(t *testing.T) { - //authors := make(map[string]user) - users["test"] = user{username: "test", email: "test"} - sb_author("test") - commit := sb_build() - if commit != "\nCo-authored-by: test " { - t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test ",commit) - } -} -//TODO: Turn this into a fuzz test -func Test_add_all(t *testing.T) { - for k := range users { - delete(users, k) - } - sb.Reset() - users["test1"] = user{username: "test1", email: "test1"} - users["test2"] = user{username: "test2", email: "test2"} - users["test3"] = user{username: "test3", email: "test3"} - all_flag = true - add_x_users([]string{}) - - commit := sb_build() - if !strings.Contains(commit, "\nCo-authored-by: test1 ") || - !strings.Contains(commit, "\nCo-authored-by: test2 ") || - !strings.Contains(commit, "\nCo-authored-by: test3 ") { - t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test1 \nCo-authored-by: test2 \n\nCo-authored-by: test3 ",commit) - } -} - -func Test_exclude_user(t *testing.T) { - // Reusing users map from last test - excludeMode := []string{"test1"} - - sb.Reset() - - add_x_users(excludeMode) - - commit := sb_build() - if strings.Contains(commit, "\nCo-authored-by: test1 ") { - t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test2 \n\nCo-authored-by: test3 ",commit) - } -} - -func Test_exclude_by_default(t *testing.T) { - // Reusing users from before - defExclude = append(defExclude, users["test1"].username) - - sb.Reset() - - add_x_users([]string{}) - - commit := sb_build() - - if strings.Contains(commit, "\nCo-authored-by: test1 ") { - t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test2 \n\nCo-authored-by: test3 ",commit) - } -} - -func Test_commit_with_grouping(t *testing.T) { - for k := range groups { - delete(groups, k) - } - - defExclude = []string{} - - groups["test1"] = []user{users["test1"]} - - excludeMode := group_selection(groups["test1"], []string{}) - - sb.Reset() - - add_x_users(excludeMode) - - commit := sb_build() - - if commit != "\nCo-authored-by: test1 " { - t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test ",commit) - } - -} - - - -