dev: automated commit - 2025-07-15 23:20:30
This commit is contained in:
parent
33106ea4a6
commit
71cda52613
8 changed files with 770 additions and 696 deletions
98
git.go
Normal file
98
git.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func isGitRepo() bool {
|
||||
cmd := exec.Command("git", "rev-parse", "--git-dir")
|
||||
return cmd.Run() == nil
|
||||
}
|
||||
|
||||
func hasUncommittedChanges() bool {
|
||||
cmd := exec.Command("git", "diff-index", "--quiet", "HEAD", "--")
|
||||
return cmd.Run() != nil
|
||||
}
|
||||
|
||||
func getCurrentBranch() (string, error) {
|
||||
cmd := exec.Command("git", "branch", "--show-current")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(output)), nil
|
||||
}
|
||||
|
||||
func handlePush() error {
|
||||
log("Preparing to push repository...")
|
||||
|
||||
if !isGitRepo() {
|
||||
errorLog("Not in a git repository")
|
||||
return fmt.Errorf("not in git repo")
|
||||
}
|
||||
|
||||
if hasUncommittedChanges() {
|
||||
warn("You have uncommitted changes")
|
||||
fmt.Println()
|
||||
|
||||
cmd := exec.Command("git", "status", "--short")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Run()
|
||||
fmt.Println()
|
||||
|
||||
defaultMsg := fmt.Sprintf("dev: automated commit - %s", time.Now().Format("2006-01-02 15:04:05"))
|
||||
|
||||
fmt.Print("Commit all changes? (Y/n): ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
answer, _ := reader.ReadString('\n')
|
||||
answer = strings.TrimSpace(strings.ToLower(answer))
|
||||
|
||||
if answer != "n" && answer != "no" {
|
||||
fmt.Println()
|
||||
fmt.Printf("Default: %s\n", defaultMsg)
|
||||
fmt.Print("Custom commit message (or press Enter for default): ")
|
||||
|
||||
commitMsg, _ := reader.ReadString('\n')
|
||||
commitMsg = strings.TrimSpace(commitMsg)
|
||||
|
||||
if commitMsg == "" {
|
||||
commitMsg = defaultMsg
|
||||
}
|
||||
|
||||
if err := exec.Command("git", "add", ".").Run(); err != nil {
|
||||
return fmt.Errorf("failed to add changes: %v", err)
|
||||
}
|
||||
|
||||
if err := exec.Command("git", "commit", "-m", commitMsg).Run(); err != nil {
|
||||
return fmt.Errorf("failed to commit changes: %v", err)
|
||||
}
|
||||
|
||||
log("✓ Changes committed: %s", commitMsg)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runSecurityScan(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
branch, err := getCurrentBranch()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get current branch: %v", err)
|
||||
}
|
||||
|
||||
log("Pushing branch '%s' to origin...", branch)
|
||||
cmd := exec.Command("git", "push", "origin", branch)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
errorLog("❌ Push failed")
|
||||
return fmt.Errorf("push failed")
|
||||
}
|
||||
|
||||
log("✅ Successfully pushed to origin/%s", branch)
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue