feat: add pre and post command

This commit is contained in:
duorameng
2026-05-08 20:18:00 +08:00
parent 2f88fa0718
commit a3871e75b7
17 changed files with 255 additions and 67 deletions
+22 -1
View File
@@ -1,6 +1,10 @@
package utils
import "strings"
import (
"os"
"path/filepath"
"strings"
)
// GetRepoIdentifier 返回根据仓库URL和分支生成的作者_仓库名标识符
func GetRepoIdentifier(url string, branch string) string {
@@ -45,3 +49,20 @@ func GetRepoIdentifier(url string, branch string) string {
identifier = strings.ReplaceAll(identifier, ".", "_")
return identifier
}
// GetActualRepoDir 返回仓库真实的物理目录
func GetActualRepoDir(targetPath, sourceURL, branch, sourceType string) string {
repoDir := targetPath
if sourceType == "git" && sourceURL != "" {
repoName := GetRepoIdentifier(sourceURL, branch)
// 检查 targetPath 是否已存在且是 Git 仓库
gitDir := filepath.Join(repoDir, ".git")
if info, err := os.Stat(repoDir); err == nil && info.IsDir() {
if _, err := os.Stat(gitDir); os.IsNotExist(err) {
// 只有当目标目录存在但不是 Git 仓库时,才追加仓库名
repoDir = filepath.Join(repoDir, repoName)
}
}
}
return repoDir
}