mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-11 10:19:02 +00:00
feat: 增加 git 仓库校验
This commit is contained in:
parent
22d93edd9a
commit
39d02d1a04
1 changed files with 17 additions and 0 deletions
|
|
@ -27,6 +27,10 @@ func runReview(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := requireGitRepo(opts.repoDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tpl, err := template.LoadDefault()
|
||||
if err != nil {
|
||||
return fmt.Errorf("load default template: %w", err)
|
||||
|
|
@ -155,6 +159,19 @@ func resolveRepoDir(input string) (string, error) {
|
|||
return absPath, nil
|
||||
}
|
||||
|
||||
// requireGitRepo validates that the given directory is part of a git repository.
|
||||
func requireGitRepo(dir string) error {
|
||||
repoDir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("resolve path: %w", err)
|
||||
}
|
||||
out, err := runGitCmd(repoDir, "rev-parse", "--git-dir")
|
||||
if err != nil || len(out) == 0 {
|
||||
return fmt.Errorf("%s is not a git repository, code review requires a valid git repository", repoDir)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildToolRegistry(collector *tool.CommentCollector, fr *tool.FileReader, diffMap map[string]string) tool.Registry {
|
||||
reg := tool.NewRegistry()
|
||||
reg.Register(tool.NewFileRead(fr))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue