Merge branch 'master' into devops2

# Conflicts:
#	pkg/apis/devops/v1alpha2/register.go
This commit is contained in:
runzexia
2019-04-28 11:23:54 +08:00
6 changed files with 1289 additions and 211 deletions

View File

@@ -20,7 +20,6 @@ package devops
import (
"github.com/emicklei/go-restful"
log "github.com/golang/glog"
"kubesphere.io/kubesphere/pkg/errors"
"kubesphere.io/kubesphere/pkg/models/devops"
"net/http"
)
@@ -39,7 +38,6 @@ func GetPipeline(req *restful.Request, resp *restful.Response) {
}
func SearchPipelines(req *restful.Request, resp *restful.Response) {
res, err := devops.SearchPipelines(req.Request)
if err != nil {
parseErr(err, resp)
@@ -120,10 +118,180 @@ func Validate(req *restful.Request, resp *restful.Response) {
_, _ = resp.Write(res)
}
func GetOrgSCM(req *restful.Request, resp *restful.Response) {
func GetSCMOrg(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scmId")
res, err := devops.GetOrgSCM(scmId, req.Request)
res, err := devops.GetSCMOrg(scmId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func GetOrgRepo(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scmId")
organizationId := req.PathParameter("organizationId")
res, err := devops.GetOrgRepo(scmId, organizationId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func StopPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.StopPipeline(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func ReplayPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.ReplayPipeline(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func GetRunLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.GetRunLog(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_, _ = resp.Write(res)
}
func GetArtifacts(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
res, err := devops.GetArtifacts(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func GetPipeBranch(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
res, err := devops.GetPipeBranch(projectName, pipelineName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func CheckPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
stepId := req.PathParameter("stepId")
res, err := devops.CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_, _ = resp.Write(res)
}
func GetConsoleLog(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
res, err := devops.GetConsoleLog(projectName, pipelineName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_, _ = resp.Write(res)
}
func ScanBranch(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
res, err := devops.ScanBranch(projectName, pipelineName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_, _ = resp.Write(res)
}
func RunPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
res, err := devops.RunPipeline(projectName, pipelineName, branchName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func GetStepsStatus(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
runId := req.PathParameter("runId")
nodeId := req.PathParameter("nodeId")
res, err := devops.GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
_ = resp.WriteAsJson(res)
}
func GetCrumb(req *restful.Request, resp *restful.Response) {
res, err := devops.GetCrumb(req.Request)
if err != nil {
parseErr(err, resp)
return
@@ -135,9 +303,9 @@ func GetOrgSCM(req *restful.Request, resp *restful.Response) {
func parseErr(err error, resp *restful.Response) {
log.Error(err)
if jErr, ok := err.(*devops.JkError); ok {
_ = resp.WriteHeaderAndEntity(jErr.Code, err)
_ = resp.WriteError(jErr.Code, err)
} else {
_ = resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
_ = resp.WriteError(http.StatusInternalServerError, err)
}
return
}