Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
ee50a1c
added function TestAutoCommit_NoStagedFiles | included 'testing' in a…
noneandundefined Jun 29, 2025
d52b91f
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
d40f640
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
be44d79
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
3a8c057
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
b944e59
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
df47c71
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
f51e05e
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
e0bcf61
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
def8157
added variable calledInfo
noneandundefined Jun 29, 2025
a8aadb8
added condition logic: calledInfo
noneandundefined Jun 29, 2025
cd9bc2e
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
c54b7eb
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
3fce71e
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
15df210
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
a030644
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
5214e20
added variable calledInfo | added function TestAutoCommit_NoStagedFil…
noneandundefined Jun 29, 2025
cce2545
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
1b7b5dc
if msg is not equal to No files staged for commit."
noneandundefined Jun 29, 2025
029a040
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
443f0a5
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
61ae439
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
7a7dbd6
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
2ad96b3
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
bf95b22
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
b02e613
renamed function appendMsg -> AppendMsg
noneandundefined Jun 29, 2025
c434cee
changed value in variable nextMsg
noneandundefined Jun 29, 2025
fbf8697
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
44a2422
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
5cdc950
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
803b29a
added variable calledInfo
noneandundefined Jun 29, 2025
b20d2f5
added variable calledInfo
noneandundefined Jun 29, 2025
979f338
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
1f76696
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
1587f6c
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
2a2e573
added function TestAutoCommit_ErrorGettingFiles | if err is equal to …
noneandundefined Jun 29, 2025
68a2aa5
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
9594ba2
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
a0437ed
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
20b4522
added variable calledInfo
noneandundefined Jun 29, 2025
5d946a6
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
b645178
added variable calledError
noneandundefined Jun 29, 2025
9af377c
added variables: calledErr, expected | if calledErr is not equal to e…
noneandundefined Jun 29, 2025
eabaeb7
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
68d717e
added functions: TestAutoCommit_NoStagedFiles, TestAutoCommit_ErrorGe…
noneandundefined Jun 29, 2025
408ff15
the 'Makefile' file has been changed
noneandundefined Jun 29, 2025
fb8c944
the 'Makefile' file has been changed
noneandundefined Jun 29, 2025
8400002
added variables: calledInfo, calledErr, expected | added functions: T…
noneandundefined Jun 29, 2025
eeb300f
added variables: calledInfo, calledErr, expected | added functions: T…
noneandundefined Jun 29, 2025
b614400
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
4321814
added function TestParser
noneandundefined Jun 29, 2025
d3aca6f
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
0803902
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
16486c7
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
faa0a67
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
171ad94
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
ccb2067
if err is not equal to nil
noneandundefined Jun 29, 2025
d529b25
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
5fb46ca
added variable expected | if msg is not equal to expected
noneandundefined Jun 29, 2025
125c3be
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
7efc68b
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
4975c06
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
6c07b0c
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
aeb40a3
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
e499d0f
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
8da82e6
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
9cd84bc
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
5ac1c50
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
de59ac8
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
60aec9e
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
f83397b
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
340a2f3
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
c2a6867
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
d2f8d15
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
62ade17
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
4b74b05
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
8006e33
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
b997c6f
added variable restore | added variables: origGetStagedFiles, origPar…
noneandundefined Jun 29, 2025
501e872
changed value in variable restore
noneandundefined Jun 29, 2025
2728cbc
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
a8e6a40
deleted function SaveAndRestoreMocks | added structure Mocks | added …
noneandundefined Jun 29, 2025
e0fbf61
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
620d3ee
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
a83dc54
changed the 'v2.12.x' branch
noneandundefined Jun 29, 2025
1e5a037
added variables: mocks, mocks
noneandundefined Jun 29, 2025
d6c579c
added variable mocks | changed value in variable expected
noneandundefined Jun 29, 2025
40e87d9
changed value in variable expected
noneandundefined Jun 29, 2025
597e389
added static html code web-site
noneandundefined Jun 29, 2025
03bf2b4
the 'vercel.json' file has been changed | the 'index.html' file has b…
noneandundefined Jun 30, 2025
c400963
deleted function GetStagedFiles
noneandundefined Jun 30, 2025
5e72dc2
added variables: builder, cmd, buf, cmd, scanner | if err is not equa…
noneandundefined Jun 30, 2025
9b4f9f8
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
ab79c24
added variables: cmd, out, root, cmd | added functions: GetGitRoot, G…
noneandundefined Jun 30, 2025
773c804
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
a328e8a
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
95300fe
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
da773c4
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
6cb0512
added variables: builder, workers, jobs, lang, nextMsg | added functi…
noneandundefined Jun 30, 2025
a731d40
included 'time' in define.go
noneandundefined Jun 30, 2025
dce987a
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
2cd4441
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
d00b98c
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
70d28d0
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
5010730
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
4fa2cd6
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
6d62d56
added variables: lines, inImportBlock, trimmed, importName, quoted, l…
noneandundefined Jun 30, 2025
afebc5d
added variables: m, name, parent, methods, m, name, parent, methods, …
noneandundefined Jun 30, 2025
013ca29
added variables: lines, inImportBlock, trimmed, importName, quoted, l…
noneandundefined Jun 30, 2025
3e836a7
added variables: lines, line, parser, m, name, paramsString, params, …
noneandundefined Jun 30, 2025
6f95bab
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
5ae25e5
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
203c3ea
added variables: lines, inImportBlock, trimmed, importName, quoted, l…
noneandundefined Jun 30, 2025
1b18c6a
added variables: m, name, parent, methods, m, name, parent, methods, …
noneandundefined Jun 30, 2025
aa8758a
added variable ext | added switch on 'ext' with cases: '.go', '.py', …
noneandundefined Jun 30, 2025
5a6476a
changed value in variable lang
noneandundefined Jun 30, 2025
44cf2e5
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
1a63629
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
d614d61
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
f9bf842
added variables: re, match, cmd, url, regex, match, builder, buf, git…
noneandundefined Jun 30, 2025
662d1c2
changed value in variable issue
noneandundefined Jun 30, 2025
bf84e3a
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
3b909f9
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
e0efc6d
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
31de7b2
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
fc3aafe
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
bff8703
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
4052aa6
included 'git-auto-commit/diff' in test.g.go
noneandundefined Jun 30, 2025
c596a71
included 'git-auto-commit/diff', 'git-auto-commit/parser' in test.g.go
noneandundefined Jun 30, 2025
d9903b4
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
7b52286
added variable cmd | included 'fmt', 'os', 'os/exec' in commit.go
noneandundefined Jun 30, 2025
9a12aed
added variables: builder, builder, builder | included 'fmt', 'strings…
noneandundefined Jun 30, 2025
b6ae91d
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
bfe9c84
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
738e58a
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
04b2ce5
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
ebde600
changed value in variable versionFile
noneandundefined Jun 30, 2025
9960d5f
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
8b6cc9a
added variables: versionFile, data, scriptUpdate, scriptUpdateExt, tm…
noneandundefined Jun 30, 2025
130d8b8
added variables: versionFile, data | added variables: sigs, cmd | add…
noneandundefined Jun 30, 2025
fced47f
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
03436e0
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
f7b61ca
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
2193e62
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
73ca345
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
03da2af
changed value in variable versionFile
noneandundefined Jun 30, 2025
9438875
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
341adab
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
f653c11
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
cbcf490
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
81b4e4a
added variables: builder, builder, builder | included 'fmt', 'strings…
noneandundefined Jun 30, 2025
249287e
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
fc3a7d3
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
9ecd233
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
18b5102
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
25695f0
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
8534246
added variable ext | added switch on 'ext' with cases: '.go', '.py', …
noneandundefined Jun 30, 2025
3f1af95
changed value in variable lang
noneandundefined Jun 30, 2025
716624d
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
9af19b6
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
95cf405
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
a9019a1
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
7b153e3
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
72c762e
added variables: mocks, calledInfo, mocks, calledErr, expected | adde…
noneandundefined Jun 30, 2025
3246deb
added variables: mocks, expected | added functions: TestParser_AddedG…
noneandundefined Jun 30, 2025
a65ed55
added function SaveMocks | included 'git-auto-commit/achelper', 'git-…
noneandundefined Jun 30, 2025
3f7af74
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
4f2420f
included 'git-auto-commit/achelper/code', 'git-auto-commit/diff', 'gi…
noneandundefined Jun 30, 2025
af4fccd
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
a925a9c
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
191328c
added function AutoCommit | if err is not equal to nil; added conditi…
noneandundefined Jun 30, 2025
3c618c6
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
1c72b86
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
0aeef33
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
8a89293
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
6f4ffa1
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
c15c5b6
added variables: mocks, expected, mocks, expected | added functions: …
noneandundefined Jun 30, 2025
2125ef7
renamed function TestParser_DeletedGoFunction -> TestParser_RenamedGo…
noneandundefined Jun 30, 2025
1047481
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
58be572
changed value in variable expected
noneandundefined Jun 30, 2025
5c0b732
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
c617ff8
renamed functions: TestParser_AddedGoFunction -> TestFormattedFunctio…
noneandundefined Jun 30, 2025
935a69a
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
bcf5ec9
renamed function TestParser -> ParamTest
noneandundefined Jun 30, 2025
184d2f9
changed value in variable expected
noneandundefined Jun 30, 2025
70d8b51
changed value in variable expected
noneandundefined Jun 30, 2025
8a2bbd0
added variables: mocks, expected | added functions: TestFormattedFunc…
noneandundefined Jun 30, 2025
ad864a6
renamed functions: TestParser -> AddedGoFunction, TestParser -> Delet…
noneandundefined Jun 30, 2025
ad66640
changed value in variable expected | added type a
noneandundefined Jun 30, 2025
44ef06a
changed value in variable expected
noneandundefined Jun 30, 2025
54e8d77
changed value in variable expected
noneandundefined Jun 30, 2025
0fb0487
added variables: mocks, expected | added functions: TestFormattedFunc…
noneandundefined Jun 30, 2025
13b4151
renamed functions: TestFormattedFunction_AddedGoFunction -> TestForma…
noneandundefined Jun 30, 2025
86965c3
changed value in variable expected
noneandundefined Jun 30, 2025
cabdf67
changed value in variable expected
noneandundefined Jun 30, 2025
5e8deef
changed value in variable expected
noneandundefined Jun 30, 2025
f8b1010
added variables: mocks, expected | added functions: TestFormattedFunc…
noneandundefined Jun 30, 2025
4545408
changed the 'v2.12.x' branch
noneandundefined Jun 30, 2025
75b4423
changed value in variable expected | renamed function DeletedGoFuncti…
noneandundefined Jun 30, 2025
b947800
changed value in variable expected
noneandundefined Jun 30, 2025
2aca386
changed value in variable expected
noneandundefined Jun 30, 2025
2a088c8
added variables: mocks, expected | added functions: TestFormattedFunc…
noneandundefined Jun 30, 2025
858700d
renamed functions: TestFormattedFunction_ChangedParamNameGoFunction -…
noneandundefined Jun 30, 2025
9b46307
renamed function Foo -> ParamTest1
noneandundefined Jun 30, 2025
494f685
changed value in variable expected
noneandundefined Jun 30, 2025
651c698
changed value in variable expected
noneandundefined Jun 30, 2025
18b0efc
added variables: mocks, expected, mocks, expected, mocks, expected, m…
noneandundefined Jun 30, 2025
c095693
added variables: mocks, expected, mocks, expected, mocks, expected, m…
noneandundefined Jun 30, 2025
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
File renamed without changes.
36 changes: 36 additions & 0 deletions ac/ac.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ac

import (
"fmt"
"git-auto-commit/achelper"
"git-auto-commit/achelper/logger"
"git-auto-commit/diff"
"git-auto-commit/git"
"git-auto-commit/parser"
)

func AutoCommit() {
achelper.GetVersion(false)

files, err := diff.GetStagedFiles()
if err != nil {
logger.ErrorLogger(fmt.Errorf("error getting staged files: %s", err.Error()))
return
}

if len(files) == 0 {
logger.InfoLogger("No files staged for commit.")
return
}

parserMsg, err := parser.Parser(files)
if err != nil {
logger.ErrorLogger(err)
return
}

if err := git.Commit(parserMsg); err != nil {
logger.ErrorLogger(fmt.Errorf("error committing: %s", err.Error()))
return
}
}
4 changes: 2 additions & 2 deletions detected.go → achelper/code/detected.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main
package code

import (
"path/filepath"
"strings"
)

func DetectLanguage(filename string) string {
var DetectLanguage = func(filename string) string {
ext := strings.ToLower(filepath.Ext(filename))

switch ext {
Expand Down
8 changes: 4 additions & 4 deletions logger.go → achelper/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package main
package logger

import (
"fmt"
"strings"
)

func InfoLogger(msg string) {
var InfoLogger = func(msg string) {
var builder strings.Builder
builder.Reset()
builder.WriteString("[git auto-commit] ")
builder.WriteString(msg)
fmt.Println(builder.String())
}

func GitLogger(msg string) {
var GitLogger = func(msg string) {
var builder strings.Builder
builder.Reset()
builder.WriteString("\033[0;34m[git auto-commit] ")
Expand All @@ -22,7 +22,7 @@ func GitLogger(msg string) {
fmt.Print(builder.String())
}

func ErrorLogger(err error) {
var ErrorLogger = func(err error) {
var builder strings.Builder
builder.Reset()
builder.WriteString("\033[0;31m[git auto-commit] ")
Expand Down
26 changes: 15 additions & 11 deletions update.go → achelper/update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package main
package achelper

import (
"fmt"
"git-auto-commit/achelper/logger"
"git-auto-commit/config"
"git-auto-commit/constants"
"git-auto-commit/git"
"io"
"net/http"
"os"
Expand All @@ -12,32 +16,32 @@ import (
)

func AutoCommitUpdate() {
root, err := GetGitRoot()
root, err := git.GetGitRoot()
if err != nil {
ErrorLogger(err)
logger.ErrorLogger(err)
return
}

versionFile := filepath.Join(root, ".git", "hooks", VERSION_FILE)
versionFile := filepath.Join(root, ".git", "hooks", constants.VERSION_FILE)

version, err := os.ReadFile(versionFile)
if err != nil {
ErrorLogger(fmt.Errorf("unknown version for auto-commit, please re-install: %w", err))
logger.ErrorLogger(fmt.Errorf("unknown version for auto-commit, please re-install: %w", err))
return
}

resp, err := http.Get(GITHUB_API_REPO_URL + "/releases/latest")
resp, err := http.Get(constants.GITHUB_API_REPO_URL + "/releases/latest")
if err != nil {
ErrorLogger(fmt.Errorf("could not check latest version: %w", err))
logger.ErrorLogger(fmt.Errorf("could not check latest version: %w", err))
return
}
defer resp.Body.Close()

var data struct {
TagName string `json:"tag_name"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
ErrorLogger(fmt.Errorf("could not parse version info: %w", err))
if err := config.JSON.NewDecoder(resp.Body).Decode(&data); err != nil {
logger.ErrorLogger(fmt.Errorf("could not parse version info: %w", err))
return
}

Expand All @@ -61,7 +65,7 @@ func AutoCommitUpdate() {
tmpFile := filepath.Join(os.TempDir(), "auto-commit-update"+scriptUpdateExt)
err = downloadFile(scriptUpdate, tmpFile)
if err != nil {
ErrorLogger(fmt.Errorf("failed to download update script: %v", err))
logger.ErrorLogger(fmt.Errorf("failed to download update script: %v", err))
return
}
defer os.Remove(tmpFile)
Expand All @@ -77,7 +81,7 @@ func AutoCommitUpdate() {
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
ErrorLogger(fmt.Errorf("failed to run update script: %v", err))
logger.ErrorLogger(fmt.Errorf("failed to run update script: %v", err))
return
}
}
Expand Down
53 changes: 53 additions & 0 deletions achelper/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package achelper

import (
"fmt"
"git-auto-commit/achelper/logger"
"git-auto-commit/config"
"git-auto-commit/constants"
"git-auto-commit/git"
"net/http"
"os"
"path/filepath"
"strings"
)

var GetVersion = func(isCurrent bool) {
root, err := git.GetGitRoot()
if err != nil {
logger.ErrorLogger(fmt.Errorf("could not get git root: %w", err))
return
}

versionFile := filepath.Join(root, ".git", "hooks", constants.VERSION_FILE)

version, err := os.ReadFile(versionFile)
if err != nil {
logger.ErrorLogger(fmt.Errorf("unknown version for auto-commit, please re-install: %w", err))
return
}

if isCurrent {
fmt.Println("[git auto-commit] current version:", strings.TrimSpace(string(version)))
}

resp, err := http.Get(constants.GITHUB_API_REPO_URL + "/releases/latest")
if err != nil {
logger.ErrorLogger(fmt.Errorf("could not check latest version: %w", err))
return
}
defer resp.Body.Close()

var data struct {
TagName string `json:"tag_name"`
}
if err := config.JSON.NewDecoder(resp.Body).Decode(&data); err != nil {
logger.ErrorLogger(fmt.Errorf("could not parse version info: %w", err))
return
}

if strings.TrimSpace(string(version)) != strings.TrimSpace(data.TagName) {
fmt.Printf("\033[33m[!] a new version is available: %s\033[0m\n", strings.TrimSpace(data.TagName))
fmt.Printf("\033[33m[!] please update! 'git auto -u'\033[0m\n")
}
}
37 changes: 21 additions & 16 deletions watcher.go → achelper/watcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main
package achelper

import (
"fmt"
"git-auto-commit/achelper/logger"
"git-auto-commit/constants"
"git-auto-commit/diff"
"git-auto-commit/git"
"git-auto-commit/parser"
"os"
"os/exec"
"os/signal"
Expand All @@ -18,12 +23,12 @@ func WatchCommit(path string) {

watcher, err := fsnotify.NewWatcher()
if err != nil {
ErrorLogger(err)
logger.ErrorLogger(err)
return
}
defer watcher.Close()

InfoLogger("Started commit watcher...")
logger.InfoLogger("Started commit watcher...")

if err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if info.IsDir() && !strings.HasPrefix(path, ".git") {
Expand All @@ -34,15 +39,15 @@ func WatchCommit(path string) {

return nil
}); err != nil {
ErrorLogger(err)
logger.ErrorLogger(err)
return
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
InfoLogger("shutdown work watcher...")
logger.InfoLogger("shutdown work watcher...")
os.Exit(0)
}()

Expand All @@ -61,36 +66,36 @@ func WatchCommit(path string) {
}

if err := exec.Command("git", "add", ".").Run(); err != nil {
ErrorLogger(err)
logger.ErrorLogger(err)
return
}

files, err := GetStagedFiles()
files, err := diff.GetStagedFiles()
if err != nil {
ErrorLogger(fmt.Errorf("error getting staged files: %s", err.Error()))
logger.ErrorLogger(fmt.Errorf("error getting staged files: %s", err.Error()))
return
}

if len(files) == 0 {
InfoLogger("No files staged for commit.")
logger.InfoLogger("No files staged for commit.")
}

parser, err := Parser(files)
parser, err := parser.Parser(files)
if err != nil {
ErrorLogger(err)
logger.ErrorLogger(err)
return
}

if uint16(len(parser)) >= MAX_COMMIT_LENGTH_WATCHER {
if err := Commit(parser); err != nil {
ErrorLogger(err)
if uint16(len(parser)) >= constants.MAX_COMMIT_LENGTH_WATCHER {
if err := git.Commit(parser); err != nil {
logger.ErrorLogger(err)
}
}
}
case err := <-watcher.Errors:
ErrorLogger(err)
logger.ErrorLogger(err)
}

time.Sleep(COMMIT_TIME)
time.Sleep(constants.COMMIT_TIME)
}
}
1 change: 1 addition & 0 deletions acpkg/acpkg-comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package acpkg
9 changes: 5 additions & 4 deletions auto-function.go → acpkg/acpkg-function.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main
package acpkg

import (
"git-auto-commit/constants"
"git-auto-commit/types"
"regexp"
"strings"
Expand Down Expand Up @@ -121,13 +122,13 @@ func FormattedFunction(diff, lang string) string {
}

parser := strings.Join(results, " | ")
for len(parser) > int(MAX_COMMIT_LENGTH) && len(results) > 1 {
for len(parser) > int(constants.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)]
if len(parser) > int(constants.MAX_COMMIT_LENGTH) && len(results) == 1 {
parser = parser[:int(constants.MAX_COMMIT_LENGTH)]
}

return parser
Expand Down
9 changes: 5 additions & 4 deletions auto-import.go → acpkg/acpkg-import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main
package acpkg

import (
"git-auto-commit/constants"
"regexp"
"strings"
)
Expand Down Expand Up @@ -86,13 +87,13 @@ func FormattedImport(diff, lang, filename string) string {
}

result := "included " + strings.Join(quoted, ", ") + " in " + filename
for len(result) > int(MAX_COMMIT_LENGTH) && len(quoted) > 1 {
for len(result) > int(constants.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)]
if len(result) > int(constants.MAX_COMMIT_LENGTH) && len(quoted) == 1 {
result = result[:int(constants.MAX_COMMIT_LENGTH)]
}

return result
Expand Down
Loading