mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-30 18:00:56 +01:00
fix GetGitRemoteBranchesPlain when git url has port
Signed-off-by: hantmac <hantmac@outlook.com>
This commit is contained in:
@@ -139,17 +139,9 @@ func SaveSpiderGitSyncError(s model.Spider, errMsg string) {
|
||||
// 获得Git分支
|
||||
func GetGitRemoteBranchesPlain(gitUrl string, username string, password string) (branches []string, err error) {
|
||||
storage := memory.NewStorage()
|
||||
u, _ := url.Parse(gitUrl)
|
||||
var listOptions git.ListOptions
|
||||
if strings.HasPrefix(gitUrl, "http") {
|
||||
gitUrl = fmt.Sprintf(
|
||||
"%s://%s:%s@%s%s",
|
||||
u.Scheme,
|
||||
username,
|
||||
password,
|
||||
u.Hostname(),
|
||||
u.Path,
|
||||
)
|
||||
gitUrl = formatGitUrl(gitUrl, username, password)
|
||||
} else {
|
||||
auth, err := ssh.NewPublicKeysFromFile(username, path.Join(os.Getenv("HOME"), ".ssh", "id_rsa"), "")
|
||||
if err != nil {
|
||||
@@ -183,6 +175,33 @@ func GetGitRemoteBranchesPlain(gitUrl string, username string, password string)
|
||||
return branches, nil
|
||||
}
|
||||
|
||||
func formatGitUrl(gitUrl, username, password string) string {
|
||||
u, _ := url.Parse(gitUrl)
|
||||
gitHost := u.Hostname()
|
||||
gitPort := u.Port()
|
||||
if gitPort == "" {
|
||||
gitUrl = fmt.Sprintf(
|
||||
"%s://%s:%s@%s%s",
|
||||
u.Scheme,
|
||||
username,
|
||||
password,
|
||||
u.Hostname(),
|
||||
u.Path,
|
||||
)
|
||||
} else {
|
||||
gitUrl = fmt.Sprintf(
|
||||
"%s://%s:%s@%s:%s%s",
|
||||
u.Scheme,
|
||||
username,
|
||||
password,
|
||||
gitHost,
|
||||
gitPort,
|
||||
u.Path,
|
||||
)
|
||||
}
|
||||
return gitUrl
|
||||
}
|
||||
|
||||
// 重置爬虫Git
|
||||
func ResetSpiderGit(s model.Spider) (err error) {
|
||||
// 删除文件夹
|
||||
|
||||
Reference in New Issue
Block a user