提交 2857071b 编写于 作者: Z Zhuxiaoyang 提交者: zryfish

Dev (#9)

* add tag & add webhook api
Signed-off-by: Nsoulseen <sunzhu@yunify.com>
上级 daab932e
......@@ -271,12 +271,12 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("branch", "branch ").
Required(false).
DataFormat("branch=%s")).
Returns(http.StatusOK, RespOK, []devops.PipeBranchRun{}).
Writes([]devops.PipeBranchRun{}))
Returns(http.StatusOK, RespOK, []devops.BranchPipelineRun{}).
Writes([]devops.BranchPipelineRun{}))
// 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}").
To(devopsapi.GetPipeBranchRun).
To(devopsapi.GetBranchPipelineRun).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get DevOps Pipelines run in branch.").
Param(webservice.PathParameter("pipelineName", "pipeline name")).
......@@ -286,12 +286,12 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("start", "start").
Required(false).
DataFormat("start=%d")).
Returns(http.StatusOK, RespOK, devops.PipeBranchRun{}).
Writes(devops.PipeBranchRun{}))
Returns(http.StatusOK, RespOK, devops.BranchPipelineRun{}).
Writes(devops.BranchPipelineRun{}))
// 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").
To(devopsapi.GetBranchPipeRunNodes).
To(devopsapi.GetPipelineRunNodesbyBranch).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get node on DevOps Pipelines run.").
Param(webservice.PathParameter("projectName", "devops project name")).
......@@ -302,8 +302,8 @@ func addWebService(c *restful.Container) error {
Required(false).
DataFormat("limit=%d").
DefaultValue("limit=10000")).
Returns(http.StatusOK, RespOK, []devops.BranchPipeRunNodes{}).
Writes([]devops.BranchPipeRunNodes{}))
Returns(http.StatusOK, RespOK, []devops.BranchPipelineRunNodes{}).
Writes([]devops.BranchPipelineRunNodes{}))
// 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").
......@@ -554,18 +554,18 @@ func addWebService(c *restful.Container) error {
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}").
To(devopsapi.GetBranchPipe).
To(devopsapi.GetBranchPipeline).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipeline run in branch.").
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.PathParameter("branchName", "pipeline branch name")).
Returns(http.StatusOK, RespOK, devops.BranchPipe{}).
Writes(devops.BranchPipe{}))
Returns(http.StatusOK, RespOK, devops.BranchPipeline{}).
Writes(devops.BranchPipeline{}))
// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/?limit=10000
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes").
To(devopsapi.GetPipeRunNodes).
To(devopsapi.GetPipelineRunNodes).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Pipeline run nodes.").
Param(webservice.PathParameter("projectName", "devops project name")).
......@@ -574,8 +574,8 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK, []devops.PipeRunNodes{}).
Writes([]devops.PipeRunNodes{}))
Returns(http.StatusOK, RespOK, []devops.PipelineRunNodes{}).
Writes([]devops.PipelineRunNodes{}))
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit=
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps").
......@@ -615,6 +615,32 @@ func addWebService(c *restful.Container) error {
Returns(http.StatusOK, RespOK,devops.ResJson{}).
Writes(devops.ResJson{}))
// match /git/notifyCommit/?url=
webservice.Route(webservice.GET("/devops/notifycommit").
To(devopsapi.GetNotifyCommit).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Notify Commit by GET HTTP method.").
Produces("text/plain; charset=utf-8").
Param(webservice.QueryParameter("url", "the url for webhook to push.").
Required(true).
DataFormat("url=%s")))
// Gitlab or some other scm managers can only use HTTP method. match /git/notifyCommit/?url=
webservice.Route(webservice.POST("/devops/notifycommit").
To(devopsapi.GetNotifyCommit).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Get Notify Commit by POST HTTP method.").
Consumes("application/json").
Produces("text/plain; charset=utf-8").
Param(webservice.QueryParameter("url", "the url for webhook to push.").
Required(true).
DataFormat("url=%s")))
webservice.Route(webservice.POST("/devops/github/webhook").
To(devopsapi.GithubWebhook).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("receive webhook request."))
c.Add(webservice)
return nil
......
......@@ -46,7 +46,7 @@ func SearchPipelines(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -60,39 +60,39 @@ func SearchPipelineRuns(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetPipeBranchRun(req *restful.Request, resp *restful.Response) {
func GetBranchPipelineRun(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.GetPipeBranchRun(projectName, pipelineName, branchName, runId, req.Request)
res, err := devops.GetBranchPipelineRun(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetBranchPipeRunNodes(req *restful.Request, resp *restful.Response) {
func GetPipelineRunNodesbyBranch(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.GetBranchPipeRunNodes(projectName, pipelineName, branchName, runId, req.Request)
res, err := devops.GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -121,7 +121,7 @@ func Validate(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -134,7 +134,7 @@ func GetSCMOrg(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -148,7 +148,7 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -164,7 +164,7 @@ func StopPipeline(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -180,7 +180,7 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -210,7 +210,7 @@ func GetArtifacts(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -223,7 +223,7 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -281,7 +281,7 @@ func RunPipeline(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -298,7 +298,7 @@ func GetStepsStatus(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -309,7 +309,7 @@ func GetCrumb(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -344,7 +344,7 @@ func CheckCron(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -359,36 +359,36 @@ func GetPipelineRun(req *restful.Request, resp *restful.Response) {
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetBranchPipe(req *restful.Request, resp *restful.Response) {
func GetBranchPipeline(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
branchName := req.PathParameter("branchName")
res, err := devops.GetBranchPipe(projectName, pipelineName, branchName, req.Request)
res, err := devops.GetBranchPipeline(projectName, pipelineName, branchName, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetPipeRunNodes(req *restful.Request, resp *restful.Response) {
func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) {
projectName := req.PathParameter("projectName")
pipelineName := req.PathParameter("pipelineName")
runId := req.PathParameter("runId")
res, err := devops.GetPipeRunNodes(projectName, pipelineName, runId, req.Request)
res, err := devops.GetPipelineRunNodes(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
......@@ -404,29 +404,45 @@ func GetNodeSteps(req *restful.Request, resp *restful.Response) {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func ToJenkinsfile(req *restful.Request, resp *restful.Response) {
res, err := devops.ToJenkinsfile(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func ToJson(req *restful.Request, resp *restful.Response) {
res, err := devops.ToJson(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Header().Set(restful.HEADER_ContentType, "application/json")
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.Write(res)
}
func GetNotifyCommit(req *restful.Request, resp *restful.Response) {
res, err := devops.GetNotifyCommit(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Write(res)
}
func GithubWebhook(req *restful.Request, resp *restful.Response) {
res, err := devops.GithubWebhook(req.Request)
if err != nil {
parseErr(err, resp)
return
}
resp.Write(res)
}
......
......@@ -30,14 +30,20 @@ import (
"time"
)
var JenkinsUrl string
var (
jenkinsUrl string
jenkinsAdminUsername string
jenkinsAdminPassword string
)
func init() {
flag.StringVar(&JenkinsUrl, "jenkins-url", "http://ks-jenkins.kubesphere-devops-system.svc.cluster.local:80", "jenkins server host")
flag.StringVar(&jenkinsUrl, "jenkins-url", "http://ks-jenkins.kubesphere-devops-system.svc.cluster.local:80", "jenkins server host")
flag.StringVar(&jenkinsAdminUsername, "jenkins-adminusername", "admin", "admin username of jenkins")
flag.StringVar(&jenkinsAdminPassword, "jenkins-adminpassword", "passw0rd", "admin password of jenkins")
}
func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineUrl, projectName, pipelineName)
baseUrl := fmt.Sprintf(jenkinsUrl+GetPipelineUrl, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -50,7 +56,7 @@ func GetPipeline(projectName, pipelineName string, req *http.Request) ([]byte, e
}
func SearchPipelines(req *http.Request) ([]byte, error) {
baseUrl := JenkinsUrl + SearchPipelineUrl + req.URL.RawQuery
baseUrl := jenkinsUrl + SearchPipelineUrl + req.URL.RawQuery
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -63,7 +69,7 @@ func SearchPipelines(req *http.Request) ([]byte, error) {
}
func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+SearchPipelineRunUrl+req.URL.RawQuery, projectName, pipelineName)
baseUrl := fmt.Sprintf(jenkinsUrl+SearchPipelineRunUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -75,8 +81,8 @@ func SearchPipelineRuns(projectName, pipelineName string, req *http.Request) ([]
return res, err
}
func GetPipeBranchRun(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeBranchRunUrl, projectName, pipelineName, branchName, runId)
func GetBranchPipelineRun(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl+GetPipeBranchRunUrl, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -88,8 +94,8 @@ func GetPipeBranchRun(projectName, pipelineName, branchName, runId string, req *
return res, err
}
func GetBranchPipeRunNodes(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
func GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl+GetBranchPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -102,7 +108,7 @@ func GetBranchPipeRunNodes(projectName, pipelineName, branchName, runId string,
}
func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetStepLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
......@@ -115,7 +121,7 @@ func GetStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId str
}
func Validate(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ValidateUrl, scmId)
baseUrl := fmt.Sprintf(jenkinsUrl+ValidateUrl, scmId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
......@@ -128,7 +134,7 @@ func Validate(scmId string, req *http.Request) ([]byte, error) {
}
func GetSCMOrg(scmId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetSCMOrgUrl+req.URL.RawQuery, scmId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetSCMOrgUrl+req.URL.RawQuery, scmId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -141,7 +147,7 @@ func GetSCMOrg(scmId string, req *http.Request) ([]byte, error) {
}
func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetOrgRepoUrl+req.URL.RawQuery, scmId, organizationId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -154,7 +160,7 @@ func GetOrgRepo(scmId, organizationId string, req *http.Request) ([]byte, error)
}
func StopPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
baseUrl := fmt.Sprintf(jenkinsUrl+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -167,7 +173,7 @@ func StopPipeline(projectName, pipelineName, branchName, runId string, req *http
}
func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
baseUrl := fmt.Sprintf(jenkinsUrl+ReplayPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -180,7 +186,7 @@ func ReplayPipeline(projectName, pipelineName, branchName, runId string, req *ht
}
func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetRunLogUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -193,7 +199,7 @@ func GetRunLog(projectName, pipelineName, branchName, runId string, req *http.Re
}
func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetArtifactsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -206,7 +212,7 @@ func GetArtifacts(projectName, pipelineName, branchName, runId string, req *http
}
func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeBranchUrl+req.URL.RawQuery, projectName, pipelineName)
baseUrl := fmt.Sprintf(jenkinsUrl+GetPipeBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -219,7 +225,7 @@ func GetPipeBranch(projectName, pipelineName string, req *http.Request) ([]byte,
}
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)
baseUrl := fmt.Sprintf(jenkinsUrl+CheckPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId, stepId)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
......@@ -232,7 +238,7 @@ func CheckPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId
}
func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
baseUrl := fmt.Sprintf(jenkinsUrl+GetConsoleLogUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
......@@ -245,7 +251,7 @@ func GetConsoleLog(projectName, pipelineName string, req *http.Request) ([]byte,
}
func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
baseUrl := fmt.Sprintf(jenkinsUrl+ScanBranchUrl+req.URL.RawQuery, projectName, pipelineName)
log.Infof("Jenkins-url: " + baseUrl)
resBody, err := sendJenkinsRequest(baseUrl, req)
......@@ -258,7 +264,7 @@ func ScanBranch(projectName, pipelineName string, req *http.Request) ([]byte, er
}
func RunPipeline(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
baseUrl := fmt.Sprintf(jenkinsUrl+RunPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -271,7 +277,7 @@ func RunPipeline(projectName, pipelineName, branchName string, req *http.Request
}
func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -284,7 +290,7 @@ func GetStepsStatus(projectName, pipelineName, branchName, runId, nodeId string,
}
func GetCrumb(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + GetCrumbUrl)
baseUrl := fmt.Sprintf(jenkinsUrl + GetCrumbUrl)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -297,8 +303,9 @@ func GetCrumb(req *http.Request) ([]byte, error) {
}
func CheckScriptCompile(req *http.Request) ([]byte, error) {
baseUrl := JenkinsUrl + CheckScriptCompileUrl
baseUrl := jenkinsUrl + CheckScriptCompileUrl
log.Infof("Jenkins-url: " + baseUrl)
req.SetBasicAuth(jenkinsAdminUsername, jenkinsAdminPassword)
resBody, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
......@@ -310,8 +317,9 @@ func CheckScriptCompile(req *http.Request) ([]byte, error) {
}
func CheckCron(req *http.Request) (*CheckCronRes, error) {
baseUrl := JenkinsUrl + CheckCronUrl + req.URL.RawQuery
baseUrl := jenkinsUrl + CheckCronUrl + req.URL.RawQuery
log.Infof("Jenkins-url: " + baseUrl)
req.SetBasicAuth(jenkinsAdminUsername, jenkinsAdminPassword)
var res = new(CheckCronRes)
resp, err := http.Get(baseUrl)
......@@ -334,7 +342,7 @@ func CheckCron(req *http.Request) (*CheckCronRes, error) {
}
func GetPipelineRun(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, runId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetPipelineRunUrl, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -346,8 +354,8 @@ func GetPipelineRun(projectName, pipelineName, runId string, req *http.Request)
return res, err
}
func GetBranchPipe(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetBranchPipeUrl, projectName, pipelineName, branchName)
func GetBranchPipeline(projectName, pipelineName, branchName string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl+GetBranchPipeUrl, projectName, pipelineName, branchName)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -359,8 +367,8 @@ func GetBranchPipe(projectName, pipelineName, branchName string, req *http.Reque
return res, err
}
func GetPipeRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
func GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl+GetPipeRunNodesUrl+req.URL.RawQuery, projectName, pipelineName, runId)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -373,9 +381,8 @@ func GetPipeRunNodes(projectName, pipelineName, runId string, req *http.Request)
}
func GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
baseUrl := fmt.Sprintf(jenkinsUrl+GetNodeStepsUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId)
log.Infof("Jenkins-url: " + baseUrl)
//var res = new(NodeSteps)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
......@@ -387,7 +394,7 @@ func GetNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, r
}
func ToJenkinsfile(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + ToJenkinsfileUrl)
baseUrl := fmt.Sprintf(jenkinsUrl + ToJenkinsfileUrl)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......@@ -400,7 +407,34 @@ func ToJenkinsfile(req *http.Request) ([]byte, error) {
}
func ToJson(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(JenkinsUrl + ToJsonUrl)
baseUrl := fmt.Sprintf(jenkinsUrl + ToJsonUrl)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GetNotifyCommit(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl + GetNotifyCommitUrl + req.URL.RawQuery)
log.Infof("Jenkins-url: " + baseUrl)
req.Method = "GET"
res, err := sendJenkinsRequest(baseUrl, req)
if err != nil {
log.Error(err)
return nil, err
}
return res, err
}
func GithubWebhook(req *http.Request) ([]byte, error) {
baseUrl := fmt.Sprintf(jenkinsUrl + GithubWebhookUrl + req.URL.RawQuery)
log.Infof("Jenkins-url: " + baseUrl)
res, err := sendJenkinsRequest(baseUrl, req)
......
此差异已折叠。
......@@ -47,4 +47,6 @@ const (
GetNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?"
ToJenkinsfileUrl = "/pipeline-model-converter/toJenkinsfile"
ToJsonUrl = "/pipeline-model-converter/toJson"
GetNotifyCommitUrl = "/git/notifyCommit/?"
GithubWebhookUrl = "/github-webhook/"
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册