mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
refactor: rewrite parts of the commit function to be a bit more sane, removed the jump as well
This commit is contained in:
+31
-34
@@ -10,54 +10,51 @@ import (
|
||||
|
||||
// This util file is used to create a commit message using a string builder
|
||||
|
||||
// string builder for the commit message
|
||||
var sb strings.Builder
|
||||
|
||||
// list of excluded authors based on the author file
|
||||
var excludeMode = []string{}
|
||||
|
||||
// Regex pattern used to create temp users to add to the commit message
|
||||
var reg, _ = regexp.Compile("([^:]+):([^:]+)")
|
||||
|
||||
func Commit(message string, authors []string) string {
|
||||
// string builder for the commit message
|
||||
var sb strings.Builder
|
||||
excludeMode := []string{}
|
||||
|
||||
// write the commit message to the string builder
|
||||
sb.WriteString(message + "\n")
|
||||
fst := authors[0]
|
||||
|
||||
if fst == "all" || fst == "All" {
|
||||
add_x_users(excludeMode)
|
||||
goto skip_loop
|
||||
add_x_users(excludeMode, &sb)
|
||||
return sb.String()
|
||||
} else if Groups[fst] != nil {
|
||||
excludeMode = group_selection(Groups[fst], excludeMode)
|
||||
add_x_users(excludeMode)
|
||||
goto skip_loop
|
||||
add_x_users(excludeMode, &sb)
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// Loop that adds users
|
||||
for _, committer := range authors {
|
||||
if _, ok := Users[committer]; ok {
|
||||
sb_author(committer)
|
||||
} else if match := reg.MatchString(committer); match {
|
||||
str := strings.Split(committer, ":")
|
||||
// Loop that adds users
|
||||
for _, committer := range authors {
|
||||
if _, ok := Users[committer]; ok {
|
||||
sb_author(committer, &sb)
|
||||
} 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('>')
|
||||
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")
|
||||
}
|
||||
}
|
||||
if len(excludeMode) > 0 {
|
||||
add_x_users(excludeMode)
|
||||
} 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 edge cases at top of function
|
||||
skip_loop:
|
||||
// Add excluded users after processing all authors
|
||||
if len(excludeMode) > 0 {
|
||||
add_x_users(excludeMode, &sb)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
@@ -95,7 +92,7 @@ func GitPush() {
|
||||
}
|
||||
|
||||
// helper function to add an author to the commit message
|
||||
func sb_author(committer string) {
|
||||
func sb_author(committer string, sb *strings.Builder) {
|
||||
sb.WriteString("\nCo-authored-by: ")
|
||||
sb.WriteString(Users[committer].Username)
|
||||
sb.WriteString(" <")
|
||||
@@ -104,13 +101,13 @@ func sb_author(committer string) {
|
||||
}
|
||||
|
||||
// helper function to add x amount of users to the commit message
|
||||
func add_x_users(excludeMode []string) {
|
||||
func add_x_users(excludeMode []string, sb *strings.Builder) {
|
||||
if len(DefExclude) > 0 {
|
||||
excludeMode = append(excludeMode, DefExclude...)
|
||||
}
|
||||
for key, user := range Users {
|
||||
if !slices.Contains(excludeMode, user.Username) {
|
||||
sb_author(key)
|
||||
sb_author(key, sb)
|
||||
excludeMode = append(excludeMode, user.Username)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user