mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
fixed git integration error
This commit is contained in:
@@ -10,7 +10,9 @@ import (
|
||||
|
||||
func GetGitRemoteBranches(c *gin.Context) {
|
||||
url := c.Query("url")
|
||||
branches, err := services.GetGitRemoteBranchesPlain(url)
|
||||
username := c.Query("username")
|
||||
password := c.Query("password")
|
||||
branches, err := services.GetGitRemoteBranchesPlain(url, username, password)
|
||||
if err != nil {
|
||||
HandleError(http.StatusInternalServerError, c, err)
|
||||
return
|
||||
|
||||
@@ -137,13 +137,38 @@ func SaveSpiderGitSyncError(s model.Spider, errMsg string) {
|
||||
}
|
||||
|
||||
// 获得Git分支
|
||||
func GetGitRemoteBranchesPlain(url string) (branches []string, err error) {
|
||||
func GetGitRemoteBranchesPlain(gitUrl string, username string, password string) (branches []string, err error) {
|
||||
storage := memory.NewStorage()
|
||||
u, err := url.Parse(gitUrl)
|
||||
if err != nil {
|
||||
return branches, err
|
||||
}
|
||||
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,
|
||||
)
|
||||
} else {
|
||||
auth, err := ssh.NewPublicKeysFromFile(username, path.Join(os.Getenv("HOME"), ".ssh", "id_rsa"), "")
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
debug.PrintStack()
|
||||
return branches, err
|
||||
}
|
||||
listOptions = git.ListOptions{
|
||||
Auth: auth,
|
||||
}
|
||||
}
|
||||
remote := git.NewRemote(storage, &config.RemoteConfig{
|
||||
URLs: []string{
|
||||
url,
|
||||
gitUrl,
|
||||
}})
|
||||
rfs, err := remote.List(&git.ListOptions{})
|
||||
rfs, err := remote.List(&listOptions)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<el-input
|
||||
v-model="spiderForm.git_username"
|
||||
:placeholder="$t('Git Username')"
|
||||
@blur="onGitUrlChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
@@ -51,6 +52,7 @@
|
||||
v-model="spiderForm.git_password"
|
||||
:placeholder="$t('Git Password')"
|
||||
type="password"
|
||||
@blur="onGitUrlChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
|
||||
Reference in New Issue
Block a user