register.go 30.2 KB
Newer Older
S
sunzhu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*

  Copyright 2019 The KubeSphere Authors.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

R
update  
runzexia 已提交
17
*/
18

S
sunzhu 已提交
19 20 21 22 23 24
package v1alpha2

import (
	"github.com/emicklei/go-restful"
	"github.com/emicklei/go-restful-openapi"
	"k8s.io/apimachinery/pkg/runtime/schema"
25
	devopsapi "kubesphere.io/kubesphere/pkg/apiserver/devops"
S
sunzhu 已提交
26
	"kubesphere.io/kubesphere/pkg/apiserver/runtime"
27
	"kubesphere.io/kubesphere/pkg/models/devops"
R
runzexia 已提交
28

R
runzexia 已提交
29
	"kubesphere.io/kubesphere/pkg/params"
R
runzexia 已提交
30
	"net/http"
S
sunzhu 已提交
31 32
)

R
runzexia 已提交
33 34 35 36
const (
	GroupName = "devops.kubesphere.io"
	RespOK    = "ok"
)
S
sunzhu 已提交
37 38 39 40 41 42 43 44 45

var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}

var (
	WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
	AddToContainer    = WebServiceBuilder.AddToContainer
)

func addWebService(c *restful.Container) error {
46

S
sunzhu 已提交
47 48
	webservice := runtime.NewWebService(GroupVersion)

49 50 51 52 53 54
	tags := []string{"DevOps"}

	webservice.Route(webservice.GET("/devops/{devops}").
		To(devopsapi.GetDevOpsProjectHandler).
		Doc("get devops project").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
55
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
56
		Returns(http.StatusOK, RespOK, devops.DevOpsProject{}).
R
runzexia 已提交
57
		Writes(devops.DevOpsProject{}))
58 59 60 61 62

	webservice.Route(webservice.PATCH("/devops/{devops}").
		To(devopsapi.UpdateProjectHandler).
		Doc("get devops project").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
63
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
64
		Returns(http.StatusOK, RespOK, devops.DevOpsProject{}).
R
runzexia 已提交
65
		Writes(devops.DevOpsProject{}))
66 67 68 69 70

	webservice.Route(webservice.GET("/devops/{devops}/defaultroles").
		To(devopsapi.GetDevOpsProjectDefaultRoles).
		Doc("get devops project defaultroles").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
71
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
72
		Returns(http.StatusOK, RespOK, []devops.Role{}).
R
runzexia 已提交
73
		Writes([]devops.Role{}))
74 75 76 77 78

	webservice.Route(webservice.GET("/devops/{devops}/members").
		To(devopsapi.GetDevOpsProjectMembersHandler).
		Doc("get devops project members").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
79 80 81 82 83 84 85 86
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.QueryParameter(params.PagingParam, "page").
			Required(false).
			DataFormat("limit=%d,page=%d").
			DefaultValue("limit=10,page=1")).
		Param(webservice.QueryParameter(params.ConditionsParam, "query conditions").
			Required(false).
			DataFormat("key=%s,key~%s")).
R
runzexia 已提交
87
		Returns(http.StatusOK, RespOK, []devops.DevOpsProjectMembership{}).
R
runzexia 已提交
88
		Writes([]devops.DevOpsProjectMembership{}))
89 90 91 92 93

	webservice.Route(webservice.GET("/devops/{devops}/members/{members}").
		To(devopsapi.GetDevOpsProjectMemberHandler).
		Doc("get devops project member").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
94 95
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("members", "member's username")).
R
runzexia 已提交
96
		Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
R
runzexia 已提交
97
		Writes(devops.DevOpsProjectMembership{}))
98 99 100 101 102

	webservice.Route(webservice.POST("/devops/{devops}/members").
		To(devopsapi.AddDevOpsProjectMemberHandler).
		Doc("add devops project members").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
103
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
104
		Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
R
runzexia 已提交
105 106 107 108 109 110
		Writes(devops.DevOpsProjectMembership{}))

	webservice.Route(webservice.PATCH("/devops/{devops}/members/{members}").
		To(devopsapi.UpdateDevOpsProjectMemberHandler).
		Doc("update devops project members").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
111 112
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("members", "member's username")).
R
runzexia 已提交
113 114 115 116 117 118 119
		Reads(devops.DevOpsProjectMembership{}).
		Writes(devops.DevOpsProjectMembership{}))

	webservice.Route(webservice.DELETE("/devops/{devops}/members/{members}").
		To(devopsapi.DeleteDevOpsProjectMemberHandler).
		Doc("delete devops project members").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
120 121
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("members", "member's username")).
R
runzexia 已提交
122 123
		Writes(devops.DevOpsProjectMembership{}))

R
runzexia 已提交
124 125 126
	webservice.Route(webservice.POST("/devops/{devops}/pipelines").
		To(devopsapi.CreateDevOpsProjectPipelineHandler).
		Doc("add devops project pipeline").
R
runzexia 已提交
127
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
128
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
129
		Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
R
runzexia 已提交
130 131 132
		Writes(devops.ProjectPipeline{}).
		Reads(devops.ProjectPipeline{}))

R
runzexia 已提交
133 134
	webservice.Route(webservice.PUT("/devops/{devops}/pipelines/{pipelines}").
		To(devopsapi.UpdateDevOpsProjectPipelineHandler).
R
runzexia 已提交
135
		Doc("update devops project pipeline").
R
runzexia 已提交
136 137
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("pipelines", "pipeline name")).
R
runzexia 已提交
138
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
139
		Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
R
runzexia 已提交
140 141 142
		Writes(devops.ProjectPipeline{}).
		Reads(devops.ProjectPipeline{}))

R
runzexia 已提交
143 144 145 146
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/config").
		To(devopsapi.GetDevOpsProjectPipelineHandler).
		Doc("get devops project pipeline config").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
147 148
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("pipelines", "pipeline name")).
R
runzexia 已提交
149
		Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
R
runzexia 已提交
150
		Writes(devops.ProjectPipeline{}))
R
runzexia 已提交
151

R
runzexia 已提交
152 153 154 155
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/sonarStatus").
		To(devopsapi.GetPipelineSonarStatusHandler).
		Doc("get devops project pipeline sonarStatus").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
156 157
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("pipelines", "pipeline name")).
R
runzexia 已提交
158
		Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
R
runzexia 已提交
159
		Writes([]devops.SonarStatus{}))
R
runzexia 已提交
160

R
runzexia 已提交
161 162 163 164
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}/branches/{branches}/sonarStatus").
		To(devopsapi.GetMultiBranchesPipelineSonarStatusHandler).
		Doc("get devops project pipeline sonarStatus").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
165 166 167
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("pipelines", "pipeline name")).
		Param(webservice.PathParameter("branches", "branch name")).
R
runzexia 已提交
168
		Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
R
runzexia 已提交
169
		Writes([]devops.SonarStatus{}))
R
runzexia 已提交
170

R
runzexia 已提交
171 172 173
	webservice.Route(webservice.DELETE("/devops/{devops}/pipelines/{pipelines}").
		To(devopsapi.DeleteDevOpsProjectPipelineHandler).
		Doc("delete devops project pipeline").
R
runzexia 已提交
174
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
175 176
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("pipelines", "pipeline name")))
R
runzexia 已提交
177

R
runzexia 已提交
178 179
	webservice.Route(webservice.PUT("/devops/{devops}/pipelines").
		To(devopsapi.CreateDevOpsProjectPipelineHandler).
R
runzexia 已提交
180
		Doc("update devops project pipeline").
R
runzexia 已提交
181
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
182 183
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Reads(devops.ProjectPipeline{}))
184

R
runzexia 已提交
185 186 187
	webservice.Route(webservice.POST("/devops/{devops}/credentials").
		To(devopsapi.CreateDevOpsProjectCredentialHandler).
		Doc("add project credential pipeline").
188
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
189
		Param(webservice.PathParameter("devops", "devops project's Id")).
R
runzexia 已提交
190 191 192 193 194 195
		Reads(devops.JenkinsCredential{}))

	webservice.Route(webservice.PUT("/devops/{devops}/credentials/{credentials}").
		To(devopsapi.UpdateDevOpsProjectCredentialHandler).
		Doc("update project credential pipeline").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
196 197
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("credentials", "credential's Id")).
R
runzexia 已提交
198 199 200 201 202
		Reads(devops.JenkinsCredential{}))

	webservice.Route(webservice.DELETE("/devops/{devops}/credentials/{credentials}").
		To(devopsapi.DeleteDevOpsProjectCredentialHandler).
		Doc("delete project credential pipeline").
203
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
204 205
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("credentials", "credential's Id")))
R
runzexia 已提交
206 207 208 209 210

	webservice.Route(webservice.GET("/devops/{devops}/credentials/{credentials}").
		To(devopsapi.GetDevOpsProjectCredentialHandler).
		Doc("get project credential pipeline").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
211 212 213 214
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("credentials", "credential's Id")).
		Param(webservice.QueryParameter("domain", "credential's domain")).
		Param(webservice.QueryParameter("content", "get additional content")).
R
runzexia 已提交
215
		Returns(http.StatusOK, RespOK, devops.JenkinsCredential{}).
R
runzexia 已提交
216 217 218 219 220 221
		Reads(devops.JenkinsCredential{}))

	webservice.Route(webservice.GET("/devops/{devops}/credentials").
		To(devopsapi.GetDevOpsProjectCredentialsHandler).
		Doc("get project credential pipeline").
		Metadata(restfulspec.KeyOpenAPITags, tags).
R
runzexia 已提交
222 223 224
		Param(webservice.PathParameter("devops", "devops project's Id")).
		Param(webservice.PathParameter("credentials", "credential's Id")).
		Param(webservice.QueryParameter("domain", "credential's domain")).
R
runzexia 已提交
225
		Returns(http.StatusOK, RespOK, []devops.JenkinsCredential{}).
R
runzexia 已提交
226
		Reads([]devops.JenkinsCredential{}))
S
sunzhu 已提交
227 228 229

	// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}"
	webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}").
230
		To(devopsapi.GetPipeline).
S
sunzhu 已提交
231 232 233
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get DevOps Pipelines.").
		Param(webservice.PathParameter("pipelineName", "pipeline name")).
Z
Zhuxiaoyang 已提交
234
		Param(webservice.PathParameter("projectName", "devops project name")).
R
runzexia 已提交
235
		Returns(http.StatusOK, RespOK, devops.Pipeline{}).
Z
Zhuxiaoyang 已提交
236
		Writes(devops.Pipeline{}))
S
sunzhu 已提交
237 238 239

	// match Jenkisn api: "jenkins_api/blue/rest/search"
	webservice.Route(webservice.GET("/devops/search").
240
		To(devopsapi.SearchPipelines).
S
sunzhu 已提交
241 242 243
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Search DevOps resource.").
		Param(webservice.QueryParameter("q", "query pipelines").
S
soulseen 已提交
244 245
			Required(false).
			DataFormat("q=%s")).
S
sunzhu 已提交
246
		Param(webservice.QueryParameter("filter", "filter resource").
S
soulseen 已提交
247 248
			Required(false).
			DataFormat("filter=%s")).
S
sunzhu 已提交
249
		Param(webservice.QueryParameter("start", "start page").
S
soulseen 已提交
250 251
			Required(false).
			DataFormat("start=%d")).
S
sunzhu 已提交
252
		Param(webservice.QueryParameter("limit", "limit count").
S
soulseen 已提交
253
			Required(false).
Z
Zhuxiaoyang 已提交
254
			DataFormat("limit=%d")).
R
runzexia 已提交
255
		Returns(http.StatusOK, RespOK, []devops.Pipeline{}).
Z
Zhuxiaoyang 已提交
256
		Writes([]devops.Pipeline{}))
S
sunzhu 已提交
257 258 259

	// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/"
	webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs").
260
		To(devopsapi.SearchPipelineRuns).
S
sunzhu 已提交
261
		Metadata(restfulspec.KeyOpenAPITags, tags).
Z
Zhuxiaoyang 已提交
262
		Doc("Search DevOps Pipelines runs in branch.").
S
sunzhu 已提交
263 264 265
		Param(webservice.PathParameter("pipelineName", "pipeline name")).
		Param(webservice.PathParameter("projectName", "devops project name")).
		Param(webservice.QueryParameter("start", "start page").
S
soulseen 已提交
266 267
			Required(false).
			DataFormat("start=%d")).
S
sunzhu 已提交
268
		Param(webservice.QueryParameter("limit", "limit count").
S
soulseen 已提交
269
			Required(false).
Z
Zhuxiaoyang 已提交
270 271 272 273
			DataFormat("limit=%d")).
		Param(webservice.QueryParameter("branch", "branch ").
			Required(false).
			DataFormat("branch=%s")).
Z
Zhuxiaoyang 已提交
274 275
		Returns(http.StatusOK, RespOK, []devops.BranchPipelineRun{}).
		Writes([]devops.BranchPipelineRun{}))
S
sunzhu 已提交
276 277 278

	// 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}").
Z
Zhuxiaoyang 已提交
279
		To(devopsapi.GetBranchPipelineRun).
S
sunzhu 已提交
280
		Metadata(restfulspec.KeyOpenAPITags, tags).
Z
Zhuxiaoyang 已提交
281
		Doc("Get DevOps Pipelines run in branch.").
S
sunzhu 已提交
282 283 284
		Param(webservice.PathParameter("pipelineName", "pipeline name")).
		Param(webservice.PathParameter("projectName", "devops project name")).
		Param(webservice.PathParameter("branchName", "pipeline branch name")).
Z
Zhuxiaoyang 已提交
285 286 287 288
		Param(webservice.PathParameter("runId", "pipeline runs id")).
		Param(webservice.QueryParameter("start", "start").
			Required(false).
			DataFormat("start=%d")).
Z
Zhuxiaoyang 已提交
289 290
		Returns(http.StatusOK, RespOK, devops.BranchPipelineRun{}).
		Writes(devops.BranchPipelineRun{}))
S
sunzhu 已提交
291 292 293

	// 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").
Z
Zhuxiaoyang 已提交
294
		To(devopsapi.GetPipelineRunNodesbyBranch).
S
sunzhu 已提交
295 296 297 298 299 300 301 302 303
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get node on DevOps Pipelines run.").
		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("limit", "limit").
			Required(false).
			DataFormat("limit=%d").
Z
Zhuxiaoyang 已提交
304
			DefaultValue("limit=10000")).
Z
Zhuxiaoyang 已提交
305 306
		Returns(http.StatusOK, RespOK, []devops.BranchPipelineRunNodes{}).
		Writes([]devops.BranchPipelineRunNodes{}))
S
sunzhu 已提交
307 308 309

	// 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").
310
		To(devopsapi.GetStepLog).
S
sunzhu 已提交
311
		Metadata(restfulspec.KeyOpenAPITags, tags).
Z
Zhuxiaoyang 已提交
312 313
		Doc("Get pipelines step log.").
		Produces("text/plain; charset=utf-8").
S
sunzhu 已提交
314 315 316 317 318 319 320 321 322 323 324
		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 runs node id")).
		Param(webservice.PathParameter("stepId", "pipeline runs step id")).
		Param(webservice.QueryParameter("start", "start").
			Required(true).
			DataFormat("start=%d").
			DefaultValue("start=0")))

S
soulseen 已提交
325 326
	// match "/blue/rest/organizations/jenkins/scm/github/validate/"
	webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate").
327
		To(devopsapi.Validate).
S
soulseen 已提交
328 329
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Validate Github personal access token.").
Z
Zhuxiaoyang 已提交
330
		Param(webservice.PathParameter("scmId", "SCM id")).
R
runzexia 已提交
331
		Returns(http.StatusOK, RespOK, devops.Validates{}).
Z
Zhuxiaoyang 已提交
332
		Writes(devops.Validates{}))
S
soulseen 已提交
333 334 335

	// match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/?credentialId=github"
	webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations").
Z
Zhuxiaoyang 已提交
336
		To(devopsapi.GetSCMOrg).
S
soulseen 已提交
337 338 339
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("List organizations of SCM").
		Param(webservice.PathParameter("scmId", "SCM id")).
Z
Zhuxiaoyang 已提交
340 341 342
		Param(webservice.QueryParameter("credentialId", "credential id for SCM").
			Required(true).
			DataFormat("credentialId=%s")).
R
runzexia 已提交
343
		Returns(http.StatusOK, RespOK, []devops.SCMOrg{}).
Z
Zhuxiaoyang 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
		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")).
R
runzexia 已提交
362
		Returns(http.StatusOK, RespOK, []devops.OrgRepo{}).
Z
Zhuxiaoyang 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
		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")).
R
runzexia 已提交
382
		Returns(http.StatusOK, RespOK, devops.StopPipe{}).
Z
Zhuxiaoyang 已提交
383 384
		Writes(devops.StopPipe{}))

Z
Zhuxiaoyang 已提交
385
	// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/Replay/
Z
Zhuxiaoyang 已提交
386 387 388 389 390 391 392 393
	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")).
R
runzexia 已提交
394
		Returns(http.StatusOK, RespOK, devops.ReplayPipe{}).
Z
Zhuxiaoyang 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407
		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").
S
soulseen 已提交
408
			Required(true).
Z
Zhuxiaoyang 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
			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").
S
soulseen 已提交
444
			Required(true).
Z
Zhuxiaoyang 已提交
445
			DataFormat("limit=%d")).
R
runzexia 已提交
446
		Returns(http.StatusOK, RespOK, []devops.PipeBranch{}).
Z
Zhuxiaoyang 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
		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/
Z
Zhuxiaoyang 已提交
485
	webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/run").
Z
Zhuxiaoyang 已提交
486 487 488 489 490 491 492
		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")).
R
runzexia 已提交
493
		Returns(http.StatusOK, RespOK, devops.QueuedBlueRun{}).
Z
Zhuxiaoyang 已提交
494 495 496
		Writes(devops.QueuedBlueRun{}))

	// match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit=
Z
Zhuxiaoyang 已提交
497
	webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status").
Z
Zhuxiaoyang 已提交
498 499 500 501 502 503 504 505 506 507 508
		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")).
R
runzexia 已提交
509
		Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}).
Z
Zhuxiaoyang 已提交
510 511 512
		Writes([]devops.QueuedBlueRun{}))

	// match /crumbIssuer/api/json/
Z
Zhuxiaoyang 已提交
513
	webservice.Route(webservice.GET("/devops/crumbissuer").
Z
Zhuxiaoyang 已提交
514 515 516
		To(devopsapi.GetCrumb).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get crumb").
R
runzexia 已提交
517
		Returns(http.StatusOK, RespOK, devops.Crumb{}).
Z
Zhuxiaoyang 已提交
518
		Writes(devops.Crumb{}))
S
soulseen 已提交
519

Z
Zhuxiaoyang 已提交
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
	// match /job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile
	webservice.Route(webservice.POST("/devops/check/scriptcompile").
		To(devopsapi.CheckScriptCompile).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Consumes("application/x-www-form-urlencoded", "charset=utf-8").
		Produces("application/json", "charset=utf-8").
		Doc("Check pipeline script compile.").
		Reads("value=\"\"").
		Returns(http.StatusOK, RespOK, devops.CheckScript{}).
		Writes(devops.CheckScript{}))

	// match /job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec
	webservice.Route(webservice.GET("/devops/check/cron").
		To(devopsapi.CheckCron).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Produces("application/json", "charset=utf-8").
		Doc("Check pipeline script compile.").
		Param(webservice.QueryParameter("value", "cpec value").
			Required(true).
			DataFormat("value=%s")).
		Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}).
		Returns(http.StatusOK, RespOK, devops.CheckCronRes{}).
		Writes(devops.CheckCronRes{}))

	// match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/
	webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}").
		To(devopsapi.GetPipelineRun).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get run pipeline in project.").
		Param(webservice.PathParameter("projectName", "devops project name")).
		Param(webservice.PathParameter("pipelineName", "pipeline name")).
		Param(webservice.PathParameter("runId", "pipeline run id")).
		Returns(http.StatusOK, RespOK, devops.PipelineRun{}).
		Writes(devops.PipelineRun{}))

	// match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}
	webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}").
Z
Zhuxiaoyang 已提交
557
		To(devopsapi.GetBranchPipeline).
Z
Zhuxiaoyang 已提交
558 559 560 561 562
		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")).
Z
Zhuxiaoyang 已提交
563 564
		Returns(http.StatusOK, RespOK, devops.BranchPipeline{}).
		Writes(devops.BranchPipeline{}))
Z
Zhuxiaoyang 已提交
565 566 567

	// 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").
Z
Zhuxiaoyang 已提交
568
		To(devopsapi.GetPipelineRunNodes).
Z
Zhuxiaoyang 已提交
569 570 571 572 573 574 575 576
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get Pipeline run nodes.").
		Param(webservice.PathParameter("projectName", "devops project name")).
		Param(webservice.PathParameter("pipelineName", "pipeline name")).
		Param(webservice.PathParameter("runId", "pipeline run id")).
		Param(webservice.QueryParameter("limit", "limit count").
			Required(false).
			DataFormat("limit=%d")).
Z
Zhuxiaoyang 已提交
577 578
		Returns(http.StatusOK, RespOK, []devops.PipelineRunNodes{}).
		Writes([]devops.PipelineRunNodes{}))
Z
Zhuxiaoyang 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617

	// 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").
		To(devopsapi.GetNodeSteps).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Doc("Get steps in node.").
		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 id")).
		Param(webservice.PathParameter("nodeId", "pipeline node id")).
		Param(webservice.QueryParameter("limit", "limit count").
			Required(false).
			DataFormat("limit=%d")).
		Returns(http.StatusOK, RespOK,[]devops.NodeSteps{}).
		Writes([]devops.NodeSteps{}))

	// match /pipeline-model-converter/toJenkinsfile
	webservice.Route(webservice.POST("/devops/tojenkinsfile").
		To(devopsapi.ToJenkinsfile).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Consumes("application/x-www-form-urlencoded").
		Produces("application/json", "charset=utf-8").
		Doc("Json to Jenkinsfile.").
		Reads(devops.ReqJson{}).
		Returns(http.StatusOK, RespOK,devops.NodeSteps{}).
		Writes(devops.ResJenkinsfile{}))

	// match /pipeline-model-converter/toJson
	webservice.Route(webservice.POST("/devops/tojson").
		To(devopsapi.ToJson).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Consumes("application/x-www-form-urlencoded").
		Produces("application/json", "charset=utf-8").
		Doc("Jenkinsfile to Json.").
		Reads(devops.ReqJenkinsfile{}).
		Returns(http.StatusOK, RespOK,devops.ResJson{}).
		Writes(devops.ResJson{}))

Z
Zhuxiaoyang 已提交
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
	// 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."))

S
sunzhu 已提交
644 645 646 647
	c.Add(webservice)

	return nil
}