From 9227f8faedd418583aaf1697422a504a7614da0f Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Thu, 5 Jul 2018 12:47:23 +0800 Subject: [PATCH] [REV] optimization implementation --- builder/sources/git.go | 20 ++++++++++++++++++++ builder/sources/git_test.go | 7 +++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/builder/sources/git.go b/builder/sources/git.go index 1c07ddf53..7fc03dc8a 100644 --- a/builder/sources/git.go +++ b/builder/sources/git.go @@ -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"}) } diff --git a/builder/sources/git_test.go b/builder/sources/git_test.go index b65c989af..cce67e9a7 100644 --- a/builder/sources/git_test.go +++ b/builder/sources/git_test.go @@ -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)