diff --git a/pkg/apis/devops/v1alpha2/register.go b/pkg/apis/devops/v1alpha2/register.go index 71932250be833b622b43b59b13fbb0dcdfa45517..9d7a9da1a2fc6bf1ac1161277eed098bace64ff9 100644 --- a/pkg/apis/devops/v1alpha2/register.go +++ b/pkg/apis/devops/v1alpha2/register.go @@ -48,6 +48,7 @@ func addWebService(c *restful.Container) error { Doc("get devops project"). Metadata(restfulspec.KeyOpenAPITags, tags). Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", &devops.DevOpsProject{}). Writes(&devops.DevOpsProject{})) webservice.Route(webservice.PATCH("/devops/{devops}"). @@ -55,57 +56,80 @@ func addWebService(c *restful.Container) error { Doc("get devops project"). Metadata(restfulspec.KeyOpenAPITags, tags). Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", &devops.DevOpsProject{}). Writes(&devops.DevOpsProject{})) webservice.Route(webservice.GET("/devops/{devops}/defaultroles"). To(devopsapi.GetDevOpsProjectDefaultRoles). Doc("get devops project defaultroles"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", &devops.DefaultRoles). Writes(&devops.DefaultRoles)) webservice.Route(webservice.GET("/devops/{devops}/members"). To(devopsapi.GetDevOpsProjectMembersHandler). Doc("get devops project members"). Metadata(restfulspec.KeyOpenAPITags, tags). - Writes(&[]*devops.DevOpsProjectMembership{})) + Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", []*devops.DevOpsProjectMembership{}). + Writes([]*devops.DevOpsProjectMembership{})) webservice.Route(webservice.GET("/devops/{devops}/members/{members}"). To(devopsapi.GetDevOpsProjectMemberHandler). Doc("get devops project member"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Param(webservice.PathParameter("members", "username")). + Returns(http.StatusOK, "success", []*devops.DevOpsProjectMembership{}). Writes(&devops.DevOpsProjectMembership{})) webservice.Route(webservice.POST("/devops/{devops}/members"). To(devopsapi.AddDevOpsProjectMemberHandler). Doc("add devops project members"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", &devops.DevOpsProjectMembership{}). Writes(&devops.DevOpsProjectMembership{})) webservice.Route(webservice.POST("/devops/{devops}/pipelines"). To(devopsapi.CreateDevOpsProjectPipelineHandler). Doc("add devops project pipeline"). - Metadata(restfulspec.KeyOpenAPITags, tags). - Reads(devops.ProjectPipeline{})) + Param(webservice.PathParameter("devops", "projectId")). + Returns(http.StatusOK, "success", &devops.ProjectPipeline{}). + Writes(&devops.ProjectPipeline{}). + Reads(&devops.ProjectPipeline{})) webservice.Route(webservice.PUT("/devops/{devops}/pipelines/{pipelines}"). To(devopsapi.UpdateDevOpsProjectPipelineHandler). - Doc("add devops project pipeline"). + Doc("update devops project pipeline"). + Param(webservice.PathParameter("devops", "projectId")). + Param(webservice.PathParameter("pipelines", "pipelineId")). Metadata(restfulspec.KeyOpenAPITags, tags). - Reads(devops.ProjectPipeline{})) + Returns(http.StatusOK, "success", &devops.ProjectPipeline{}). + Writes(&devops.ProjectPipeline{}). + Reads(&devops.ProjectPipeline{})) webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/config"). To(devopsapi.GetDevOpsProjectPipelineHandler). Doc("get devops project pipeline config"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Param(webservice.PathParameter("pipelines", "pipelineId")). Returns(http.StatusOK, "ok", devops.ProjectPipeline{}). Writes(devops.ProjectPipeline{})) webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/sonarStatus"). To(devopsapi.GetPipelineSonarStatusHandler). Doc("get devops project pipeline sonarStatus"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Param(webservice.PathParameter("pipelines", "pipelineId")). Returns(http.StatusOK, "ok", []devops.SonarStatus{}). Writes([]devops.SonarStatus{})) webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/branches/{branches}/sonarStatus"). To(devopsapi.GetMultiBranchesPipelineSonarStatusHandler). Doc("get devops project pipeline sonarStatus"). Metadata(restfulspec.KeyOpenAPITags, tags). + Param(webservice.PathParameter("devops", "projectId")). + Param(webservice.PathParameter("pipelines", "pipelineId")). + Param(webservice.PathParameter("branches", "branchName")). Returns(http.StatusOK, "ok", []devops.SonarStatus{}). Writes([]devops.SonarStatus{})) webservice.Route(webservice.DELETE("/devops/{devops}/pipelines/{pipelines}"). diff --git a/pkg/models/devops/common.go b/pkg/models/devops/common.go index d0e03e77568762018983f04d1502b5a03ea10856..2721f165163551f011a3e4b784fe241d5044ba0a 100644 --- a/pkg/models/devops/common.go +++ b/pkg/models/devops/common.go @@ -314,9 +314,9 @@ func CheckProjectUserInRole(username, projectId string, roles []string) error { return nil } -func GetProjectUserRole(username, projectId string) (string ,error) { +func GetProjectUserRole(username, projectId string) (string, error) { if username == KS_ADMIN { - return ProjectOwner,nil + return ProjectOwner, nil } dbconn := devops_mysql.OpenDatabase() membership := &DevOpsProjectMembership{} @@ -326,8 +326,8 @@ func GetProjectUserRole(username, projectId string) (string ,error) { db.Eq(DevOpsProjectMembershipUsernameColumn, username), db.Eq(DevOpsProjectMembershipProjectIdColumn, projectId))).LoadOne(membership) if err != nil { - return "",err + return "", err } - return membership.Role,nil + return membership.Role, nil } diff --git a/pkg/models/tenant/devops.go b/pkg/models/tenant/devops.go index dfa3f1bffca8d32641b4a4aba1bba047eb7362d0..a135f91f6ce9577a700ba38b2c36bed091085a9f 100644 --- a/pkg/models/tenant/devops.go +++ b/pkg/models/tenant/devops.go @@ -254,7 +254,7 @@ func CreateDevopsProject(username string, workspace string, req *devops.DevOpsPr } func GetUserDevopsSimpleRules(username, projectId string) ([]models.SimpleRule, error) { - role,err := devops.GetProjectUserRole(username,projectId) + role, err := devops.GetProjectUserRole(username, projectId) if err != nil { glog.Errorf("%+v", err) return nil, restful.NewError(http.StatusForbidden, err.Error())