register.go 43.4 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"
R
runzexia 已提交
27
	"kubesphere.io/kubesphere/pkg/constants"
28
	"kubesphere.io/kubesphere/pkg/models/devops"
R
runzexia 已提交
29

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

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

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

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

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

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

50 51
	webservice.Route(webservice.GET("/devops/{devops}").
		To(devopsapi.GetDevOpsProjectHandler).
R
Ray Zhou 已提交
52
		Doc("Get the specified DevOps Project").
R
runzexia 已提交
53
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}).
R
Ray Zhou 已提交
54
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
55
		Returns(http.StatusOK, RespOK, devops.DevOpsProject{}).
R
runzexia 已提交
56
		Writes(devops.DevOpsProject{}))
57 58 59

	webservice.Route(webservice.PATCH("/devops/{devops}").
		To(devopsapi.UpdateProjectHandler).
R
Ray Zhou 已提交
60
		Doc("Update the specified DevOps Project").
R
runzexia 已提交
61
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag}).
R
Ray Zhou 已提交
62
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
63
		Reads(devops.DevOpsProject{}).
R
runzexia 已提交
64
		Returns(http.StatusOK, RespOK, devops.DevOpsProject{}).
R
runzexia 已提交
65
		Writes(devops.DevOpsProject{}))
66 67 68

	webservice.Route(webservice.GET("/devops/{devops}/defaultroles").
		To(devopsapi.GetDevOpsProjectDefaultRoles).
R
Ray Zhou 已提交
69
		Doc("Get the build-in roles info of the specified DevOps project").
R
runzexia 已提交
70
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
71
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
72
		Returns(http.StatusOK, RespOK, []devops.Role{}).
R
runzexia 已提交
73
		Writes([]devops.Role{}))
74 75 76

	webservice.Route(webservice.GET("/devops/{devops}/members").
		To(devopsapi.GetDevOpsProjectMembersHandler).
R
Ray Zhou 已提交
77
		Doc("Get the members of the specified DevOps project").
R
runzexia 已提交
78
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
79
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
80 81 82 83
		Param(webservice.QueryParameter(params.PagingParam, "page").
			Required(false).
			DataFormat("limit=%d,page=%d").
			DefaultValue("limit=10,page=1")).
R
Ray Zhou 已提交
84
		Param(webservice.QueryParameter(params.ConditionsParam, "query conditions, support using key-value pairs separated by comma to search, like 'conditions:somekey=somevalue,anotherkey=anothervalue'").
R
runzexia 已提交
85 86
			Required(false).
			DataFormat("key=%s,key~%s")).
R
runzexia 已提交
87
		Returns(http.StatusOK, RespOK, []devops.DevOpsProjectMembership{}).
R
runzexia 已提交
88
		Writes([]devops.DevOpsProjectMembership{}))
89

R
runzexia 已提交
90
	webservice.Route(webservice.GET("/devops/{devops}/members/{member}").
91
		To(devopsapi.GetDevOpsProjectMemberHandler).
R
Ray Zhou 已提交
92
		Doc("Get the specified member of the DevOps project").
R
runzexia 已提交
93
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
94 95
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("member", "member's username, e.g. admin")).
R
runzexia 已提交
96
		Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
R
runzexia 已提交
97
		Writes(devops.DevOpsProjectMembership{}))
98 99 100

	webservice.Route(webservice.POST("/devops/{devops}/members").
		To(devopsapi.AddDevOpsProjectMemberHandler).
R
Ray Zhou 已提交
101
		Doc("Add a member to the specified DevOps project").
R
runzexia 已提交
102
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
103
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
104
		Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
R
runzexia 已提交
105 106
		Writes(devops.DevOpsProjectMembership{}).
		Reads(devops.DevOpsProjectMembership{}))
R
runzexia 已提交
107

R
runzexia 已提交
108
	webservice.Route(webservice.PATCH("/devops/{devops}/members/{member}").
R
runzexia 已提交
109
		To(devopsapi.UpdateDevOpsProjectMemberHandler).
R
Ray Zhou 已提交
110
		Doc("Update the specified member of the DevOps project").
R
runzexia 已提交
111
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
112 113
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("member", "member's username, e.g. admin")).
R
runzexia 已提交
114
		Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
R
runzexia 已提交
115 116 117
		Reads(devops.DevOpsProjectMembership{}).
		Writes(devops.DevOpsProjectMembership{}))

R
runzexia 已提交
118
	webservice.Route(webservice.DELETE("/devops/{devops}/members/{member}").
R
runzexia 已提交
119
		To(devopsapi.DeleteDevOpsProjectMemberHandler).
R
Ray Zhou 已提交
120
		Doc("Delete the specified member of the DevOps project").
R
runzexia 已提交
121
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
R
Ray Zhou 已提交
122 123
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("member", "member's username, e.g. admin")).
R
runzexia 已提交
124 125
		Writes(devops.DevOpsProjectMembership{}))

R
runzexia 已提交
126 127
	webservice.Route(webservice.POST("/devops/{devops}/pipelines").
		To(devopsapi.CreateDevOpsProjectPipelineHandler).
R
Ray Zhou 已提交
128 129
		Doc("Create a DevOps project pipeline").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
130
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
runzexia 已提交
131
		Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
R
runzexia 已提交
132 133 134
		Writes(devops.ProjectPipeline{}).
		Reads(devops.ProjectPipeline{}))

R
runzexia 已提交
135
	webservice.Route(webservice.PUT("/devops/{devops}/pipelines/{pipeline}").
R
runzexia 已提交
136
		To(devopsapi.UpdateDevOpsProjectPipelineHandler).
R
Ray Zhou 已提交
137 138 139
		Doc("Update the specified pipeline of the DevOps project").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
R
runzexia 已提交
140
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
runzexia 已提交
141 142 143
		Writes(devops.ProjectPipeline{}).
		Reads(devops.ProjectPipeline{}))

S
soulseen 已提交
144 145
	webservice.Route(webservice.DELETE("/devops/{devops}/pipelines/{pipeline}").
		To(devopsapi.DeleteDevOpsProjectPipelineHandler).
R
Ray Zhou 已提交
146
		Doc("Delete the specified pipeline of the DevOps project").
R
runzexia 已提交
147
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
148 149
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")))
S
soulseen 已提交
150

R
runzexia 已提交
151
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/config").
R
runzexia 已提交
152
		To(devopsapi.GetDevOpsProjectPipelineHandler).
R
Ray Zhou 已提交
153
		Doc("Get the configuration information of the specified pipeline of the DevOps Project").
R
runzexia 已提交
154
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
155 156
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
R
runzexia 已提交
157
		Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
R
runzexia 已提交
158
		Writes(devops.ProjectPipeline{}))
R
runzexia 已提交
159

R
runzexia 已提交
160
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/sonarstatus").
R
runzexia 已提交
161
		To(devopsapi.GetPipelineSonarStatusHandler).
162
		Doc("Get the sonar quality information for the specified pipeline of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
R
runzexia 已提交
163
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
164
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
165
		Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
R
runzexia 已提交
166
		Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
R
runzexia 已提交
167
		Writes([]devops.SonarStatus{}))
R
runzexia 已提交
168

R
Ray Zhou 已提交
169
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/sonarstatus").
R
runzexia 已提交
170
		To(devopsapi.GetMultiBranchesPipelineSonarStatusHandler).
171
		Doc("Get the sonar quality check information for the specified pipeline branch of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
R
runzexia 已提交
172
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
173
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
Ray Zhou 已提交
174
		Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
R
runzexia 已提交
175
		Param(webservice.PathParameter("branch", "branch name, e.g. master")).
R
runzexia 已提交
176
		Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
R
runzexia 已提交
177
		Writes([]devops.SonarStatus{}))
R
runzexia 已提交
178 179 180

	webservice.Route(webservice.POST("/devops/{devops}/credentials").
		To(devopsapi.CreateDevOpsProjectCredentialHandler).
R
Ray Zhou 已提交
181
		Doc("Create a credential in the specified DevOps project").
R
runzexia 已提交
182
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectCredentialTag}).
R
Ray Zhou 已提交
183
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
184 185
		Reads(devops.JenkinsCredential{}))

R
runzexia 已提交
186
	webservice.Route(webservice.PUT("/devops/{devops}/credentials/{credential}").
R
runzexia 已提交
187
		To(devopsapi.UpdateDevOpsProjectCredentialHandler).
R
Ray Zhou 已提交
188
		Doc("Update the specified credential of the DevOps project").
R
runzexia 已提交
189
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectCredentialTag}).
R
Ray Zhou 已提交
190 191
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("credential", "credential's ID, e.g. dockerhub-id")).
R
runzexia 已提交
192 193
		Reads(devops.JenkinsCredential{}))

R
runzexia 已提交
194
	webservice.Route(webservice.DELETE("/devops/{devops}/credentials/{credential}").
R
runzexia 已提交
195
		To(devopsapi.DeleteDevOpsProjectCredentialHandler).
R
Ray Zhou 已提交
196
		Doc("Delete the specified credential of the DevOps project").
R
runzexia 已提交
197
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectCredentialTag}).
R
Ray Zhou 已提交
198 199
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("credential", "credential's ID, e.g. dockerhub-id")))
R
runzexia 已提交
200

R
runzexia 已提交
201
	webservice.Route(webservice.GET("/devops/{devops}/credentials/{credential}").
R
runzexia 已提交
202
		To(devopsapi.GetDevOpsProjectCredentialHandler).
R
Ray Zhou 已提交
203
		Doc("Get the specified credential of the DevOps project").
R
runzexia 已提交
204
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectCredentialTag}).
R
Ray Zhou 已提交
205 206
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
		Param(webservice.PathParameter("credential", "credential's ID, e.g. dockerhub-id")).
R
runzexia 已提交
207
		Param(webservice.QueryParameter("content", `
R
Ray Zhou 已提交
208 209 210 211
Get extra credential content if this query parameter is set. 
Specifically, there are three types of info in a credential. One is the basic info that must be returned for each query such as name, id, etc.
The second one is non-encrypted info such as the username of the username-password type of credential, which returns when the "content" parameter is set to non-empty.
The last one is encrypted info, such as the password of the username-password type of credential, which never returns.
R
runzexia 已提交
212
`)).
R
runzexia 已提交
213
		Returns(http.StatusOK, RespOK, devops.JenkinsCredential{}))
R
runzexia 已提交
214 215 216

	webservice.Route(webservice.GET("/devops/{devops}/credentials").
		To(devopsapi.GetDevOpsProjectCredentialsHandler).
R
Ray Zhou 已提交
217
		Doc("Get all credentials of the specified DevOps project").
R
runzexia 已提交
218
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectCredentialTag}).
R
Ray Zhou 已提交
219
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
runzexia 已提交
220
		Returns(http.StatusOK, RespOK, []devops.JenkinsCredential{}))
S
sunzhu 已提交
221

222 223
	// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}").
224
		To(devopsapi.GetPipeline).
R
runzexia 已提交
225
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
226 227
		Doc("Get the specified pipeline of the DevOps project").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
228
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
runzexia 已提交
229
		Returns(http.StatusOK, RespOK, devops.Pipeline{}).
Z
Zhuxiaoyang 已提交
230
		Writes(devops.Pipeline{}))
S
sunzhu 已提交
231 232

	// match Jenkisn api: "jenkins_api/blue/rest/search"
233
	webservice.Route(webservice.GET("/search").
234
		To(devopsapi.SearchPipelines).
R
runzexia 已提交
235
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
runzexia 已提交
236
		Doc("Search DevOps resource. More info: https://github.com/jenkinsci/blueocean-plugin/tree/master/blueocean-rest#get-pipelines-across-organization").
S
soulseen 已提交
237
		Param(webservice.QueryParameter("q", "query pipelines, condition for filtering.").
R
runzexia 已提交
238
			Required(true).
S
soulseen 已提交
239
			DataFormat("q=%s")).
R
runzexia 已提交
240
		Param(webservice.QueryParameter("filter", "Filter some types of jobs. e.g. no-folder,will not get a job of type folder").
S
soulseen 已提交
241 242
			Required(false).
			DataFormat("filter=%s")).
R
Ray Zhou 已提交
243
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
S
soulseen 已提交
244 245
			Required(false).
			DataFormat("start=%d")).
S
soulseen 已提交
246
		Param(webservice.QueryParameter("limit", "the limit item count of the search.").
S
soulseen 已提交
247
			Required(false).
Z
Zhuxiaoyang 已提交
248
			DataFormat("limit=%d")).
R
runzexia 已提交
249
		Returns(http.StatusOK, RespOK, []devops.Pipeline{}).
Z
Zhuxiaoyang 已提交
250
		Writes([]devops.Pipeline{}))
S
sunzhu 已提交
251

252 253
	// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs").
254
		To(devopsapi.SearchPipelineRuns).
R
runzexia 已提交
255
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
256
		Doc("Get all runs of the specified pipeline").
257
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
258
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
R
Ray Zhou 已提交
259
		Param(webservice.QueryParameter("start", "the item number that the search starts from").
S
soulseen 已提交
260 261
			Required(false).
			DataFormat("start=%d")).
R
Ray Zhou 已提交
262
		Param(webservice.QueryParameter("limit", "the limit item count of the search").
S
soulseen 已提交
263
			Required(false).
Z
Zhuxiaoyang 已提交
264
			DataFormat("limit=%d")).
R
runzexia 已提交
265 266 267
		Param(webservice.QueryParameter("branch", "the name of branch, same as repository branch, will be filtered by branch.").
			Required(false).
			DataFormat("branch=%s")).
Z
Zhuxiaoyang 已提交
268 269
		Returns(http.StatusOK, RespOK, []devops.BranchPipelineRun{}).
		Writes([]devops.BranchPipelineRun{}))
S
sunzhu 已提交
270

271 272
	// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}").
Z
Zhuxiaoyang 已提交
273
		To(devopsapi.GetBranchPipelineRun).
R
runzexia 已提交
274
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
275
		Doc("(MultiBranchesPipeline) Get all runs in the specified branch").
S
soulseen 已提交
276
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
277
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
278
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
279
		Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")).
Z
Zhuxiaoyang 已提交
280 281
		Returns(http.StatusOK, RespOK, devops.BranchPipelineRun{}).
		Writes(devops.BranchPipelineRun{}))
S
sunzhu 已提交
282

283 284
	// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/nodes"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes").
Z
Zhuxiaoyang 已提交
285
		To(devopsapi.GetPipelineRunNodesbyBranch).
R
runzexia 已提交
286
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
287
		Doc("(MultiBranchesPipeline) Get run nodes.").
S
soulseen 已提交
288
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
289
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
290
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
291
		Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")).
S
soulseen 已提交
292
		Param(webservice.QueryParameter("limit", "the limit item count of the search.").
S
sunzhu 已提交
293 294
			Required(false).
			DataFormat("limit=%d").
Z
Zhuxiaoyang 已提交
295
			DefaultValue("limit=10000")).
Z
Zhuxiaoyang 已提交
296 297
		Returns(http.StatusOK, RespOK, []devops.BranchPipelineRunNodes{}).
		Writes([]devops.BranchPipelineRunNodes{}))
S
sunzhu 已提交
298

299 300
	// match "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}/log/?start=0"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}/log").
Z
Zhuxiaoyang 已提交
301
		To(devopsapi.GetBranchStepLog).
R
runzexia 已提交
302
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
303
		Doc("(MultiBranchesPipeline) Get the step logs in the specified pipeline activity.").
Z
Zhuxiaoyang 已提交
304
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
305
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
306
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
307
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
308
		Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")).
R
Ray Zhou 已提交
309 310 311
		Param(webservice.PathParameter("node", "pipeline node id, the stage in pipeline.")).
		Param(webservice.PathParameter("step", "pipeline step id, the step in pipeline.")).
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
R
runzexia 已提交
312
			Required(false).
S
sunzhu 已提交
313 314 315
			DataFormat("start=%d").
			DefaultValue("start=0")))

316 317
	// match "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/nodes/{node}/steps/{step}/log/?start=0"
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}/log").
Z
Zhuxiaoyang 已提交
318
		To(devopsapi.GetStepLog).
R
runzexia 已提交
319
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
Z
Zhuxiaoyang 已提交
320 321
		Doc("Get pipelines step log.").
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
322
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
323
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
324 325 326
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
		Param(webservice.PathParameter("node", "pipeline node ID, the stage in pipeline.")).
		Param(webservice.PathParameter("step", "pipeline step ID, the step in pipeline.")).
R
Ray Zhou 已提交
327
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
R
runzexia 已提交
328
			Required(false).
Z
Zhuxiaoyang 已提交
329 330 331
			DataFormat("start=%d").
			DefaultValue("start=0")))

S
soulseen 已提交
332
	// match "/blue/rest/organizations/jenkins/scm/github/validate/"
333
	webservice.Route(webservice.POST("/scms/{scm}/verify").
334
		To(devopsapi.Validate).
R
runzexia 已提交
335
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
R
Ray Zhou 已提交
336
		Doc("Validate the access token of the specified source configuration management (SCM) such as Github").
R
Ray Zhou 已提交
337
		Param(webservice.PathParameter("scm", "the ID of the source configuration management (SCM).")).
R
runzexia 已提交
338
		Returns(http.StatusOK, RespOK, devops.Validates{}).
Z
Zhuxiaoyang 已提交
339
		Writes(devops.Validates{}))
S
soulseen 已提交
340

341 342
	// match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/?credentialId=github"
	webservice.Route(webservice.GET("/scms/{scm}/organizations").
Z
Zhuxiaoyang 已提交
343
		To(devopsapi.GetSCMOrg).
R
runzexia 已提交
344
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
S
soulseen 已提交
345
		Doc("List all organizations of the specified source configuration management (SCM) such as Github.").
R
Ray Zhou 已提交
346 347
		Param(webservice.PathParameter("scm", "the ID of the source configuration management (SCM).")).
		Param(webservice.QueryParameter("credentialId", "credential ID for source configuration management (SCM).").
Z
Zhuxiaoyang 已提交
348
			Required(true).
R
runzexia 已提交
349
			DataFormat("credentialId=%s")).
R
runzexia 已提交
350
		Returns(http.StatusOK, RespOK, []devops.SCMOrg{}).
Z
Zhuxiaoyang 已提交
351 352
		Writes([]devops.SCMOrg{}))

353 354
	// match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/{organization}/repositories/?credentialId=&pageNumber&pageSize="
	webservice.Route(webservice.GET("/scms/{scm}/organizations/{organization}/repositories").
Z
Zhuxiaoyang 已提交
355
		To(devopsapi.GetOrgRepo).
R
runzexia 已提交
356
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsScmTag}).
S
soulseen 已提交
357
		Doc("List all repositories in the specified organization.").
R
Ray Zhou 已提交
358 359 360
		Param(webservice.PathParameter("scm", "The ID of the source configuration management (SCM).")).
		Param(webservice.PathParameter("organization", "organization ID, such as github username.")).
		Param(webservice.QueryParameter("credentialId", "credential ID for SCM.").
Z
Zhuxiaoyang 已提交
361
			Required(true).
R
runzexia 已提交
362
			DataFormat("credentialId=%s")).
S
soulseen 已提交
363
		Param(webservice.QueryParameter("pageNumber", "page number.").
Z
Zhuxiaoyang 已提交
364 365
			Required(true).
			DataFormat("pageNumber=%d")).
S
soulseen 已提交
366
		Param(webservice.QueryParameter("pageSize", "the item count of one page.").
Z
Zhuxiaoyang 已提交
367 368
			Required(true).
			DataFormat("pageSize=%d")).
R
runzexia 已提交
369
		Returns(http.StatusOK, RespOK, []devops.OrgRepo{}).
Z
Zhuxiaoyang 已提交
370 371
		Writes([]devops.OrgRepo{}))

372 373
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/stop/
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/stop").
Z
Zhuxiaoyang 已提交
374
		To(devopsapi.StopBranchPipeline).
R
runzexia 已提交
375
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
376
		Doc("(MultiBranchesPipeline) Stop the specified pipeline of the DevOps project.").
S
soulseen 已提交
377
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
378
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
379
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
380
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
S
soulseen 已提交
381
		Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep.").
Z
Zhuxiaoyang 已提交
382 383 384
			Required(false).
			DataFormat("blocking=%t").
			DefaultValue("blocking=false")).
S
soulseen 已提交
385
		Param(webservice.QueryParameter("timeOutInSecs", "the time of stop and between each retries sleep.").
Z
Zhuxiaoyang 已提交
386 387 388
			Required(false).
			DataFormat("timeOutInSecs=%d").
			DefaultValue("timeOutInSecs=10")).
R
runzexia 已提交
389
		Returns(http.StatusOK, RespOK, devops.StopPipe{}).
Z
Zhuxiaoyang 已提交
390 391
		Writes(devops.StopPipe{}))

392 393
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/stop/
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/stop").
Z
Zhuxiaoyang 已提交
394
		To(devopsapi.StopPipeline).
R
runzexia 已提交
395
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
396 397
		Doc("Stop pipeline").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
398
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
399
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
S
soulseen 已提交
400
		Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep.").
Z
Zhuxiaoyang 已提交
401 402 403
			Required(false).
			DataFormat("blocking=%t").
			DefaultValue("blocking=false")).
S
soulseen 已提交
404
		Param(webservice.QueryParameter("timeOutInSecs", "the time of stop and between each retries sleep.").
Z
Zhuxiaoyang 已提交
405 406 407 408 409 410
			Required(false).
			DataFormat("timeOutInSecs=%d").
			DefaultValue("timeOutInSecs=10")).
		Returns(http.StatusOK, RespOK, devops.StopPipe{}).
		Writes(devops.StopPipe{}))

411 412
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/Replay/
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/replay").
Z
Zhuxiaoyang 已提交
413
		To(devopsapi.ReplayBranchPipeline).
R
runzexia 已提交
414
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
415
		Doc("(MultiBranchesPipeline) Replay the specified pipeline of the DevOps project").
S
soulseen 已提交
416
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
417
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
418
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
419
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
runzexia 已提交
420
		Returns(http.StatusOK, RespOK, devops.ReplayPipe{}).
Z
Zhuxiaoyang 已提交
421 422
		Writes(devops.ReplayPipe{}))

423 424
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/Replay/
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/replay").
Z
Zhuxiaoyang 已提交
425
		To(devopsapi.ReplayPipeline).
R
runzexia 已提交
426
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
Z
Zhuxiaoyang 已提交
427
		Doc("Replay pipeline").
S
soulseen 已提交
428
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
429
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
430
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
Z
Zhuxiaoyang 已提交
431 432 433
		Returns(http.StatusOK, RespOK, devops.ReplayPipe{}).
		Writes(devops.ReplayPipe{}))

434 435
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/log/?start=0
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/log").
Z
Zhuxiaoyang 已提交
436
		To(devopsapi.GetBranchRunLog).
R
runzexia 已提交
437
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
438
		Doc("(MultiBranchesPipeline) Get run logs of the specified pipeline activity.").
Z
Zhuxiaoyang 已提交
439
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
440
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
441
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
442
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
443
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
Ray Zhou 已提交
444
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
R
runzexia 已提交
445
			Required(false).
Z
Zhuxiaoyang 已提交
446 447 448
			DataFormat("start=%d").
			DefaultValue("start=0")))

449 450
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/log/?start=0
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/log").
Z
Zhuxiaoyang 已提交
451
		To(devopsapi.GetRunLog).
R
runzexia 已提交
452
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
453
		Doc("Get run logs of the specified pipeline activity.").
Z
Zhuxiaoyang 已提交
454
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
455
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
456
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
457
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
Ray Zhou 已提交
458
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
R
runzexia 已提交
459
			Required(false).
Z
Zhuxiaoyang 已提交
460 461 462
			DataFormat("start=%d").
			DefaultValue("start=0")))

463 464
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/artifacts
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/artifacts").
Z
Zhuxiaoyang 已提交
465
		To(devopsapi.GetBranchArtifacts).
R
runzexia 已提交
466
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
467
		Doc("(MultiBranchesPipeline) Get all artifacts generated from the specified run of the pipeline branch.").
S
soulseen 已提交
468
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
469
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
470
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
471
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
Ray Zhou 已提交
472
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
Z
Zhuxiaoyang 已提交
473 474
			Required(false).
			DataFormat("start=%d")).
S
soulseen 已提交
475
		Param(webservice.QueryParameter("limit", "the limit item count of the search.").
Z
Zhuxiaoyang 已提交
476 477 478 479 480
			Required(false).
			DataFormat("limit=%d")).
		Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}).
		Writes([]devops.Artifacts{}))

481 482
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/artifacts
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/artifacts").
Z
Zhuxiaoyang 已提交
483
		To(devopsapi.GetArtifacts).
R
runzexia 已提交
484
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
485 486
		Doc("Get all artifacts in the specified pipeline.").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
487
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
488
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
Ray Zhou 已提交
489
		Param(webservice.QueryParameter("start", "the item number that the search starts from.").
Z
Zhuxiaoyang 已提交
490 491
			Required(false).
			DataFormat("start=%d")).
S
soulseen 已提交
492
		Param(webservice.QueryParameter("limit", "the limit item count of the search.").
Z
Zhuxiaoyang 已提交
493 494 495 496 497
			Required(false).
			DataFormat("limit=%d")).
		Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}).
		Writes([]devops.Artifacts{}))

498 499
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/?filter=&start&limit=
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches").
Z
Zhuxiaoyang 已提交
500
		To(devopsapi.GetPipeBranch).
R
runzexia 已提交
501
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
502 503
		Doc("(MultiBranchesPipeline) Get all branches in the specified pipeline.").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
504
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
runzexia 已提交
505
		Param(webservice.QueryParameter("filter", "filter remote scm. e.g. origin").
R
runzexia 已提交
506
			Required(false).
Z
Zhuxiaoyang 已提交
507
			DataFormat("filter=%s")).
R
runzexia 已提交
508
		Param(webservice.QueryParameter("start", "the count of branches start.").
R
runzexia 已提交
509 510
			Required(false).
			DataFormat("start=%d").DefaultValue("start=0")).
R
runzexia 已提交
511
		Param(webservice.QueryParameter("limit", "the count of branches limit.").
R
runzexia 已提交
512 513
			Required(false).
			DataFormat("limit=%d").DefaultValue("limit=100")).
R
runzexia 已提交
514
		Returns(http.StatusOK, RespOK, []devops.PipeBranch{}).
Z
Zhuxiaoyang 已提交
515 516
		Writes([]devops.PipeBranch{}))

517 518
	// /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}").
S
soulseen 已提交
519
		To(devopsapi.SubmitBranchInputStep).
R
runzexia 已提交
520
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
521 522
		Doc("(MultiBranchesPipeline) Proceed or Break the paused pipeline which waiting for user input.").
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
523
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
524
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
525 526 527
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
		Param(webservice.PathParameter("node", "pipeline node ID, the stage in pipeline.")).
		Param(webservice.PathParameter("step", "pipeline step ID, the step in pipeline.")).
R
Ray Zhou 已提交
528 529
		Reads(devops.CheckPlayload{}).
		Produces("text/plain; charset=utf-8"))
530 531 532

	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}").
S
soulseen 已提交
533
		To(devopsapi.SubmitInputStep).
R
runzexia 已提交
534
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
535
		Doc("Proceed or Break the paused pipeline which is waiting for user input.").
Z
Zhuxiaoyang 已提交
536 537
		Reads(devops.CheckPlayload{}).
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
538
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
539
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
540 541 542
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
		Param(webservice.PathParameter("node", "pipeline node ID, the stage in pipeline.")).
		Param(webservice.PathParameter("step", "pipeline step ID")))
Z
Zhuxiaoyang 已提交
543

Z
Zhuxiaoyang 已提交
544
	// match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText
545
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/consolelog").
Z
Zhuxiaoyang 已提交
546
		To(devopsapi.GetConsoleLog).
R
runzexia 已提交
547
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
548
		Doc("Get scan reponsitory logs in the specified pipeline.").
Z
Zhuxiaoyang 已提交
549
		Produces("text/plain; charset=utf-8").
S
soulseen 已提交
550
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
551
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")))
Z
Zhuxiaoyang 已提交
552

553 554
	// match /job/{devops}/job/{pipeline}/build?delay=0
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/scan").
Z
Zhuxiaoyang 已提交
555
		To(devopsapi.ScanBranch).
R
runzexia 已提交
556
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
557
		Doc("Scan remote Repository, Start a build if have new branch.").
Z
Zhuxiaoyang 已提交
558
		Produces("text/html; charset=utf-8").
S
soulseen 已提交
559
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
560
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
561
		Param(webservice.QueryParameter("delay", "the delay time to scan").
S
soulseen 已提交
562
			Required(false).
Z
Zhuxiaoyang 已提交
563 564
			DataFormat("delay=%d")))

565
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{}/runs/
R
runzexia 已提交
566
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs").
Z
Zhuxiaoyang 已提交
567
		To(devopsapi.RunBranchPipeline).
R
runzexia 已提交
568
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
569
		Doc("(MultiBranchesPipeline) Run the specified pipeline of the DevOps project.").
Z
Zhuxiaoyang 已提交
570
		Reads(devops.RunPayload{}).
S
soulseen 已提交
571
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
572
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
573
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
runzexia 已提交
574
		Returns(http.StatusOK, RespOK, devops.QueuedBlueRun{}).
Z
Zhuxiaoyang 已提交
575
		Writes(devops.QueuedBlueRun{}))
Z
Zhuxiaoyang 已提交
576

577
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/
R
runzexia 已提交
578
	webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs").
Z
Zhuxiaoyang 已提交
579
		To(devopsapi.RunPipeline).
R
runzexia 已提交
580
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
Z
Zhuxiaoyang 已提交
581 582
		Doc("Run pipeline.").
		Reads(devops.RunPayload{}).
S
soulseen 已提交
583
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
584
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
Z
Zhuxiaoyang 已提交
585 586
		Returns(http.StatusOK, RespOK, devops.QueuedBlueRun{}).
		Writes(devops.QueuedBlueRun{}))
Z
Zhuxiaoyang 已提交
587 588

	// match /crumbIssuer/api/json/
589
	webservice.Route(webservice.GET("/crumbissuer").
Z
Zhuxiaoyang 已提交
590
		To(devopsapi.GetCrumb).
R
runzexia 已提交
591
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
runzexia 已提交
592
		Doc("Get crumb issuer. A CrumbIssuer represents an algorithm to generate a nonce value, known as a crumb, to counter cross site request forgery exploits. Crumbs are typically hashes incorporating information that uniquely identifies an agent that sends a request, along with a guarded secret so that the crumb value cannot be forged by a third party.").
R
runzexia 已提交
593
		Returns(http.StatusOK, RespOK, devops.Crumb{}).
Z
Zhuxiaoyang 已提交
594
		Writes(devops.Crumb{}))
S
soulseen 已提交
595

596 597 598 599 600 601 602 603 604 605 606
	// TODO are not used in this version. will be added in 2.1.0
	//// 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(devops.ReqScript{}).
	//	Returns(http.StatusOK, RespOK, devops.CheckScript{}).
	//	Writes(devops.CheckScript{}))
Z
Zhuxiaoyang 已提交
607 608

	// match /job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec
609 610 611 612 613 614 615 616 617 618 619 620 621 622
	//webservice.Route(webservice.GET("/devops/check/cron").
	//	To(devopsapi.CheckCron).
	//	Metadata(restfulspec.KeyOpenAPITags, tags).
	//	Produces("application/json", "charset=utf-8").
	//	Doc("Check cron script compile.").
	//	Param(webservice.QueryParameter("value", "string of cron script.").
	//		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/{devops}/{pipeline}/runs/{run}/
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}").
Z
Zhuxiaoyang 已提交
623
		To(devopsapi.GetPipelineRun).
R
runzexia 已提交
624
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
625
		Doc("Get all activities in the specified pipeline.").
626
		Param(webservice.PathParameter("devops", "the name of devops project")).
627
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
628
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
Z
Zhuxiaoyang 已提交
629 630 631
		Returns(http.StatusOK, RespOK, devops.PipelineRun{}).
		Writes(devops.PipelineRun{}))

632 633
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}").
Z
Zhuxiaoyang 已提交
634
		To(devopsapi.GetBranchPipeline).
R
runzexia 已提交
635
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
636
		Doc("(MultiBranchesPipeline) Get all activities in the specified pipeline.").
637
		Param(webservice.PathParameter("devops", "the name of devops project")).
638
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
639
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch")).
Z
Zhuxiaoyang 已提交
640 641
		Returns(http.StatusOK, RespOK, devops.BranchPipeline{}).
		Writes(devops.BranchPipeline{}))
Z
Zhuxiaoyang 已提交
642

643 644
	// match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/?limit=10000
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes").
Z
Zhuxiaoyang 已提交
645
		To(devopsapi.GetPipelineRunNodes).
R
runzexia 已提交
646
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
647
		Doc("Get all nodes in the specified activity. node is the stage in the pipeline task").
648
		Param(webservice.PathParameter("devops", "the name of devops project")).
649
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
650
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build")).
Z
Zhuxiaoyang 已提交
651 652
		Returns(http.StatusOK, RespOK, []devops.PipelineRunNodes{}).
		Writes([]devops.PipelineRunNodes{}))
Z
Zhuxiaoyang 已提交
653 654

	// match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit=
655
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps").
Z
Zhuxiaoyang 已提交
656
		To(devopsapi.GetBranchNodeSteps).
R
runzexia 已提交
657
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
658
		Doc("(MultiBranchesPipeline) Get all steps in the specified node.").
659
		Param(webservice.PathParameter("devops", "the name of devops project")).
660
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
661
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
662 663
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
		Param(webservice.PathParameter("node", "pipeline node ID, the stage in pipeline.")).
R
runzexia 已提交
664
		Returns(http.StatusOK, RespOK, []devops.NodeSteps{}).
Z
Zhuxiaoyang 已提交
665 666
		Writes([]devops.NodeSteps{}))

Z
Zhuxiaoyang 已提交
667
	// match /blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?limit=
668
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps").
Z
Zhuxiaoyang 已提交
669
		To(devopsapi.GetNodeSteps).
R
runzexia 已提交
670
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
S
soulseen 已提交
671
		Doc("Get all steps in the specified node.").
672
		Param(webservice.PathParameter("devops", "the name of devops project")).
673
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
674 675
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build")).
		Param(webservice.PathParameter("node", "pipeline node ID, the stage in pipeline.")).
R
runzexia 已提交
676
		Returns(http.StatusOK, RespOK, []devops.NodeSteps{}).
Z
Zhuxiaoyang 已提交
677 678
		Writes([]devops.NodeSteps{}))

Z
Zhuxiaoyang 已提交
679
	// match /pipeline-model-converter/toJenkinsfile
680
	webservice.Route(webservice.POST("/tojenkinsfile").
Z
Zhuxiaoyang 已提交
681
		To(devopsapi.ToJenkinsfile).
R
runzexia 已提交
682
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsfileTag}).
Z
Zhuxiaoyang 已提交
683 684
		Consumes("application/x-www-form-urlencoded").
		Produces("application/json", "charset=utf-8").
S
soulseen 已提交
685
		Doc("Convert json to jenkinsfile format.").
Z
Zhuxiaoyang 已提交
686
		Reads(devops.ReqJson{}).
R
runzexia 已提交
687
		Returns(http.StatusOK, RespOK, devops.ResJenkinsfile{}).
Z
Zhuxiaoyang 已提交
688 689 690
		Writes(devops.ResJenkinsfile{}))

	// match /pipeline-model-converter/toJson
691
	webservice.Route(webservice.POST("/tojson").
Z
Zhuxiaoyang 已提交
692
		To(devopsapi.ToJson).
R
runzexia 已提交
693
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsfileTag}).
Z
Zhuxiaoyang 已提交
694 695
		Consumes("application/x-www-form-urlencoded").
		Produces("application/json", "charset=utf-8").
S
soulseen 已提交
696
		Doc("Convert jenkinsfile to json format. Usually the frontend uses json to show or edit pipeline").
Z
Zhuxiaoyang 已提交
697
		Reads(devops.ReqJenkinsfile{}).
R
runzexia 已提交
698
		Returns(http.StatusOK, RespOK, devops.ResJson{}).
Z
Zhuxiaoyang 已提交
699 700
		Writes(devops.ResJson{}))

Z
Zhuxiaoyang 已提交
701
	// match /git/notifyCommit/?url=
702
	webservice.Route(webservice.GET("/webhook/git").
Z
Zhuxiaoyang 已提交
703
		To(devopsapi.GetNotifyCommit).
R
runzexia 已提交
704
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsWebhookTag}).
705
		Doc("Get commit notification by HTTP GET method. Git webhook will request here.").
Z
Zhuxiaoyang 已提交
706
		Produces("text/plain; charset=utf-8").
R
Ray Zhou 已提交
707
		Param(webservice.QueryParameter("url", "Git url").
Z
Zhuxiaoyang 已提交
708 709 710 711
			Required(true).
			DataFormat("url=%s")))

	// Gitlab or some other scm managers can only use HTTP method. match /git/notifyCommit/?url=
712
	webservice.Route(webservice.POST("/webhook/git").
R
runzexia 已提交
713
		To(devopsapi.PostNotifyCommit).
R
runzexia 已提交
714
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsWebhookTag}).
715
		Doc("Get commit notification by HTTP POST method. Git webhook will request here.").
Z
Zhuxiaoyang 已提交
716 717
		Consumes("application/json").
		Produces("text/plain; charset=utf-8").
R
Ray Zhou 已提交
718
		Param(webservice.QueryParameter("url", "Git url").
Z
Zhuxiaoyang 已提交
719 720 721
			Required(true).
			DataFormat("url=%s")))

722
	webservice.Route(webservice.POST("/webhook/github").
Z
Zhuxiaoyang 已提交
723
		To(devopsapi.GithubWebhook).
R
runzexia 已提交
724
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsWebhookTag}).
725
		Doc("Get commit notification. Github webhook will request here."))
Z
Zhuxiaoyang 已提交
726

Z
Zhuxiaoyang 已提交
727
	// in scm get all steps in nodes.
728
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodesdetail").
Z
Zhuxiaoyang 已提交
729
		To(devopsapi.GetBranchNodesDetail).
R
runzexia 已提交
730
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
731
		Doc("(MultiBranchesPipeline) Get steps details in an activity node. For a node, the steps which is defined inside the node.").
S
soulseen 已提交
732
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
733
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
734
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
735
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
runzexia 已提交
736
		Returns(http.StatusOK, RespOK, []devops.NodesDetail{}).
Z
Zhuxiaoyang 已提交
737 738 739
		Writes(devops.NodesDetail{}))

	// out of scm get all steps in nodes.
740
	webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodesdetail").
Z
Zhuxiaoyang 已提交
741
		To(devopsapi.GetNodesDetail).
R
runzexia 已提交
742
		Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
R
Ray Zhou 已提交
743
		Doc("Get steps details inside a activity node. For a node, the steps which defined inside the node.").
S
soulseen 已提交
744
		Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
745
		Param(webservice.PathParameter("pipeline", "the name of the CI/CD pipeline")).
R
Ray Zhou 已提交
746
		Param(webservice.PathParameter("branch", "the name of branch, same as repository branch.")).
R
Ray Zhou 已提交
747
		Param(webservice.PathParameter("run", "pipeline run ID, the unique ID for a pipeline once build.")).
R
runzexia 已提交
748
		Returns(http.StatusOK, RespOK, []devops.NodesDetail{}).
Z
Zhuxiaoyang 已提交
749 750
		Writes(devops.NodesDetail{}))

S
sunzhu 已提交
751 752 753 754
	c.Add(webservice)

	return nil
}