Skip to content

Commit

Permalink
change checkPipelineName and checkDevopsName apis (#963)
Browse files Browse the repository at this point in the history
change

Co-authored-by: drzhangg <[email protected]>
  • Loading branch information
ks-ci-bot and drzhangg committed Jun 13, 2023
1 parent 6983b14 commit 55cc9ad
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pkg/client/devops/fake/fakedevops.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (d *Devops) GetPipeline(projectName, pipelineName string, httpParameters *d
return nil, nil
}

func (d *Devops) CheckPipelineName(projectName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {
func (d *Devops) CheckPipelineName(projectName, pipelineName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/devops/jclient/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@ func (j *JenkinsClient) CheckCron(projectName string, httpParameters *devops.Htt
return j.jenkins.CheckCron(projectName, httpParameters)
}

func (j *JenkinsClient) CheckPipelineName(projectName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {
return j.jenkins.CheckPipelineName(projectName, httpParameters)
func (j *JenkinsClient) CheckPipelineName(projectName, pipelineName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {
return j.jenkins.CheckPipelineName(projectName, pipelineName, httpParameters)
}
6 changes: 4 additions & 2 deletions pkg/client/devops/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ func (j *Jenkins) Poll() (int, error) {
return resp.StatusCode, nil
}

func (j *Jenkins) CheckPipelineName(projectName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {
func (j *Jenkins) CheckPipelineName(projectName, pipelineName string, httpParameters *devops.HttpParameters) (map[string]interface{}, error) {

httpParameters.Url.RawQuery = fmt.Sprintf("value=%s", pipelineName)
PipelineOjb := &Pipeline{
HttpParameters: httpParameters,
Jenkins: j,
Path: fmt.Sprintf(CheckPipelineName+httpParameters.Url.RawQuery, projectName),
Path: fmt.Sprintf(CheckPipelineName, projectName),
}
res, err := PipelineOjb.CheckPipelineName()
return res, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/devops/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ type HttpParameters struct {

type PipelineOperator interface {
// Pipelinne operator interface
CheckPipelineName(projectName string, httpParameters *HttpParameters) (map[string]interface{}, error)
CheckPipelineName(projectName, pipelineName string, httpParameters *HttpParameters) (map[string]interface{}, error)
GetPipeline(projectName, pipelineName string, httpParameters *HttpParameters) (*Pipeline, error)
ListPipelines(httpParameters *HttpParameters) (*PipelineList, error)
GetPipelineRun(projectName, pipelineName, runId string, httpParameters *HttpParameters) (*PipelineRun, error)
Expand Down
12 changes: 9 additions & 3 deletions pkg/kapis/devops/v1alpha2/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ import (

const jenkinsHeaderPre = "X-"

func (h *ProjectPipelineHandler) CheckPipelineName(req *restful.Request, resp *restful.Response) {
jobName := req.PathParameter("devops")
res, err := h.devopsOperator.CheckPipelineName(jobName, req.Request)
func (h *ProjectPipelineHandler) CheckPipelineName(req *restful.Request, resp *restful.Response, projectName, pipelineName string) {
res, err := h.devopsOperator.CheckPipelineName(projectName, pipelineName, req.Request)
if err != nil {
parseErr(err, resp)
return
Expand All @@ -60,6 +59,12 @@ func (h *ProjectPipelineHandler) CheckPipelineName(req *restful.Request, resp *r
func (h *ProjectPipelineHandler) GetPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("devops")
pipelineName := req.PathParameter("pipeline")
check := req.QueryParameter("check")

if check == "true" {
h.CheckPipelineName(req, resp, projectName, pipelineName)
return
}

res, err := h.devopsOperator.GetPipeline(projectName, pipelineName, req.Request)
if err != nil {
Expand All @@ -69,6 +74,7 @@ func (h *ProjectPipelineHandler) GetPipeline(req *restful.Request, resp *restful

resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)

}

func (h *ProjectPipelineHandler) getPipelinesByRequest(req *restful.Request) (api.ListResult, error) {
Expand Down
7 changes: 0 additions & 7 deletions pkg/kapis/devops/v1alpha2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ func AddPipelineToWebService(webservice *restful.WebService, devopsClient devops
if projectPipelineEnable {
projectPipelineHandler := NewProjectPipelineHandler(devopsClient, k8sClient)

// match Jenkins api "/job/{devops}/checkJobName?value="
webservice.Route(webservice.GET("/devops/{devops}/checkPipelineName").
To(projectPipelineHandler.CheckPipelineName).
Doc("check the job name does it exist").
Param(webservice.PathParameter("value", "the name of the new job")).
Returns(http.StatusOK, api.StatusOK, nil))

webservice.Route(webservice.GET("/devops/{devops}/credentials/{credential}/usage").
To(projectPipelineHandler.GetProjectCredentialUsage).
Doc("Get the specified credential usage of the DevOps project").
Expand Down
6 changes: 0 additions & 6 deletions pkg/kapis/devops/v1alpha2/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ func TestAPIsExist(t *testing.T) {
method: http.MethodGet,
uri: "/devops/fake/pipelines/fake",
},
}, {
name: "check pipeline name if exist",
args: args{
method: http.MethodGet,
uri: "/devops/fake/checkPipelineName?value=fake1",
},
}, {
name: "search API",
args: args{
Expand Down
11 changes: 7 additions & 4 deletions pkg/kapis/devops/v1alpha3/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func (h *devopsHandler) GetDevOpsProject(request *restful.Request, response *res
workspace := request.PathParameter("workspace")
devopsProject := request.PathParameter("devops")
generateNameFlag := request.QueryParameter("generateName")
check := request.QueryParameter("check")

if check == "true" {
h.CheckDevopsName(request, response, workspace, devopsProject, generateNameFlag)
return
}

if client, err := h.getDevOps(request); err == nil {
var project *v1alpha3.DevOpsProject
Expand Down Expand Up @@ -395,10 +401,7 @@ func (h *devopsHandler) getDevOps(request *restful.Request) (operator devops.Dev
return
}

func (h *devopsHandler) CheckDevopsName(request *restful.Request, response *restful.Response) {
workspace := request.PathParameter("workspace")
devopsName := request.QueryParameter("devopsName")
generateNameFlag := request.QueryParameter("generateName")
func (h *devopsHandler) CheckDevopsName(request *restful.Request, response *restful.Response, workspace, devopsName string, generateNameFlag string) {

var result map[string]interface{}
if client, err := h.getDevOps(request); err == nil {
Expand Down
5 changes: 0 additions & 5 deletions pkg/kapis/devops/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ func registerRoutersForWorkspace(handler *devopsHandler, ws *restful.WebService)
Returns(http.StatusOK, api.StatusOK, v1alpha3.DevOpsProject{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}))

// /workspaces/{workspace}/devops/checkDevopsName?devopsName=xxx&generateName=true
ws.Route(ws.GET("/workspaces/{workspace}/devops/checkDevopsName").
To(handler.CheckDevopsName).
Doc("check the devops project name does it exist").
Returns(http.StatusOK, api.StatusOK, nil))
}

func registerRoutersForCI(handler *devopsHandler, ws *restful.WebService) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/devops/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type DevopsOperator interface {
UpdateCredentialObj(projectName string, secret *v1.Secret) (*v1.Secret, error)
ListCredentialObj(projectName string, query *query.Query) (api.ListResult, error)

CheckPipelineName(projectName string, req *http.Request) (map[string]interface{}, error)
CheckPipelineName(projectName, pipelineName string, req *http.Request) (map[string]interface{}, error)
GetPipeline(projectName, pipelineName string, req *http.Request) (*devops.Pipeline, error)
ListPipelines(req *http.Request) (*devops.PipelineList, error)
GetPipelineRun(projectName, pipelineName, runId string, req *http.Request) (*devops.PipelineRun, error)
Expand Down Expand Up @@ -469,8 +469,8 @@ func (d devopsOperator) ListCredentialObj(projectName string, query *query.Query
return *resourcesV1alpha3.DefaultList(result, query, resourcesV1alpha3.DefaultCompare(), resourcesV1alpha3.DefaultFilter()), nil
}

func (d devopsOperator) CheckPipelineName(projectName string, req *http.Request) (map[string]interface{}, error) {
return d.devopsClient.CheckPipelineName(projectName, convertToHttpParameters(req))
func (d devopsOperator) CheckPipelineName(projectName, pipelineName string, req *http.Request) (map[string]interface{}, error) {
return d.devopsClient.CheckPipelineName(projectName, pipelineName, convertToHttpParameters(req))
}

// others
Expand Down

0 comments on commit 55cc9ad

Please sign in to comment.