d4x1 commented on code in PR #8611:
URL:
https://github.com/apache/incubator-devlake/pull/8611#discussion_r2573630842
##########
backend/plugins/webhook/impl/impl.go:
##########
@@ -128,5 +128,8 @@ func (p Webhook) ApiResources()
map[string]map[string]plugin.ApiResourceHandler
"connections/by-name/:connectionName/issue/:issueKey/close": {
"POST": api.CloseIssueByName,
},
+ "projects/:projectName/deployments": {
Review Comment:
I think `projects/by-name/:projectName/deployments` is better, just like
`onnections/by-name/***`.
##########
backend/plugins/webhook/api/deployments.go:
##########
@@ -109,6 +112,96 @@ func PostDeploymentsByName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceO
return postDeployments(input, connection, err)
}
+// PostDeploymentsByProjectName
+// @Summary create deployment by project name
+// @Description Create deployment pipeline by project name.<br/>
+// @Description example1:
{"repo_url":"devlake","commit_sha":"015e3d3b480e417aede5a1293bd61de9b0fd051d","start_time":"2020-01-01T12:00:00+00:00","end_time":"2020-01-01T12:59:59+00:00","environment":"PRODUCTION"}<br/>
+// @Description So we suggest request before task after deployment pipeline
finish.
+// @Description Both cicd_pipeline and cicd_task will be created
+// @Tags plugins/webhook
+// @Param body body WebhookDeploymentReq true "json body"
+// @Success 200
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 403 {string} errcode.Error "Forbidden"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /projects/:projectName/deployments [POST]
+func PostDeploymentsByProjectName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors.Error) {
+ // find or create the connection for this project
+ connection := &models.WebhookConnection{}
+ projectName := input.Params["projectName"]
+ webhookName := fmt.Sprintf("%s_deployments", projectName)
+ err := findByProjectName(connection, input.Params, pluginName,
webhookName)
+ if err != nil {
+ // if not found, we will attempt to create a new connection
+ // Use direct comparison against the package sentinel; only
treat other errors as fatal.
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
Review Comment:
Maybe we can use
`https://github.com/apache/incubator-devlake/blob/920bc624f1c04bc01e944410d413fa113ed25554/backend/impls/dalgorm/dalgorm.go#L490`
to keep a unified style.
##########
backend/plugins/webhook/api/deployments.go:
##########
@@ -109,6 +112,96 @@ func PostDeploymentsByName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceO
return postDeployments(input, connection, err)
}
+// PostDeploymentsByProjectName
+// @Summary create deployment by project name
+// @Description Create deployment pipeline by project name.<br/>
+// @Description example1:
{"repo_url":"devlake","commit_sha":"015e3d3b480e417aede5a1293bd61de9b0fd051d","start_time":"2020-01-01T12:00:00+00:00","end_time":"2020-01-01T12:59:59+00:00","environment":"PRODUCTION"}<br/>
+// @Description So we suggest request before task after deployment pipeline
finish.
+// @Description Both cicd_pipeline and cicd_task will be created
+// @Tags plugins/webhook
+// @Param body body WebhookDeploymentReq true "json body"
+// @Success 200
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 403 {string} errcode.Error "Forbidden"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /projects/:projectName/deployments [POST]
+func PostDeploymentsByProjectName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors.Error) {
+ // find or create the connection for this project
+ connection := &models.WebhookConnection{}
+ projectName := input.Params["projectName"]
+ webhookName := fmt.Sprintf("%s_deployments", projectName)
Review Comment:
According to previous discussion, I think this means current project's
`default(or missing) webhook connection`.
I prefer something that contains the `default` (or missing) meaning. We can
add more items later under the default webhook.
This is just an advice.
##########
backend/plugins/webhook/api/deployments.go:
##########
@@ -109,6 +112,96 @@ func PostDeploymentsByName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceO
return postDeployments(input, connection, err)
}
+// PostDeploymentsByProjectName
+// @Summary create deployment by project name
+// @Description Create deployment pipeline by project name.<br/>
+// @Description example1:
{"repo_url":"devlake","commit_sha":"015e3d3b480e417aede5a1293bd61de9b0fd051d","start_time":"2020-01-01T12:00:00+00:00","end_time":"2020-01-01T12:59:59+00:00","environment":"PRODUCTION"}<br/>
+// @Description So we suggest request before task after deployment pipeline
finish.
+// @Description Both cicd_pipeline and cicd_task will be created
+// @Tags plugins/webhook
+// @Param body body WebhookDeploymentReq true "json body"
+// @Success 200
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 403 {string} errcode.Error "Forbidden"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /projects/:projectName/deployments [POST]
+func PostDeploymentsByProjectName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors.Error) {
+ // find or create the connection for this project
+ connection := &models.WebhookConnection{}
+ projectName := input.Params["projectName"]
+ webhookName := fmt.Sprintf("%s_deployments", projectName)
+ err := findByProjectName(connection, input.Params, pluginName,
webhookName)
+ if err != nil {
+ // if not found, we will attempt to create a new connection
+ // Use direct comparison against the package sentinel; only
treat other errors as fatal.
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ logger.Error(err, "failed to find webhook connection
for project", "projectName", input.Params["projectName"])
+ return nil, err
+ }
+
+ // create the connection
+ logger.Debug("creating webhook connection for project %s",
input.Params["projectName"])
Review Comment:
Use `projectName` instead of `input.Params["projectName"]`.
##########
backend/plugins/webhook/api/deployments.go:
##########
@@ -109,6 +112,96 @@ func PostDeploymentsByName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceO
return postDeployments(input, connection, err)
}
+// PostDeploymentsByProjectName
+// @Summary create deployment by project name
+// @Description Create deployment pipeline by project name.<br/>
+// @Description example1:
{"repo_url":"devlake","commit_sha":"015e3d3b480e417aede5a1293bd61de9b0fd051d","start_time":"2020-01-01T12:00:00+00:00","end_time":"2020-01-01T12:59:59+00:00","environment":"PRODUCTION"}<br/>
+// @Description So we suggest request before task after deployment pipeline
finish.
+// @Description Both cicd_pipeline and cicd_task will be created
+// @Tags plugins/webhook
+// @Param body body WebhookDeploymentReq true "json body"
+// @Success 200
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 403 {string} errcode.Error "Forbidden"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /projects/:projectName/deployments [POST]
+func PostDeploymentsByProjectName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors.Error) {
Review Comment:
Try to make this handler looks simple and clear.
For example:
```golang
func PostDeploymentsByProjectName(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors.Error) {
GetOrCreateConnection
postDeployments
}
func GetOrCreateConnection(){
// part 1: check project's missing webhook connection, create or update.
// part 2: if the connection is created newly, updatte project's
blueprint.
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]