[REV] optimization implementation

This commit is contained in:
zhoujunhao 2018-07-05 12:47:23 +08:00
parent c30483a085
commit 9227f8faed
2 changed files with 23 additions and 4 deletions

View File

@ -121,6 +121,7 @@ func GitClone(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
GetPrivateFileParam := csi.TenantID
flag := true
Loop:
fmt.Println(GetPrivateFileParam,flag)
if logger != nil {
//进度信息
logger.Info(fmt.Sprintf("开始从Git源(%s)获取代码", csi.RepositoryURL), map[string]string{"step": "clone_code"})
@ -205,6 +206,7 @@ Loop:
flag = false
goto Loop
}
fmt.Println("第二次1")
if logger != nil {
logger.Error(fmt.Sprintf("拉取代码发生错误,代码源鉴权失败。"), map[string]string{"step": "callback", "status": "failure"})
}
@ -229,6 +231,14 @@ Loop:
return rs, fmt.Errorf("branch %s is not exist", csi.Branch)
}
if strings.Contains(err.Error(), "ssh: unable to authenticate") {
logrus.Info("没有找到ssh")
if flag {
GetPrivateFileParam = "builder_rsa"
flag = false
goto Loop
}
fmt.Println("第二次2")
if logger != nil {
logger.Error(fmt.Sprintf("远程代码库需要配置SSH Key。"), map[string]string{"step": "callback", "status": "failure"})
}
@ -263,6 +273,7 @@ func GitPull(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
GetPrivateFileParam := csi.TenantID
flag := true
Loop:
fmt.Println(GetPrivateFileParam,flag)
if logger != nil {
//进度信息
logger.Info(fmt.Sprintf("开始从Git源(%s)更新代码", csi.RepositoryURL), map[string]string{"step": "clone_code"})
@ -341,6 +352,7 @@ Loop:
flag = false
goto Loop
}
fmt.Println("第二次1")
if logger != nil {
logger.Error(fmt.Sprintf("更新代码发生错误,代码源鉴权失败。"), map[string]string{"step": "callback", "status": "failure"})
@ -366,6 +378,14 @@ Loop:
return rs, fmt.Errorf("branch %s is not exist", csi.Branch)
}
if strings.Contains(err.Error(), "ssh: unable to authenticate") {
logrus.Info("没有找到ssh")
if flag {
GetPrivateFileParam = "builder_rsa"
flag = false
goto Loop
}
fmt.Println("第二次2")
if logger != nil {
logger.Error(fmt.Sprintf("远程代码库需要配置SSH Key。"), map[string]string{"step": "callback", "status": "failure"})
}

View File

@ -34,7 +34,7 @@ func init() {
func TestGitClone(t *testing.T) {
start := time.Now()
csi := CodeSourceInfo{
RepositoryURL: "https://github.com/goodrain/rainbond-docs.git",
RepositoryURL: "git@gitee.com:zhoujunhaogoodrain/webhook_test.git",
Branch: "master",
}
//logger := event.GetManager().GetLogger("system")
@ -49,7 +49,7 @@ func TestGitClone(t *testing.T) {
func TestGitPull(t *testing.T) {
csi := CodeSourceInfo{
RepositoryURL: "git@code.goodrain.com:goodrain/test.git",
RepositoryURL: "git@gitee.com:zhoujunhaogoodrain/webhook_test.git",
Branch: "master2",
}
//logger := event.GetManager().GetLogger("system")
@ -66,8 +66,7 @@ func TestGitPull(t *testing.T) {
func TestGitPullOrClone(t *testing.T) {
csi := CodeSourceInfo{
RepositoryURL: "git@code.goodrain.com:goodrain/goodrain_web.git",
Branch: "publiccloud",
RepositoryURL: "git@gitee.com:zhoujunhaogoodrain/webhook_test.git",
}
//logger := event.GetManager().GetLogger("system")
res, err := GitCloneOrPull(csi, "/tmp/goodrainweb2", nil, 1)