未验证 提交 d5fdfd51 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #3550 from LinuxSuRen/fix-url-redundant-check

Fix the BitBucket endpoint URL redundant checking
...@@ -542,7 +542,7 @@ func AddPipelineToWebService(webservice *restful.WebService, devopsClient devops ...@@ -542,7 +542,7 @@ func AddPipelineToWebService(webservice *restful.WebService, devopsClient devops
webservice.Route(webservice.POST("/scms/{scm}/servers"). webservice.Route(webservice.POST("/scms/{scm}/servers").
To(projectPipelineHandler.CreateSCMServers). To(projectPipelineHandler.CreateSCMServers).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
Doc("Create scm server in the jenkins."). Doc("Create scm server if it does not exist in the Jenkins.").
Param(webservice.PathParameter("scm", "The ID of the source configuration management (SCM).")). Param(webservice.PathParameter("scm", "The ID of the source configuration management (SCM).")).
Reads(devops.CreateScmServerReq{}). Reads(devops.CreateScmServerReq{}).
Returns(http.StatusOK, RespOK, devops.SCMServer{}). Returns(http.StatusOK, RespOK, devops.SCMServer{}).
......
...@@ -43,6 +43,7 @@ import ( ...@@ -43,6 +43,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops" "kubesphere.io/kubesphere/pkg/simple/client/devops"
"net/http" "net/http"
"sort" "sort"
"strings"
"sync" "sync"
) )
...@@ -826,6 +827,7 @@ func (d devopsOperator) GetOrgRepo(scmId, organizationId string, req *http.Reque ...@@ -826,6 +827,7 @@ func (d devopsOperator) GetOrgRepo(scmId, organizationId string, req *http.Reque
return res, err return res, err
} }
// CreateSCMServers creates a Bitbucket server config item in Jenkins configuration if there's no same API address exist
func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devops.SCMServer, error) { func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devops.SCMServer, error) {
requestBody, err := ioutil.ReadAll(req.Body) requestBody, err := ioutil.ReadAll(req.Body)
...@@ -846,8 +848,9 @@ func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devo ...@@ -846,8 +848,9 @@ func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devo
return nil, err return nil, err
} }
createReq.ApiURL = strings.TrimSuffix(createReq.ApiURL, "/")
for _, server := range servers { for _, server := range servers {
if server.ApiURL == createReq.ApiURL { if strings.TrimSuffix(server.ApiURL, "/") == createReq.ApiURL {
return &server, nil return &server, nil
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册