mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
Merge pull request #861 from hantmac/fix/fix_GetGitRemoteBranchesPlain
fix GetGitRemoteBranchesPlain when git url has port
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) {
|
||||
// 删除文件夹
|
||||
|
||||
@@ -64,6 +64,7 @@ github.com/crawlab-team/crawlab-go-sdk v0.0.3 h1:xtXPvAfrFInqHMQTc9z/4I4x3UD3MlK
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.0.3/go.mod h1:o8G5GycvFLpN2JAFKARnc1sPP9cVl4UL/henjBuU/m0=
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.0.5 h1:dpKEIMIwuAUTV+0ieow8QAGixrQKnslSfHrejBm/hOk=
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.0.5/go.mod h1:T462oNoHharqpV+d6mHORzxCTXx85nZUAnjRl4y2X9Y=
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.0.6/go.mod h1:xGUasmWVpsYgnMOZNyXqVUHEbZM09U7mUuF6krz5wN4=
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.3.3 h1:AfnpbX8284bju/EDQlncnIlj6OAeeLz2zSKL+XSoxCA=
|
||||
github.com/crawlab-team/crawlab-go-sdk v0.3.3/go.mod h1:o8G5GycvFLpN2JAFKARnc1sPP9cVl4UL/henjBuU/m0=
|
||||
github.com/crawlab-team/crawlab-sdk v0.3.3 h1:wIZULN0tthEYN5rm4udC4lvNmYWUCVcIpjo8eOEAiUY=
|
||||
@@ -190,6 +191,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
|
||||
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
||||
|
||||
Reference in New Issue
Block a user