提交 1e87ad59 编写于 作者: Z Zhuxiaoyang 提交者: zryfish

Dev (#1)

* add api & rename alias
Signed-off-by: Nsoulseen <sunzhu@yunify.com>
上级 e26a7a0c
...@@ -21,11 +21,16 @@ import ( ...@@ -21,11 +21,16 @@ import (
"github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi" "github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/apiserver/devops" devopsapi "kubesphere.io/kubesphere/pkg/apiserver/devops"
"kubesphere.io/kubesphere/pkg/apiserver/runtime" "kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/models/devops"
"net/http"
) )
const GroupName = "devops.kubesphere.io" const (
GroupName = "devops.kubesphere.io"
RespMessage = "ok"
)
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"} var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
...@@ -41,15 +46,17 @@ func addWebService(c *restful.Container) error { ...@@ -41,15 +46,17 @@ func addWebService(c *restful.Container) error {
// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}" // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}").
To(devops.GetPipeline). To(devopsapi.GetPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get DevOps Pipelines."). Doc("Get DevOps Pipelines.").
Param(webservice.PathParameter("pipelineName", "pipeline name")). Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name"))) Param(webservice.PathParameter("projectName", "devops project name")).
Returns(http.StatusOK, RespMessage, devops.Pipeline{}).
Writes(devops.Pipeline{}))
// match Jenkisn api: "jenkins_api/blue/rest/search" // match Jenkisn api: "jenkins_api/blue/rest/search"
webservice.Route(webservice.GET("/devops/search"). webservice.Route(webservice.GET("/devops/search").
To(devops.SearchPipelines). To(devopsapi.SearchPipelines).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Search DevOps resource."). Doc("Search DevOps resource.").
Param(webservice.QueryParameter("q", "query pipelines"). Param(webservice.QueryParameter("q", "query pipelines").
...@@ -63,11 +70,13 @@ func addWebService(c *restful.Container) error { ...@@ -63,11 +70,13 @@ func addWebService(c *restful.Container) error {
DataFormat("start=%d")). DataFormat("start=%d")).
Param(webservice.QueryParameter("limit", "limit count"). Param(webservice.QueryParameter("limit", "limit count").
Required(false). Required(false).
DataFormat("limit=%d"))) DataFormat("limit=%d")).
Returns(http.StatusOK, RespMessage, []devops.Pipeline{}).
Writes([]devops.Pipeline{}))
// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/" // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs").
To(devops.SearchPipelineRuns). To(devopsapi.SearchPipelineRuns).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Search DevOps Pipelines runs."). Doc("Search DevOps Pipelines runs.").
Param(webservice.PathParameter("pipelineName", "pipeline name")). Param(webservice.PathParameter("pipelineName", "pipeline name")).
...@@ -77,21 +86,31 @@ func addWebService(c *restful.Container) error { ...@@ -77,21 +86,31 @@ func addWebService(c *restful.Container) error {
DataFormat("start=%d")). DataFormat("start=%d")).
Param(webservice.QueryParameter("limit", "limit count"). Param(webservice.QueryParameter("limit", "limit count").
Required(false). Required(false).
DataFormat("limit=%d"))) DataFormat("limit=%d")).
Param(webservice.QueryParameter("branch", "branch ").
Required(false).
DataFormat("branch=%s")).
Returns(http.StatusOK, RespMessage, []devops.PipelineRun{}).
Writes([]devops.PipelineRun{}))
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/" // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}").
To(devops.GetPipelineRun). To(devopsapi.GetPipelineRun).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get DevOps Pipelines run."). Doc("Get DevOps Pipelines run.").
Param(webservice.PathParameter("pipelineName", "pipeline name")). Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")). Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id"))) Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("start", "start").
Required(false).
DataFormat("start=%d")).
Returns(http.StatusOK, RespMessage, devops.PipelineRun{}).
Writes(devops.PipelineRun{}))
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes" // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes").
To(devops.GetPipelineRunNodes). To(devopsapi.GetPipelineRunNodes).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get node on DevOps Pipelines run."). Doc("Get node on DevOps Pipelines run.").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
...@@ -101,13 +120,16 @@ func addWebService(c *restful.Container) error { ...@@ -101,13 +120,16 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("limit", "limit"). Param(webservice.QueryParameter("limit", "limit").
Required(false). Required(false).
DataFormat("limit=%d"). DataFormat("limit=%d").
DefaultValue("limit=10000"))) DefaultValue("limit=10000")).
Returns(http.StatusOK, RespMessage, []devops.Nodes{}).
Writes([]devops.Nodes{}))
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0" // match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log"). webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log").
To(devops.GetStepLog). To(devopsapi.GetStepLog).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipelines step log."). Doc("Get pipelines step log.").
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")). Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")). Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")). Param(webservice.PathParameter("branchName", "pipeline branch name")).
...@@ -121,20 +143,198 @@ func addWebService(c *restful.Container) error { ...@@ -121,20 +143,198 @@ func addWebService(c *restful.Container) error {
// match "/blue/rest/organizations/jenkins/scm/github/validate/" // match "/blue/rest/organizations/jenkins/scm/github/validate/"
webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate"). webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate").
To(devops.Validate). To(devopsapi.Validate).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Validate Github personal access token."). Doc("Validate Github personal access token.").
Param(webservice.PathParameter("scmId", "SCM id"))) Param(webservice.PathParameter("scmId", "SCM id")).
Returns(http.StatusOK, RespMessage, devops.Validates{}).
Writes(devops.Validates{}))
// match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/?credentialId=github" // match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/?credentialId=github"
webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations"). webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations").
To(devops.GetOrgSCM). To(devopsapi.GetSCMOrg).
Metadata(restfulspec.KeyOpenAPITags, tags). Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("List organizations of SCM"). Doc("List organizations of SCM").
Param(webservice.PathParameter("scmId", "SCM id")). Param(webservice.PathParameter("scmId", "SCM id")).
Param(webservice.QueryParameter("credentialId", "credentialId for SCM"). Param(webservice.QueryParameter("credentialId", "credential id for SCM").
Required(true).
DataFormat("credentialId=%s")).
Returns(http.StatusOK, RespMessage, []devops.SCMOrg{}).
Writes([]devops.SCMOrg{}))
// match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/{organizationId}/repositories/?credentialId=&pageNumber&pageSize="
webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations/{organizationId}/repositories").
To(devopsapi.GetOrgRepo).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get SCM repositories in an organization").
Param(webservice.PathParameter("scmId", "SCM id")).
Param(webservice.PathParameter("organizationId", "organization Id, such as github username")).
Param(webservice.QueryParameter("credentialId", "credential id for SCM").
Required(true).
DataFormat("credentialId=%s")).
Param(webservice.QueryParameter("pageNumber", "page number").
Required(true).
DataFormat("pageNumber=%d")).
Param(webservice.QueryParameter("pageSize", "page size").
Required(true).
DataFormat("pageSize=%d")).
Returns(http.StatusOK, RespMessage, []devops.OrgRepo{}).
Writes([]devops.OrgRepo{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop/
webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop").
To(devopsapi.StopPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Stop pipeline in running").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep").
Required(false).
DataFormat("blocking=%t").
DefaultValue("blocking=false")).
Param(webservice.QueryParameter("timeOutInSecs", "the time of stop and between each retries sleep").
Required(false).
DataFormat("timeOutInSecs=%d").
DefaultValue("timeOutInSecs=10")).
Returns(http.StatusOK, RespMessage, devops.StopPipe{}).
Writes(devops.StopPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay/
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay").
To(devopsapi.ReplayPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Replay pipeline").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Returns(http.StatusOK, RespMessage, devops.ReplayPipe{}).
Writes(devops.ReplayPipe{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/log/?start=0
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/log").
To(devopsapi.GetRunLog).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipelines run log.").
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("start", "start").
Required(true). Required(true).
DataFormat("credentialId=%s"))) DataFormat("start=%d").
DefaultValue("start=0")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts").
To(devopsapi.GetArtifacts).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline artifacts.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.QueryParameter("start", "start page").
Required(false).
DataFormat("start=%d")).
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}).
Writes([]devops.Artifacts{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/?filter=&start&limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches").
To(devopsapi.GetPipeBranch).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline of branch.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.QueryParameter("filter", "filter remote").
Required(true).
DataFormat("filter=%s")).
Param(webservice.QueryParameter("start", "start").
Required(true).
DataFormat("start=%d")).
Param(webservice.QueryParameter("limit", "limit count").
Required(true).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespMessage, []devops.PipeBranch{}).
Writes([]devops.PipeBranch{}))
// /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}").
To(devopsapi.CheckPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build.").
Reads(devops.CheckPlayload{}).
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline runs id")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.PathParameter("stepId", "pipeline step id")))
// match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/console/log").
To(devopsapi.GetConsoleLog).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get index console log.").
Produces("text/plain; charset=utf-8").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")))
// match /job/{projectName}/job/{pipelineName}/build?delay=0
webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/scan").
To(devopsapi.ScanBranch).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Start a build.").
Produces("text/html; charset=utf-8").
Param(webservice.PathParameter("projecFtName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.QueryParameter("delay", "delay time").
Required(true).
DataFormat("delay=%d")))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{}/runs/
webservice.Route(webservice.POST("/devops/{projectName}/pipeline/{pipelineName}/branches/{brancheName}/run").
To(devopsapi.RunPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline artifacts.").
Reads(devops.RunPayload{}).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Returns(http.StatusOK, RespMessage, devops.QueuedBlueRun{}).
Writes(devops.QueuedBlueRun{}))
// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipeline/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status").
To(devopsapi.GetStepsStatus).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get pipeline steps status.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Param(webservice.PathParameter("runId", "pipeline run name")).
Param(webservice.PathParameter("nodeId", "pipeline node id")).
Param(webservice.QueryParameter("limit", "limit count").
Required(true).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespMessage, []devops.QueuedBlueRun{}).
Writes([]devops.QueuedBlueRun{}))
// match /crumbIssuer/api/json/
webservice.Route(webservice.GET("/devops/crumbIssuer").
To(devopsapi.GetCrumb).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get crumb").
Returns(http.StatusOK, RespMessage, devops.Crumb{}).
Writes(devops.Crumb{}))
c.Add(webservice) c.Add(webservice)
......
...@@ -20,7 +20,6 @@ package devops ...@@ -20,7 +20,6 @@ package devops
import ( import (
"github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
log "github.com/golang/glog" log "github.com/golang/glog"
"kubesphere.io/kubesphere/pkg/errors"
"kubesphere.io/kubesphere/pkg/models/devops" "kubesphere.io/kubesphere/pkg/models/devops"
"net/http" "net/http"
) )
...@@ -39,7 +38,6 @@ func GetPipeline(req *restful.Request, resp *restful.Response) { ...@@ -39,7 +38,6 @@ func GetPipeline(req *restful.Request, resp *restful.Response) {
} }
func SearchPipelines(req *restful.Request, resp *restful.Response) { func SearchPipelines(req *restful.Request, resp *restful.Response) {
res, err := devops.SearchPipelines(req.Request) res, err := devops.SearchPipelines(req.Request)
if err != nil { if err != nil {
parseErr(err, resp) parseErr(err, resp)
...@@ -120,10 +118,180 @@ func Validate(req *restful.Request, resp *restful.Response) { ...@@ -120,10 +118,180 @@ func Validate(req *restful.Request, resp *restful.Response) {
_, _ = resp.Write(res) _, _ = resp.Write(res)
} }
func GetOrgSCM(req *restful.Request, resp *restful.Response) { func GetSCMOrg(req *restful.Request, resp *restful.Response) {
scmId := req.PathParameter("scmId") 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 { if err != nil {
parseErr(err, resp) parseErr(err, resp)
return return
...@@ -135,9 +303,9 @@ func GetOrgSCM(req *restful.Request, resp *restful.Response) { ...@@ -135,9 +303,9 @@ func GetOrgSCM(req *restful.Request, resp *restful.Response) {
func parseErr(err error, resp *restful.Response) { func parseErr(err error, resp *restful.Response) {
log.Error(err) log.Error(err)
if jErr, ok := err.(*devops.JkError); ok { if jErr, ok := err.(*devops.JkError); ok {
_ = resp.WriteHeaderAndEntity(jErr.Code, err) _ = resp.WriteError(jErr.Code, err)
} else { } else {
_ = resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) _ = resp.WriteError(http.StatusInternalServerError, err)
} }
return return
} }
...@@ -39,15 +39,23 @@ func init() { ...@@ -39,15 +39,23 @@ func init() {
func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline, error) { func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineUrl, projectName, pipelineName) baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineUrl, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
var res = new(Pipeline)
resBody, err := jenkinsClient(baseUrl, req) err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
var res = new(Pipeline) return res, err
err = json.Unmarshal(resBody, &res) }
func SearchPipelines(req *http.Request) ([]interface{}, error) {
baseUrl := JenkinsUrl + SearchPipelineUrl + req.URL.RawQuery
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -56,18 +64,40 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline ...@@ -56,18 +64,40 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) (*Pipeline
return res, err return res, err
} }
func SearchPipelines(req *http.Request) ([]interface{}, error) { func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]interface{}, error) {
baseUrl := JenkinsUrl + SearchPipelineUrl + req.URL.RawQuery baseUrl := fmt.Sprintf(JenkinsUrl+SearchPipelineRunUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *http.Request) (*PipelineRun, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
var res = new(PipelineRun)
resBody, err := jenkinsClient(baseUrl, req) err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
return res, err
}
func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{} var res []interface{}
err = json.Unmarshal(resBody, &res)
err := jenkinsClient(baseUrl, req, &res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -76,18 +106,38 @@ func SearchPipelines(req *http.Request) ([]interface{}, error) { ...@@ -76,18 +106,38 @@ func SearchPipelines(req *http.Request) ([]interface{}, error) {
return res, err return res, err
} }
func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]interface{}, error) { func GetStepLog(projectName, pipelineName, branchName, runId, stepId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+SearchPipelineRunUrl+req.URL.RawQuery, projectName, pipelineName) baseUrl := fmt.Sprintf(JenkinsUrl+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func Validate(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ValidateUrl, scmId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := jenkinsClient(baseUrl, req) resBody, err := Client(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
return resBody, err
}
func GetSCMOrg(scmId string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetSCMOrgUrl+req.URL.RawQuery, scmId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{} var res []interface{}
err = json.Unmarshal(resBody, &res)
err := jenkinsClient(baseUrl, req, &res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -96,18 +146,26 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([] ...@@ -96,18 +146,26 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]
return res, err return res, err
} }
func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *http.Request) (*Pipeline, error) { func GetOrgRepo(scmId, organizationId string, req *http.Request) (*OrgRepo, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(JenkinsUrl+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
var res = new(OrgRepo)
resBody, err := jenkinsClient(baseUrl, req) err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
var res = new(Pipeline) return res, err
err = json.Unmarshal(resBody, &res) }
func StopPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) (*StopPipe, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(StopPipe)
err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -116,18 +174,39 @@ func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *ht ...@@ -116,18 +174,39 @@ func GetPipelineRun(projectName, pipelineName, branchName, runId string, req *ht
return res, err return res, err
} }
func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, req *http.Request) ([]interface{}, error) { func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) (*ReplayPipe, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) baseUrl := fmt.Sprintf(JenkinsUrl+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
var res = new(ReplayPipe)
resBody, err := jenkinsClient(baseUrl, req) err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
return res, err
}
func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := Client(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return resBody, err
}
func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{} var res []interface{}
err = json.Unmarshal(resBody, &res)
err := jenkinsClient(baseUrl, req, &res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -136,11 +215,25 @@ func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, re ...@@ -136,11 +215,25 @@ func GetPipelineRunNodes(projectName, pipelineName, branchName, runId string, re
return res, err return res, err
} }
func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) { func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]interface{}, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId) baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
var res []interface{}
err := jenkinsClient(baseUrl, req, &res)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := jenkinsClient(baseUrl, req) resBody, err := Client(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -149,11 +242,11 @@ func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId str ...@@ -149,11 +242,11 @@ func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId str
return resBody, err return resBody, err
} }
func Validate(scmId string, req *http.Request) ([]byte, error) { func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ValidateUrl, scmId) baseUrl := fmt.Sprintf(JenkinsUrl+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := jenkinsClient(baseUrl, req) resBody, err := Client(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -162,18 +255,39 @@ func Validate(scmId string, req *http.Request) ([]byte, error) { ...@@ -162,18 +255,39 @@ func Validate(scmId string, req *http.Request) ([]byte, error) {
return resBody, err return resBody, err
} }
func GetOrgSCM(scmId string, req *http.Request) ([]interface{}, error) { func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetOrgSCMUrl+req.URL.RawQuery, scmId) baseUrl := fmt.Sprintf(JenkinsUrl+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl) log.Infof("Jenkins-url: " + baseUrl)
resBody, err := jenkinsClient(baseUrl, req) resBody, err := Client(baseUrl, req)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
} }
var res []interface{} return resBody, err
err = json.Unmarshal(resBody, &res) }
func RunPipeline(projectName, pipelineName, branchName string, req *http.Request) (*QueuedBlueRun, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(QueuedBlueRun)
err := jenkinsClient(baseUrl, req, res)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) (*NodeStatus, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(NodeStatus)
err := jenkinsClient(baseUrl, req, res)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, err return nil, err
...@@ -182,8 +296,39 @@ func GetOrgSCM(scmId string, req *http.Request) ([]interface{}, error) { ...@@ -182,8 +296,39 @@ func GetOrgSCM(scmId string, req *http.Request) ([]interface{}, error) {
return res, err return res, err
} }
// create jenkins request func GetCrumb(req *http.Request) (*Crumb, error) {
func jenkinsClient(baseUrl string, req *http.Request) ([]byte, error) { baseUrl := fmt.Sprintf(JenkinsUrl + GetCrumbUrl)
log.Infof("Jenkins-url: " + baseUrl)
var res = new(Crumb)
err := jenkinsClient(baseUrl, req, res)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
// jenkins request and parse response
func jenkinsClient(baseUrl string, req *http.Request, res interface{}) error {
resBody, err := Client(baseUrl, req)
if err != nil {
log.Error(err)
return err
}
err = json.Unmarshal(resBody, res)
if err != nil {
log.Error(err)
return err
}
return nil
}
// create request
func Client(baseUrl string, req *http.Request) ([]byte, error) {
newReqUrl, err := url.Parse(baseUrl) newReqUrl, err := url.Parse(baseUrl)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -210,11 +355,8 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, error) { ...@@ -210,11 +355,8 @@ func jenkinsClient(baseUrl string, req *http.Request) ([]byte, error) {
log.Info(string(resBody)) log.Info(string(resBody))
if resp.StatusCode >= http.StatusBadRequest { if resp.StatusCode >= http.StatusBadRequest {
jkerr := new(JkError) jkerr := new(JkError)
err = json.Unmarshal(resBody, jkerr) jkerr.Code = resp.StatusCode
if err != nil { jkerr.Message = http.StatusText(resp.StatusCode)
log.Error(err)
return nil, err
}
return nil, jkerr return nil, jkerr
} }
......
...@@ -18,15 +18,8 @@ ...@@ -18,15 +18,8 @@
package devops package devops
type JkError struct { type JkError struct {
Message string `json:"message"`
Code int `json:"code"`
Errors []Errors `json:"errors"`
}
type Errors struct {
Message string `json:"message"` Message string `json:"message"`
Code string `json:"code"` Code int `json:"code"`
Field string `json:"field"`
} }
func (err *JkError) Error() string { func (err *JkError) Error() string {
......
...@@ -17,148 +17,715 @@ ...@@ -17,148 +17,715 @@
*/ */
package devops package devops
// GetPipeline & SearchPipelines
type Pipeline struct { type Pipeline struct {
Class string `json:"_class,omitempty"` Class string `json:"_class"`
Links Links `json:"_links,omitempty"` Links struct {
Actions []interface{} `json:"actions,omitempty"` Self struct {
DisplayName string `json:"displayName,omitempty"` Class string `json:"_class"`
FullDisplayName string `json:"fullDisplayName,omitempty"` Href string `json:"href"`
FullName string `json:"fullName,omitempty"` } `json:"self"`
Name interface{} `json:"name,omitempty"` Scm struct {
Organization string `json:"organization,omitempty"` Class string `json:"_class"`
Parameters interface{} `json:"parameters,omitempty"` Href string `json:"href"`
Permissions Permissions `json:"permissions,omitempty"` } `json:"scm"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis,omitempty"` Branches struct {
NumberOfFolders int `json:"numberOfFolders,omitempty"` Class string `json:"_class"`
NumberOfPipelines int `json:"numberOfPipelines,omitempty"` Href string `json:"href"`
PipelineFolderNames []interface{} `json:"pipelineFolderNames,omitempty"` } `json:"branches"`
WeatherScore int `json:"weatherScore,omitempty"` Actions struct {
BranchNames []string `json:"branchNames,omitempty"` Class string `json:"_class"`
NumberOfFailingBranches int `json:"numberOfFailingBranches,omitempty"` Href string `json:"href"`
NumberOfFailingPullRequests int `json:"numberOfFailingPullRequests,omitempty"` } `json:"actions"`
NumberOfSuccessfulBranches int `json:"numberOfSuccessfulBranches,omitempty"` Runs struct {
NumberOfSuccessfulPullRequests int `json:"numberOfSuccessfulPullRequests,omitempty"` Class string `json:"_class"`
ScmSource ScmSource `json:"scmSource,omitempty"` Href string `json:"href"`
TotalNumberOfBranches int `json:"totalNumberOfBranches,omitempty"` } `json:"runs"`
TotalNumberOfPullRequests int `json:"totalNumberOfPullRequests,omitempty"` Trends struct {
ArtifactsZipFile interface{} `json:"artifactsZipFile,omitempty"` Class string `json:"_class"`
CauseOfBlockage interface{} `json:"causeOfBlockage,omitempty"` Href string `json:"href"`
Causes []Causes `json:"causes,omitempty"` } `json:"trends"`
ChangeSet []interface{} `json:"changeSet,omitempty"` Queue struct {
Description interface{} `json:"description,omitempty"` Class string `json:"_class"`
DurationInMillis int `json:"durationInMillis,omitempty"` Href string `json:"href"`
EnQueueTime string `json:"enQueueTime,omitempty"` } `json:"queue"`
EndTime string `json:"endTime,omitempty"` } `json:"_links"`
ID string `json:"id,omitempty"` Actions []interface{} `json:"actions"`
Pipeline string `json:"pipeline,omitempty"` Disabled interface{} `json:"disabled"`
Replayable bool `json:"replayable,omitempty"` DisplayName string `json:"displayName"`
Result string `json:"result,omitempty"` FullDisplayName string `json:"fullDisplayName"`
RunSummary string `json:"runSummary,omitempty"` FullName string `json:"fullName"`
StartTime string `json:"startTime,omitempty"` Name string `json:"name"`
State string `json:"state,omitempty"` Organization string `json:"organization"`
Type string `json:"type,omitempty"` Parameters interface{} `json:"parameters"`
Branch Branch `json:"branch,omitempty"` Permissions struct {
CommitID string `json:"commitId,omitempty"` Create bool `json:"create"`
CommitURL interface{} `json:"commitUrl,omitempty"` Configure bool `json:"configure"`
PullRequest interface{} `json:"pullRequest,omitempty"` Read bool `json:"read"`
} Start bool `json:"start"`
type Self struct { Stop bool `json:"stop"`
Class string `json:"_class,omitempty"` } `json:"permissions"`
Href string `json:"href,omitempty"` EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
} NumberOfFolders int `json:"numberOfFolders"`
type Scm struct { NumberOfPipelines int `json:"numberOfPipelines"`
Class string `json:"_class,omitempty"` PipelineFolderNames []interface{} `json:"pipelineFolderNames"`
Href string `json:"href,omitempty"` WeatherScore int `json:"weatherScore"`
} BranchNames []string `json:"branchNames"`
type Branches struct { NumberOfFailingBranches int `json:"numberOfFailingBranches"`
Class string `json:"_class,omitempty"` NumberOfFailingPullRequests int `json:"numberOfFailingPullRequests"`
Href string `json:"href,omitempty"` NumberOfSuccessfulBranches int `json:"numberOfSuccessfulBranches"`
} NumberOfSuccessfulPullRequests int `json:"numberOfSuccessfulPullRequests"`
type Actions struct { ScmSource struct {
Class string `json:"_class,omitempty"` Class string `json:"_class"`
Href string `json:"href,omitempty"` APIURL interface{} `json:"apiUrl"`
} ID string `json:"id"`
type Runs struct { } `json:"scmSource"`
Class string `json:"_class,omitempty"` TotalNumberOfBranches int `json:"totalNumberOfBranches"`
Href string `json:"href,omitempty"` TotalNumberOfPullRequests int `json:"totalNumberOfPullRequests"`
}
type Trends struct {
Class string `json:"_class,omitempty"`
Href string `json:"href,omitempty"`
}
type Queue struct {
Class string `json:"_class,omitempty"`
Href string `json:"href,omitempty"`
} }
type Links struct {
Self Self `json:"self,omitempty"` // GetPipelineRun & SearchPipelineRuns
Scm Scm `json:"scm,omitempty"` type PipelineRun struct {
Branches Branches `json:"branches,omitempty"` Class string `json:"_class"`
Actions Actions `json:"actions,omitempty"` Links struct {
Runs Runs `json:"runs,omitempty"` PrevRun struct {
Trends Trends `json:"trends,omitempty"` Class string `json:"_class"`
Queue Queue `json:"queue,omitempty"` Href string `json:"href"`
PrevRun PrevRun `json:"prevRun"` } `json:"prevRun"`
Parent Parent `json:"parent"` Parent struct {
Tests Tests `json:"tests"` Class string `json:"_class"`
Nodes Nodes `json:"nodes"` Href string `json:"href"`
Log Log `json:"log"` } `json:"parent"`
BlueTestSummary BlueTestSummary `json:"blueTestSummary"` Tests struct {
Steps Steps `json:"steps"` Class string `json:"_class"`
Artifacts Artifacts `json:"artifacts"` Href string `json:"href"`
} `json:"tests"`
Nodes struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"nodes"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
NextRun struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"nextRun"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile interface{} `json:"artifactsZipFile"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
UserID string `json:"userId"`
UserName string `json:"userName"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis int `json:"durationInMillis"`
EnQueueTime string `json:"enQueueTime"`
EndTime string `json:"endTime"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary string `json:"runSummary"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
Branch struct {
IsPrimary bool `json:"isPrimary"`
Issues []interface{} `json:"issues"`
URL string `json:"url"`
} `json:"branch"`
CommitID string `json:"commitId"`
CommitURL interface{} `json:"commitUrl"`
PullRequest interface{} `json:"pullRequest"`
} }
type Permissions struct {
Create bool `json:"create,omitempty"` // GetPipelineRunNodes
Configure bool `json:"configure,omitempty"` type Nodes []struct {
Read bool `json:"read,omitempty"` Class string `json:"_class"`
Start bool `json:"start,omitempty"` Links struct {
Stop bool `json:"stop,omitempty"` Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
DisplayDescription interface{} `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Edges []struct {
Class string `json:"_class"`
ID string `json:"id"`
Type string `json:"type"`
} `json:"edges"`
FirstParent interface{} `json:"firstParent"`
Restartable bool `json:"restartable"`
Steps []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
} `json:"_links"`
Actions []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
URLName string `json:"urlName"`
} `json:"actions"`
DisplayDescription interface{} `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
} `json:"steps"`
} }
type ScmSource struct {
Class string `json:"_class,omitempty"` // Validate
APIURL interface{} `json:"apiUrl,omitempty"` type Validates struct {
ID string `json:"id,omitempty"` CredentialID string `json:"credentialId,omitempty"`
} }
type PrevRun struct {
// GetSCMOrg
type SCMOrg struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Repositories struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"repositories"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
Avatar string `json:"avatar"`
JenkinsOrganizationPipeline bool `json:"jenkinsOrganizationPipeline"`
Name string `json:"name"`
} }
type Parent struct {
// GetOrgRepo
type OrgRepo struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
Repositories struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
Items []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
DefaultBranch string `json:"defaultBranch"`
Description string `json:"description"`
Name string `json:"name"`
Permissions struct {
Admin bool `json:"admin"`
Push bool `json:"push"`
Pull bool `json:"pull"`
} `json:"permissions"`
Private bool `json:"private"`
FullName string `json:"fullName"`
} `json:"items"`
LastPage interface{} `json:"lastPage"`
NextPage interface{} `json:"nextPage"`
PageSize int `json:"pageSize"`
} `json:"repositories"`
} }
type Tests struct {
// StopPipeline
type StopPipe struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Nodes struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"nodes"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile interface{} `json:"artifactsZipFile"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis int `json:"durationInMillis"`
EnQueueTime string `json:"enQueueTime"`
EndTime string `json:"endTime"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary string `json:"runSummary"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
Branch struct {
IsPrimary bool `json:"isPrimary"`
Issues []interface{} `json:"issues"`
URL string `json:"url"`
} `json:"branch"`
CommitID string `json:"commitId"`
CommitURL interface{} `json:"commitUrl"`
PullRequest interface{} `json:"pullRequest"`
} }
type Nodes struct {
// ReplayPipeline
type ReplayPipe struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile interface{} `json:"artifactsZipFile"`
CauseOfBlockage string `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
UserID string `json:"userId,omitempty"`
UserName string `json:"userName,omitempty"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis interface{} `json:"durationInMillis"`
EnQueueTime interface{} `json:"enQueueTime"`
EndTime interface{} `json:"endTime"`
EstimatedDurationInMillis interface{} `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary interface{} `json:"runSummary"`
StartTime interface{} `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
QueueID string `json:"queueId"`
} }
type Log struct {
// GetArtifacts
type Artifacts struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
Downloadable bool `json:"downloadable"`
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Size int `json:"size"`
URL string `json:"url"` // The url for Download artifacts
} }
type BlueTestSummary struct {
// GetPipeBranch
type PipeBranch struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Scm struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"scm"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Runs struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"runs"`
Trends struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"trends"`
Queue struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"queue"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
Disabled bool `json:"disabled"`
DisplayName string `json:"displayName"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
FullDisplayName string `json:"fullDisplayName"`
FullName string `json:"fullName"`
LatestRun struct {
Class string `json:"_class"`
Links struct {
PrevRun struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"prevRun"`
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile string `json:"artifactsZipFile"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis int `json:"durationInMillis"`
EnQueueTime string `json:"enQueueTime"`
EndTime string `json:"endTime"`
EstimatedDurationInMillis int `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary string `json:"runSummary"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
} `json:"latestRun"`
Name string `json:"name"`
Organization string `json:"organization"`
Parameters []struct {
Class string `json:"_class"`
DefaultParameterValue struct {
Class string `json:"_class"`
Name string `json:"name"`
Value string `json:"value"`
} `json:"defaultParameterValue"`
Description string `json:"description"`
Name string `json:"name"`
Type string `json:"type"`
} `json:"parameters"`
Permissions struct {
Create bool `json:"create"`
Configure bool `json:"configure"`
Read bool `json:"read"`
Start bool `json:"start"`
Stop bool `json:"stop"`
} `json:"permissions"`
WeatherScore int `json:"weatherScore"`
Branch struct {
IsPrimary bool `json:"isPrimary"`
Issues []interface{} `json:"issues"`
URL string `json:"url"`
} `json:"branch"`
} }
type Steps struct {
// RunPipeline
type RunPayload struct {
Parameters []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"parameters"`
}
type QueuedBlueRun struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Parent struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"parent"`
Tests struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"tests"`
Log struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"log"`
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
BlueTestSummary struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"blueTestSummary"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Artifacts struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"artifacts"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
ArtifactsZipFile interface{} `json:"artifactsZipFile"`
CauseOfBlockage string `json:"causeOfBlockage"`
Causes []struct {
Class string `json:"_class"`
ShortDescription string `json:"shortDescription"`
UserID string `json:"userId"`
UserName string `json:"userName"`
} `json:"causes"`
ChangeSet []interface{} `json:"changeSet"`
Description interface{} `json:"description"`
DurationInMillis interface{} `json:"durationInMillis"`
EnQueueTime interface{} `json:"enQueueTime"`
EndTime interface{} `json:"endTime"`
EstimatedDurationInMillis interface{} `json:"estimatedDurationInMillis"`
ID string `json:"id"`
Name interface{} `json:"name"`
Organization string `json:"organization"`
Pipeline string `json:"pipeline"`
Replayable bool `json:"replayable"`
Result string `json:"result"`
RunSummary interface{} `json:"runSummary"`
StartTime interface{} `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
QueueID string `json:"queueId"`
} }
type Artifacts struct {
// GetNodeStatus
type NodeStatus []struct {
Class string `json:"_class"` Class string `json:"_class"`
Href string `json:"href"` Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
Steps struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"steps"`
} `json:"_links"`
Actions []interface{} `json:"actions"`
DisplayDescription interface{} `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
CauseOfBlockage interface{} `json:"causeOfBlockage"`
Edges []struct {
Class string `json:"_class"`
ID string `json:"id"`
Type string `json:"type"`
} `json:"edges"`
FirstParent interface{} `json:"firstParent"`
Restartable bool `json:"restartable"`
Steps []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
Actions struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"actions"`
} `json:"_links"`
Actions []struct {
Class string `json:"_class"`
Links struct {
Self struct {
Class string `json:"_class"`
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
URLName string `json:"urlName"`
} `json:"actions"`
DisplayDescription interface{} `json:"displayDescription"`
DisplayName string `json:"displayName"`
DurationInMillis int `json:"durationInMillis"`
ID string `json:"id"`
Input interface{} `json:"input"`
Result string `json:"result"`
StartTime string `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
} `json:"steps"`
} }
type Causes struct {
Class string `json:"_class"` // CheckPipeline
ShortDescription string `json:"shortDescription"` type CheckPlayload struct {
UserID string `json:"userId,omitempty"` ID string `json:"id"`
UserName string `json:"userName,omitempty"` Parameters []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"parameters"`
} }
type Branch struct {
IsPrimary bool `json:"isPrimary"` // Getcrumb
Issues []interface{} `json:"issues"` type Crumb struct {
URL string `json:"url"` Class string `json:"_class"`
Crumb string `json:"crumb"`
CrumbRequestField string `json:"crumbRequestField"`
} }
...@@ -26,5 +26,17 @@ const ( ...@@ -26,5 +26,17 @@ const (
GetPipelineRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?" GetPipelineRunNodesUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/?"
GetStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?" GetStepLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/%s/log/?"
ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate" ValidateUrl = "/blue/rest/organizations/jenkins/scm/%s/validate"
GetOrgSCMUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?" GetSCMOrgUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/?"
GetOrgRepoUrl = "/blue/rest/organizations/jenkins/scm/%s/organizations/%s/repositories/?"
StopPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/stop/?"
ReplayPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/replay/"
GetRunLogUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/log/?"
GetArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/artifacts/?"
GetPipeBranchUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/?"
GetConsoleLogUrl = "/job/%s/job/%s/indexing/consoleText"
ScanBranchUrl = "/job/%s/job/%s/build?"
RunPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/"
GetStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/"
GetCrumbUrl = "/crumbIssuer/api/json/"
) )
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册