mieliespoor commented on code in PR #8611:
URL: 
https://github.com/apache/incubator-devlake/pull/8611#discussion_r2577852385


##########
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:
   Good catch. I only added the projectName variable later, so didn't spot this 
place to use it.



-- 
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]

Reply via email to