4 Commits
7 changed files with 23 additions and 17 deletions

No files matched your search

+4 -5
View File
@@ -2,10 +2,10 @@ package cmd
import ( import (
"fmt" "fmt"
"git-air/internal/ui"
"os" "os"
"path/filepath" "path/filepath"
"github.com/unclesam-ly/git-air/internal/ui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@@ -43,14 +43,13 @@ func LoadConfig() (*AppConfig, error) {
// 1. 首先加载全局配置 ~/.git-air/config.yaml // 1. 首先加载全局配置 ~/.git-air/config.yaml
configPath, err := getConfigPath() configPath, err := getConfigPath()
if err == nil { if err != nil {
if data, err := os.ReadFile(configPath); err == nil && len(data) > 0 { // 隐式跳过时,可考虑记录日志或在 verbose 模式下输出
} else if data, err := os.ReadFile(configPath); err == nil && len(data) > 0 {
if err := yaml.Unmarshal(data, cfg); err != nil { if err := yaml.Unmarshal(data, cfg); err != nil {
// 全局配置错误可输出警告或直接返回错误
return nil, fmt.Errorf("解析全局配置文件 [%s] 失败: %w", configPath, err) return nil, fmt.Errorf("解析全局配置文件 [%s] 失败: %w", configPath, err)
} }
} }
}
// 2. 检查当前项目是否有专属于 git-air 的配置文件 (.git-air.yaml / git-air.yaml) 进行增量覆盖 // 2. 检查当前项目是否有专属于 git-air 的配置文件 (.git-air.yaml / git-air.yaml) 进行增量覆盖
localCandidates := []string{".git-air.yaml", ".git-air.yml", "git-air.yaml"} localCandidates := []string{".git-air.yaml", ".git-air.yml", "git-air.yaml"}
+3 -4
View File
@@ -1,19 +1,18 @@
package cmd package cmd
import ( import (
"git-air/internal/git"
"git-air/internal/ui"
"os" "os"
"path/filepath" "path/filepath"
"github.com/unclesam-ly/git-air/internal/git"
"github.com/unclesam-ly/git-air/internal/ui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const preCommitScript = `#!/bin/sh const preCommitScript = `#!/bin/sh
# git-air pre-commit hook # git-air pre-commit hook
echo "[git-air] 正在执行 Commit 前代码自动化评审..." echo "[git-air] 正在执行 Commit 前代码自动化评审..."
git-air --cached git-air --staged
# 如果评审发现阻断性问题,可通过退出码阻断 commit
` `
var hookCmd = &cobra.Command{ var hookCmd = &cobra.Command{
+12 -4
View File
@@ -2,12 +2,12 @@ package cmd
import ( import (
"context" "context"
"git-air/internal/git"
"git-air/internal/llm"
"git-air/internal/reviewer"
"git-air/internal/ui"
"os" "os"
"github.com/unclesam-ly/git-air/internal/git"
"github.com/unclesam-ly/git-air/internal/llm"
"github.com/unclesam-ly/git-air/internal/reviewer"
"github.com/unclesam-ly/git-air/internal/ui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -21,6 +21,12 @@ var rootCmd = &cobra.Command{
ctx := cmd.Context() ctx := cmd.Context()
// 1. 检查并获取 Diff // 1. 检查并获取 Diff
if flagCached, _ := cmd.Flags().GetBool("cached"); flagCached {
args = append([]string{"--cached"}, args...)
} else if flagStaged, _ := cmd.Flags().GetBool("staged"); flagStaged {
args = append([]string{"--cached"}, args...)
}
diff, err := git.GetDiff(ctx, args...) diff, err := git.GetDiff(ctx, args...)
if err != nil { if err != nil {
ui.PrintError("%v", err) ui.PrintError("%v", err)
@@ -99,4 +105,6 @@ func init() {
rootCmd.Flags().StringP("model", "m", "", "临时指定模型名称") rootCmd.Flags().StringP("model", "m", "", "临时指定模型名称")
rootCmd.Flags().StringP("provider", "p", "", "临时指定 Provider (gemini, deepseek, ollama)") rootCmd.Flags().StringP("provider", "p", "", "临时指定 Provider (gemini, deepseek, ollama)")
rootCmd.Flags().String("prompt", "", "临时指定 System Prompt") rootCmd.Flags().String("prompt", "", "临时指定 System Prompt")
rootCmd.Flags().Bool("cached", false, "显式审查暂存区(git add)代码")
rootCmd.Flags().Bool("staged", false, "显式审查暂存区(git add)代码")
} }
+1 -1
View File
@@ -1,4 +1,4 @@
module git-air module github.com/unclesam-ly/git-air
go 1.26.6 go 1.26.6
+1 -1
View File
@@ -3,7 +3,7 @@ package reviewer
import ( import (
"context" "context"
"fmt" "fmt"
"git-air/internal/llm" "github.com/unclesam-ly/git-air/internal/llm"
"strings" "strings"
) )
+1 -1
View File
@@ -33,7 +33,7 @@ func PrintFooter() {
// PrintError 打印错误信息 // PrintError 打印错误信息
func PrintError(format string, a ...interface{}) { func PrintError(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...) msg := fmt.Sprintf(format, a...)
fmt.Fprintf(os.Stderr, "%s[ERROR]%s %s\n", colorRed, colorReset, msg) _, _ = fmt.Fprintf(os.Stderr, "%s[ERROR]%s %s\n", colorRed, colorReset, msg)
} }
// PrintSuccess 打印成功信息 // PrintSuccess 打印成功信息
+1 -1
View File
@@ -1,6 +1,6 @@
package main package main
import "git-air/cmd" import "github.com/unclesam-ly/git-air/cmd"
func main() { func main() {
cmd.Execute() cmd.Execute()