From 67d7eafdbf68cee10b1fc1153d3c110027e13e2a Mon Sep 17 00:00:00 2001 From: KubeSphere CI Bot <47586280+ks-ci-bot@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:16:26 +0800 Subject: [PATCH] fix panic when timeout is nil in gitlab cloneOptions (#1017) Co-authored-by: jackyu --- pkg/client/devops/jenkins/internal/gitlab.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/client/devops/jenkins/internal/gitlab.go b/pkg/client/devops/jenkins/internal/gitlab.go index 73a293db..a8360521 100644 --- a/pkg/client/devops/jenkins/internal/gitlab.go +++ b/pkg/client/devops/jenkins/internal/gitlab.go @@ -145,11 +145,15 @@ func GetGitlabSourceFromEtree(source *etree.Element) (gitSource *devopsv1alpha3. if value, err := strconv.ParseBool(cloneExtension.SelectElement("shallow").Text()); err == nil { gitSource.CloneOption.Shallow = value } - if value, err := strconv.ParseInt(cloneExtension.SelectElement("timeout").Text(), 10, 32); err == nil { - gitSource.CloneOption.Timeout = int(value) + if timeout := cloneExtension.SelectElement("timeout"); timeout != nil { + if value, err := strconv.ParseInt(timeout.Text(), 10, 32); err == nil { + gitSource.CloneOption.Timeout = int(value) + } } - if value, err := strconv.ParseInt(cloneExtension.SelectElement("depth").Text(), 10, 32); err == nil { - gitSource.CloneOption.Depth = int(value) + if depth := cloneExtension.SelectElement("depth"); depth != nil { + if value, err := strconv.ParseInt(depth.Text(), 10, 32); err == nil { + gitSource.CloneOption.Depth = int(value) + } } } }