Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
12 changes: 11 additions & 1 deletion auto-function.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ func FormattedFunction(diff, lang string) string {
return ""
}

return strings.Join(results, " | ")
parser := strings.Join(results, " | ")
for len(parser) > int(MAX_COMMIT_LENGTH) && len(results) > 1 {
results = results[:len(results)-1]
parser = strings.Join(results, " | ")
}

if len(parser) > int(MAX_COMMIT_LENGTH) && len(results) == 1 {
parser = parser[:int(MAX_COMMIT_LENGTH)]
}

return parser
}

func parseGoFunction(line string) *types.FunctionSignature {
Expand Down
12 changes: 11 additions & 1 deletion auto-import.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ func FormattedImport(diff, lang, filename string) string {
quoted[i] = "'" + imp + "'"
}

return "included " + strings.Join(quoted, ", ") + " in " + filename
result := "included " + strings.Join(quoted, ", ") + " in " + filename
for len(result) > int(MAX_COMMIT_LENGTH) && len(quoted) > 1 {
quoted = quoted[:len(quoted)-1]
result = "included " + strings.Join(quoted, ", ") + " in " + filename
}

if len(result) > int(MAX_COMMIT_LENGTH) && len(quoted) == 1 {
result = result[:int(MAX_COMMIT_LENGTH)]
}

return result
}

return ""
Expand Down
158 changes: 118 additions & 40 deletions auto-logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func extractIfBlocks(lines []string, lang string, isNew bool) []string {
case "python":
ifRegex = regexp.MustCompile(`if\s+([^:]+):`)
case "go":
ifRegex = regexp.MustCompile(`^\s*if\b`)
ifRegex = regexp.MustCompile(`^\s*if\s+(.*)`)
case "c", "cpp", "java", "csharp", "typescript", "javascript":
ifRegex = regexp.MustCompile(`if\s*\(([^)]+)\)`)
default:
Expand All @@ -99,8 +99,11 @@ func extractIfBlocks(lines []string, lang string, isNew bool) []string {
return blocks
}

func _(expr string) string { // describeCondition
func describeCondition(expr string) string {
expr = strings.TrimSpace(expr)
if idx := strings.Index(expr, "{"); idx != -1 {
expr = strings.TrimSpace(expr[:idx])
}

replacements := []struct {
pattern *regexp.Regexp
Expand All @@ -112,6 +115,11 @@ func _(expr string) string { // describeCondition
{regexp.MustCompile(`(\w+)\s*>\s*(\d+)`), "if $1 is greater than $2"},
}

// {regexp.MustCompile(`(.+?)\s*==\s*"?(.+?)"?$`), "if $1 is equal to $2"},
// {regexp.MustCompile(`(.+?)\s*!=\s*"?(.+?)"?$`), "if $1 is not equal to $2"},
// {regexp.MustCompile(`(.+?)\s*<\s*(.+?)$`), "if $1 is less than $2"},
// {regexp.MustCompile(`(.+?)\s*>\s*(.+?)$`), "if $1 is greater than $2"},

for _, r := range replacements {
if r.pattern.MatchString(expr) {
return r.pattern.ReplaceAllString(expr, r.replace)
Expand All @@ -136,65 +144,135 @@ func FormattedLogic(line, lang, filename string) string {

if len(newIfs) > 0 && len(oldIfs) == 0 {
builder.Reset()
builder.WriteString("added logic to the ")
builder.WriteString("'")
builder.WriteString(filename)
builder.WriteString("'")
builder.WriteString(" file")
return builder.String()
}

if len(oldSwitches) > 0 && len(newSwitches) == 0 {
builder.WriteString("deleted switch: ")
for i, sw := range oldSwitches {
for i, cond := range newIfs {
if i > 0 {
builder.WriteString("; ")
}
builder.WriteString(sw.Expr)

if len(sw.Cases) > 0 {
builder.WriteString(" (cases: ")
builder.WriteString(strings.ReplaceAll(strings.Join(sw.Cases, ", "), "\"", "'"))
builder.WriteString(")")
builder.WriteString(describeCondition(cond))
}

result := builder.String()
for len(result) > int(MAX_COMMIT_LENGTH) && len(newIfs) > 1 {
newIfs = newIfs[:len(newIfs)-1]
builder.Reset()

for i, cond := range newIfs {
if i > 0 {
builder.WriteString("; ")
}

builder.WriteString(describeCondition(cond))
}

result = builder.String()
}

if len(result) > int(MAX_COMMIT_LENGTH) && len(newIfs) == 1 {
result = result[:int(MAX_COMMIT_LENGTH)]
}

return builder.String()
return result
}

if len(newSwitches) > 0 && len(oldSwitches) == 0 {
builder.WriteString("added switch: ")
for i, sw := range newSwitches {
if i > 0 {
builder.WriteString("; ")
if len(oldSwitches) > 0 && len(newSwitches) == 0 {
makeResult := func(switches []types.SwitchSignature) string {
var b strings.Builder
b.WriteString("removed switch on ")
for i, sw := range switches {
if i > 0 {
b.WriteString("; ")
}
b.WriteString("'" + sw.Expr + "'")
if len(sw.Cases) > 0 {
b.WriteString(" with cases: ")
b.WriteString(strings.ReplaceAll(strings.Join(sw.Cases, ", "), "\"", "'"))
}
}
builder.WriteString(sw.Expr)

if len(sw.Cases) > 0 {
builder.WriteString(" (cases: ")
builder.WriteString(strings.ReplaceAll(strings.Join(sw.Cases, ", "), "\"", "'"))
builder.WriteString(")")
return b.String()
}

result := makeResult(oldSwitches)
for len(result) > int(MAX_COMMIT_LENGTH) && len(oldSwitches) > 1 {
oldSwitches = oldSwitches[:len(oldSwitches)-1]
result = makeResult(oldSwitches)
}

if len(result) > int(MAX_COMMIT_LENGTH) && len(oldSwitches) == 1 {
result = result[:int(MAX_COMMIT_LENGTH)]
}

return result
}

if len(newSwitches) > 0 && len(oldSwitches) == 0 {
makeResult := func(switches []types.SwitchSignature) string {
var b strings.Builder
b.WriteString("added switch on ")
for i, sw := range switches {
if i > 0 {
b.WriteString("; ")
}
b.WriteString("'" + sw.Expr + "'")
if len(sw.Cases) > 0 {
b.WriteString(" with cases: ")
b.WriteString(strings.ReplaceAll(strings.Join(sw.Cases, ", "), "\"", "'"))
}
}

return b.String()
}

return builder.String()
result := makeResult(newSwitches)
for len(result) > int(MAX_COMMIT_LENGTH) && len(newSwitches) > 1 {
newSwitches = newSwitches[:len(newSwitches)-1]
result = makeResult(newSwitches)
}

if len(result) > int(MAX_COMMIT_LENGTH) && len(newSwitches) == 1 {
result = result[:int(MAX_COMMIT_LENGTH)]
}

return result
}

if len(oldSwitches) > 0 && len(newSwitches) > 0 {
osw := oldSwitches[0]
nsw := newSwitches[0]
if osw.Expr != nsw.Expr || strings.Join(osw.Cases, ",") != strings.Join(nsw.Cases, ",") {
builder.WriteString("changed logic switch '")
builder.WriteString(osw.Expr)
builder.WriteString(" (cases: ")
builder.WriteString(strings.Join(osw.Cases, ", "))
builder.WriteString(")' -> '")
builder.WriteString(nsw.Expr)
builder.WriteString(" (cases: ")
builder.WriteString(strings.ReplaceAll(strings.Join(nsw.Cases, ", "), "\"", "'"))
builder.WriteString(")'")
return builder.String()

makeResult := func(osw, nsw types.SwitchSignature) string {
var b strings.Builder
b.WriteString("changed switch from '")
b.WriteString(osw.Expr)
b.WriteString("' (cases: ")
b.WriteString(strings.Join(osw.Cases, ", "))
b.WriteString(") to '")
b.WriteString(nsw.Expr)
b.WriteString("' (cases: ")
b.WriteString(strings.ReplaceAll(strings.Join(nsw.Cases, ", "), "\"", "'"))
b.WriteString(")")

return b.String()
}

result := makeResult(osw, nsw)
for len(result) > int(MAX_COMMIT_LENGTH) && (len(osw.Cases) > 1 || len(nsw.Cases) > 1) {
if len(osw.Cases) > len(nsw.Cases) {
osw.Cases = osw.Cases[:len(osw.Cases)-1]
} else {
nsw.Cases = nsw.Cases[:len(nsw.Cases)-1]
}

result = makeResult(osw, nsw)
}

if len(result) > int(MAX_COMMIT_LENGTH) && len(osw.Cases) == 1 && len(nsw.Cases) == 1 {
result = result[:int(MAX_COMMIT_LENGTH)]
}

return result
}

return ""
Expand Down
12 changes: 11 additions & 1 deletion auto-variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,15 @@ func FormattedVariables(diff, lang string) string {
return ""
}

return strings.Join(results, " | ")
parser := strings.Join(results, " | ")
for len(parser) > int(MAX_COMMIT_LENGTH) && len(results) > 1 {
results = results[:len(results)-1]
parser = strings.Join(results, " | ")
}

if len(parser) > int(MAX_COMMIT_LENGTH) && len(results) == 1 {
parser = parser[:int(MAX_COMMIT_LENGTH)]
}

return parser
}
Binary file modified bin/auto-commit
Binary file not shown.
7 changes: 4 additions & 3 deletions define.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package main
import "time"

const (
MAX_LINE_LENGTH uint16 = 1024
MAX_COMMIT_LENGTH uint16 = 300
COMMIT_TIME time.Duration = 27 * time.Second
MAX_LINE_LENGTH uint16 = 1024
MAX_COMMIT_LENGTH uint16 = 300
MAX_COMMIT_LENGTH_WATCHER uint16 = 60
COMMIT_TIME time.Duration = 17 * time.Second
)
17 changes: 15 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Parser(files []string) (string, error) {

for file := range jobs {
mu.Lock()
if uint16(len(strings.Fields(payloadMsg))) > MAX_COMMIT_LENGTH {
if uint16(len(payloadMsg)) > MAX_COMMIT_LENGTH {
mu.Unlock()
continue
}
Expand Down Expand Up @@ -79,7 +79,20 @@ func Parser(files []string) (string, error) {
if len(fileChanges) > 0 {
mu.Lock()
for _, change := range fileChanges {
payloadMsg = appendMsg(payloadMsg, change)
nextMsg := appendMsg(payloadMsg, change)
if len(nextMsg) > int(MAX_COMMIT_LENGTH) {
if len(payloadMsg) == 0 {
if len(change) > int(MAX_COMMIT_LENGTH) {
change = change[:int(MAX_COMMIT_LENGTH)]
}

payloadMsg = change
}

break
}

payloadMsg = nextMsg
}
mu.Unlock()
}
Expand Down
2 changes: 1 addition & 1 deletion watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func WatchCommit(path string) {
return
}

if len(strings.Fields(parser)) >= 255 {
if uint16(len(parser)) >= MAX_COMMIT_LENGTH_WATCHER {
if err := Commit(parser); err != nil {
ErrorLogger(err)
}
Expand Down