Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ae6e2f
added new files
noneandundefined May 8, 2025
826b133
rewrite C -> golang and added variables parsed
noneandundefined May 8, 2025
3894b98
rewrite C -> golang and added variables parsed
noneandundefined May 8, 2025
7cf5b5f
rewrite C -> golang and added variables parsed
noneandundefined May 8, 2025
26ed2da
added issues file and files file for get issues and anothers changed …
noneandundefined May 8, 2025
3494c3a
Merge pull request #17 from thefuture-industries/varible-commit
noneandundefined May 8, 2025
8c7d9fd
renamed 100 -> fclass.go, 100 -> ffunction.go, 100 -> flogic.go, 100 …
noneandundefined May 8, 2025
0423d4e
changed auto-function.go, auto-variables.go, bin/auto-commit, parser.…
noneandundefined May 8, 2025
57d3b86
changed auto-function.go, bin/auto-commit
noneandundefined May 8, 2025
7794c16
changed auto-function.go, bin/auto-commit, types/types.go
noneandundefined May 8, 2025
cac143c
changed auto-function.go, bin/auto-commit
noneandundefined May 8, 2025
d424ec0
changed auto-function.go, bin/auto-commit
noneandundefined May 8, 2025
20d7c67
Merge pull request #22 from thefuture-industries/ffunctions
noneandundefined May 9, 2025
4d911c7
added fclass watch to changed methods
noneandundefined May 9, 2025
c42e963
added logic and check length commit = 1024
noneandundefined May 9, 2025
7857e73
Merge pull request #23 from thefuture-industries/fclass
noneandundefined May 9, 2025
fd35274
including logger.go | changed auto-class.go, auto-variables.go, commi…
noneandundefined May 9, 2025
4b0ebde
added remote and branches changed commit
noneandundefined May 9, 2025
027ca9f
changed auto-remote.go, bin/auto-commit, issues.go, types/types.go
noneandundefined May 9, 2025
9c95256
changed auto-structure.go, bin/auto-commit, types/types.go
noneandundefined May 9, 2025
150baba
the 'README.md' file has been changed | added function parseStruct | …
noneandundefined May 9, 2025
323dbb0
added function parseCSharpFunction
noneandundefined May 9, 2025
12573dd
changed the 'fstructure' branch
noneandundefined May 9, 2025
19f5595
changed the 'fstructure' branch
noneandundefined May 9, 2025
7b11b1a
changed the 'fstructure' branch
noneandundefined May 9, 2025
4141c09
Merge pull request #24 from thefuture-industries/fstructure
noneandundefined May 9, 2025
502c8e7
changed the 'fstructure' branch
noneandundefined May 9, 2025
c8eae32
Merge pull request #26 from thefuture-industries/fstruture
noneandundefined May 9, 2025
beb2846
changed value in variable methodRegex | the 'bin/auto-commit' file ha…
noneandundefined May 9, 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
40 changes: 0 additions & 40 deletions .github/workflows/c-check.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Static Go Check

on:
pull_request:
branches: [main]

jobs:
go_check:
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.23.0'

- name: Install dependencies
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/tools/cmd/goimports@latest

- name: Go mod tidy & download
run: |
go mod tidy
go mod download

- name: Check formatting (gofmt)
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "Файлы не отформатированы. Запустите 'gofmt -w .'"
gofmt -l .
exit 1
fi

- name: Check imports (goimports)
run: |
if [ -n "$(goimports -l .)" ]; then
echo "Неверный импорт. Запустите 'goimports -w .'"
goimports -l .
exit 1
fi

- name: Lint (golangci-lint)
run: |
make lint

- name: Build binary
run: |
mkdir -p bin
make build
49 changes: 14 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
bindir = bin
.PHONY: fmt lint test

BUILDIN_MAIN = main.c
BUILDIN_COMMIT = commit.c
BUILDIN_DETECT = detect.c
BUILDIN_DIFF = diff.c
BUILDIN_FILE = file.c
BUILDIN_GIT_ROOT = git-root.c
BUILDIN_PARSER = parser.c
BUILDIN_STRINGS = stdlib/strings.c
fmt:
gofmt -w .
goimports -w .

MAIN_OUT = "$(bindir)/auto-commit"

UNAME_S := $(shell uname -s)

CC = gcc

ifeq ($(OS),Windows_NT)
MKDIR = mkdir $(bindir) || echo "Directory already exists"
REMOVE_EXT = mv $(MAIN_OUT).exe $(MAIN_OUT)
else
MKDIR = mkdir -p $(bindir)
OS_TYPE = $(shell uname -s)
REMOVE_EXT = true
endif
lint:
golangci-lint run

check: fmt lint test
@echo "All checks passed!"
build:
$(MKDIR)
$(CC) $(BUILDIN_MAIN) -o $(MAIN_OUT) $(BUILDIN_COMMIT) \
$(BUILDIN_DETECT) $(BUILDIN_DIFF) $(BUILDIN_FILE) \
$(BUILDIN_GET_STAGED) $(BUILDIN_STRINGS) $(BUILDIN_GIT_ROOT) \
$(BUILDIN_PARSER)
@echo "Running build..."
@go build -o bin/auto-commit .

$(REMOVE_EXT)
test:
@go test -v ./...

buildt:
$(MKDIR)
$(CC) $(BUILDIN_MAIN) -o $(MAIN_OUT) $(BUILDIN_COMMIT) \
$(BUILDIN_DETECT) $(BUILDIN_DIFF) $(BUILDIN_FILE) \
$(BUILDIN_GET_STAGED) $(BUILDIN_STRINGS) $(BUILDIN_GIT_ROOT) \
$(BUILDIN_PARSER)
run: build
@./bin/auto-commit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ iex ((New-Object Net.WebClient).DownloadString('https://github.com/thefuture-ind
Go to the root of the project and run the command.

```bash
bash <(curl -s https://github.com/thefuture-industries/git-auto-commit/blob/main/scripts/install-linux-auto-commit.sh?raw=true)
curl -fsSL https://github.com/thefuture-industries/git-auto-commit/blob/main/scripts/install-linux-auto-commit.sh?raw=true | bash
```

## Setting up
Expand Down
188 changes: 188 additions & 0 deletions auto-class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package main

import (
"fmt"
"git-auto-commit/types"
"regexp"
"strings"
)

func ParseToStructureClass(line, lang string) *types.ClassSignature {
switch lang {
case "typescript", "javascript":
return parseTSJSClass(line)
case "python":
return parsePythonClass(line)
case "cpp":
return parseCppClass(line)
case "csharp":
return parseCSharpClass(line)
case "go":
return parseGoStruct(line)
case "java":
return parseJavaClass(line)
default:
return nil
}
}

func parseTSJSClass(line string) *types.ClassSignature {
classRegex := regexp.MustCompile(`class\s+(\w+)(?:\s+extends\s+(\w+))?`)
m := classRegex.FindStringSubmatch(line)

name := m[1]
parent := ""
if len(m) > 2 {
parent = m[2]
}

methods := parseAccessModifiers(line, "(public|private|protected)\\s+(\\w+)\\s*\\(")
return &types.ClassSignature{Name: name, Parent: parent, Methods: methods}
}

func parsePythonClass(line string) *types.ClassSignature {
classRegex := regexp.MustCompile(`class\\s+(\\w+)(?:\\((\\w+)\\))?:`)
m := classRegex.FindStringSubmatch(line)
if m == nil {
return nil
}

name := m[1]
parent := ""
if len(m) > 2 {
parent = m[2]
}

methods := make(map[string]string)
methodRegex := regexp.MustCompile(`def\s+(_{0,2}\w+)\s*\(`)
for _, l := range strings.Split(line, "\n") {
mm := methodRegex.FindStringSubmatch(l)
if mm != nil {
mod := "public"
if strings.HasPrefix(mm[1], "__") {
mod = "private"
} else if strings.HasPrefix(mm[1], "_") {
mod = "protected"
}

methods[mm[1]] = mod
}
}

return &types.ClassSignature{Name: name, Parent: parent, Methods: methods}
}

func parseCppClass(line string) *types.ClassSignature {
classRegex := regexp.MustCompile(`class\\s+(\\w+)(?:\\s*:\\s*(public|protected|private)\\s+(\\w+))?`)
m := classRegex.FindStringSubmatch(line)
if m == nil {
return nil
}

name := m[1]
parent := ""
if len(m) > 3 {
parent = m[3]
}

methods := parseAccessModifiers(line, "(public|private|protected):\\s*\\w+\\s+(\\w+)\\s*\\(")
return &types.ClassSignature{Name: name, Parent: parent, Methods: methods}
}

func parseCSharpClass(line string) *types.ClassSignature {
classRegex := regexp.MustCompile(`(?:public\\s+)?class\\s+(\\w+)(?:\\s*:\\s*(\\w+))?`)
m := classRegex.FindStringSubmatch(line)
if m == nil {
return nil
}

name := m[1]
parent := ""
if len(m) > 2 {
parent = m[2]
}

methods := parseAccessModifiers(line, "(public|private|protected|internal)\\s+\\w+\\s+(\\w+)\\s*\\(")
return &types.ClassSignature{Name: name, Parent: parent, Methods: methods}
}

func parseGoStruct(line string) *types.ClassSignature {
structRegex := regexp.MustCompile(`type\\s+(\\w+)\\s+struct\\s*{`)
m := structRegex.FindStringSubmatch(line)
if m == nil {
return nil
}

name := m[1]
return &types.ClassSignature{Name: name, Parent: "", Methods: make(map[string]string)}
}

func parseJavaClass(line string) *types.ClassSignature {
classRegex := regexp.MustCompile(`(?:public\\s+)?class\\s+(\\w+)(?:\\s+extends\\s+(\\w+))?`)
m := classRegex.FindStringSubmatch(line)
if m == nil {
return nil
}

name := m[1]
parent := ""
if len(m) > 2 {
parent = m[2]
}

methods := parseAccessModifiers(line, "(public|private|protected)\\s+(\\w+)\\s*\\(")
return &types.ClassSignature{Name: name, Parent: parent, Methods: methods}
}

func parseAccessModifiers(line, regex string) map[string]string {
methods := make(map[string]string)
methodRegex := regexp.MustCompile(regex)

for _, l := range strings.Split(line, "\n") {
mm := methodRegex.FindStringSubmatch(l)
if mm != nil {
methods[mm[2]] = mm[1]
}
}

return methods
}

func FormattedClass(diff, lang string) string {
var oldClass, newClass *types.ClassSignature
var oldLines, newLines []string

lines := strings.Split(diff, "\n")
for _, line := range lines {
if strings.HasPrefix(line, "-") {
oldLines = append(oldLines, line[1:])
} else if strings.HasPrefix(line, "+") {
newLines = append(newLines, line[1:])
}
}

oldClass = ParseToStructureClass(strings.Join(oldLines, "\n"), lang)
newClass = ParseToStructureClass(strings.Join(newLines, "\n"), lang)

if oldClass != nil && newClass == nil {
return fmt.Sprintf("deleted class %s", oldClass.Name)
}

if oldClass != nil && newClass != nil {
if oldClass.Name != newClass.Name {
return fmt.Sprintf("renamed class %s -> %s", oldClass.Name, newClass.Name)
}

if oldClass.Parent != newClass.Parent {
return fmt.Sprintf("the heir was changed to %s", oldClass.Name)
}

for m, oldMod := range oldClass.Methods {
if newMod, ok := newClass.Methods[m]; ok && oldMod != newMod {
return fmt.Sprintf("the access modifier of the %s method has been changed", m)
}
}
}

return ""
}
Loading
Loading