Merge pull request #2193 from shaowenchen/fix_pipeline

fix apiresult
This commit is contained in:
KubeSphere CI Bot
2020-06-12 12:34:39 +08:00
committed by GitHub
2 changed files with 13 additions and 4 deletions

View File

@@ -60,7 +60,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")).
Doc("list the credentials of the specified devops for the current user").
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}))
ws.Route(ws.POST("/devops/{devops}/credentials").
@@ -105,7 +105,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")).
Doc("list the pipelines of the specified devops for the current user").
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}))
ws.Route(ws.POST("/devops/{devops}/pipelines").
@@ -147,7 +147,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte
Required(false).
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")).Doc("List the devopsproject of the specified workspace for the current user").
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}))
ws.Route(ws.POST("/workspaces/{workspace}/devops").

View File

@@ -175,6 +175,9 @@ func (d devopsOperator) ListDevOpsProject(workspace string, limit, offset int) (
limit = len(result) - offset
}
items = result[offset : offset+limit]
if items == nil {
items = []interface{}{}
}
return api.ListResult{TotalItems: len(result), Items: items}, nil
}
@@ -218,7 +221,7 @@ func (d devopsOperator) ListPipelineObj(projectName string, limit, offset int) (
}
data, err := d.ksInformers.Devops().V1alpha3().Pipelines().Lister().Pipelines(projectObj.Status.AdminNamespace).List(labels.Everything())
if err != nil {
return api.ListResult{}, nil
return api.ListResult{}, err
}
items := make([]interface{}, 0)
var result []interface{}
@@ -230,6 +233,9 @@ func (d devopsOperator) ListPipelineObj(projectName string, limit, offset int) (
limit = len(result) - offset
}
items = result[offset : offset+limit]
if items == nil {
items = []interface{}{}
}
return api.ListResult{TotalItems: len(result), Items: items}, nil
}
@@ -298,6 +304,9 @@ func (d devopsOperator) ListCredentialObj(projectName string, limit, offset int)
limit = len(result) - offset
}
items = result[offset : offset+limit]
if items == nil {
items = []interface{}{}
}
return api.ListResult{TotalItems: len(result), Items: items}, nil
}