This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new b9b0373d2 feat(webhook): Issues and PullRequests new endpoint by 
projectName (#8915)
b9b0373d2 is described below

commit b9b0373d2462c0c2bbab631d29297b9aa242f093
Author: Jon Vaughan <[email protected]>
AuthorDate: Thu Jun 18 06:59:00 2026 +0100

    feat(webhook): Issues and PullRequests new endpoint by projectName (#8915)
    
    * feat(webhook): Issues and PullRequests new endpoint by projectName
    
    * ci: fix invalid push
    
    * ci: fix lint issues
    
    * ci: add missing lint.
---
 backend/plugins/webhook/api/deployments.go   |  6 +++---
 backend/plugins/webhook/api/issues.go        | 25 +++++++++++++++++++++++--
 backend/plugins/webhook/api/pull_requests.go | 25 +++++++++++++++++++++++--
 backend/plugins/webhook/impl/impl.go         |  6 ++++++
 4 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/backend/plugins/webhook/api/deployments.go 
b/backend/plugins/webhook/api/deployments.go
index fc2a463ef..b65ca9d08 100644
--- a/backend/plugins/webhook/api/deployments.go
+++ b/backend/plugins/webhook/api/deployments.go
@@ -126,7 +126,7 @@ func PostDeploymentsByName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceO
 // @Router /projects/:projectName/deployments [POST]
 func PostDeploymentsByProjectName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
        // find or create the connection for this project
-       connection, err, shouldReturn := getOrCreateConnection(input)
+       connection, err, shouldReturn := getOrCreateConnection(input, 
"deployments")
        if shouldReturn {
                return nil, err
        }
@@ -134,10 +134,10 @@ func PostDeploymentsByProjectName(input 
*plugin.ApiResourceInput) (*plugin.ApiRe
        return postDeployments(input, connection, err)
 }
 
-func getOrCreateConnection(input *plugin.ApiResourceInput) 
(*models.WebhookConnection, errors.Error, bool) {
+func getOrCreateConnection(input *plugin.ApiResourceInput, webhookSuffix 
string) (*models.WebhookConnection, errors.Error, bool) {
        connection := &models.WebhookConnection{}
        projectName := input.Params["projectName"]
-       webhookName := fmt.Sprintf("%s_deployments", projectName)
+       webhookName := fmt.Sprintf("%s_%s", projectName, webhookSuffix)
        err := findByProjectName(connection, input.Params, pluginName, 
webhookName)
        dal := basicRes.GetDal()
        if err != nil {
diff --git a/backend/plugins/webhook/api/issues.go 
b/backend/plugins/webhook/api/issues.go
index f91a17166..0402be164 100644
--- a/backend/plugins/webhook/api/issues.go
+++ b/backend/plugins/webhook/api/issues.go
@@ -19,11 +19,12 @@ package api
 
 import (
        "fmt"
-       "github.com/apache/incubator-devlake/core/log"
-       "github.com/apache/incubator-devlake/helpers/dbhelper"
        "net/http"
        "time"
 
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/helpers/dbhelper"
+
        "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/models/domainlayer"
@@ -112,6 +113,26 @@ func PostIssueByName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        return postIssue(input, err, connection)
 }
 
+// PostIssuesByProjectName
+// @Summary create issue by project name
+// @Description Create issue by project name. The webhook connection will be 
created automatically if it does not exist.<br/>
+// @Description example: {"url":"","issue_key":"DLK-1234","title":"a feature 
from 
DLK","description":"","epic_key":"","type":"BUG","status":"TODO","original_status":"created","story_point":0,"resolution_date":null,"created_date":"2020-01-01T12:00:00+00:00","updated_date":null,"lead_time_minutes":0,"parent_issue_key":"DLK-1200","priority":"","original_estimate_minutes":0,"time_spent_minutes":0,"time_remaining_minutes":0,"creator_id":"user1131","creator_name":"Nick
 name 1","assignee_id":"u [...]
+// @Tags plugins/webhook
+// @Param body body WebhookIssueRequest true "json body"
+// @Success 200  {string} noResponse ""
+// @Failure 400  {string} errcode.Error "Bad Request"
+// @Failure 403  {string} errcode.Error "Forbidden"
+// @Failure 500  {string} errcode.Error "Internal Error"
+// @Router /projects/:projectName/issues [POST]
+func PostIssuesByProjectName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       // find or create the connection for this project
+       connection, err, shouldReturn := getOrCreateConnection(input, "issues")
+       if shouldReturn {
+               return nil, err
+       }
+       return postIssue(input, err, connection)
+}
+
 func postIssue(input *plugin.ApiResourceInput, err errors.Error, connection 
*models.WebhookConnection) (*plugin.ApiResourceOutput, errors.Error) {
        if err != nil {
                return nil, err
diff --git a/backend/plugins/webhook/api/pull_requests.go 
b/backend/plugins/webhook/api/pull_requests.go
index a01bb6c4d..50fcee5c4 100644
--- a/backend/plugins/webhook/api/pull_requests.go
+++ b/backend/plugins/webhook/api/pull_requests.go
@@ -77,7 +77,7 @@ type WebhookPullRequestReq struct {
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 403  {string} errcode.Error "Forbidden"
 // @Failure 500  {string} errcode.Error "Internal Error"
-// @Router /plugins/webhook/connections/:connectionId/pullrequests [POST]
+// @Router /plugins/webhook/connections/:connectionId/pull_requests [POST]
 func PostPullRequests(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
        connection := &models.WebhookConnection{}
        err := connectionHelper.First(connection, input.Params)
@@ -96,7 +96,7 @@ func PostPullRequests(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 403  {string} errcode.Error "Forbidden"
 // @Failure 500  {string} errcode.Error "Internal Error"
-// @Router /plugins/webhook/connections/by-name/:connectionName/pullrequests 
[POST]
+// @Router /plugins/webhook/connections/by-name/:connectionName/pull_requests 
[POST]
 func PostPullRequestsByName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
        connection := &models.WebhookConnection{}
        err := connectionHelper.FirstByName(connection, input.Params)
@@ -104,6 +104,27 @@ func PostPullRequestsByName(input 
*plugin.ApiResourceInput) (*plugin.ApiResource
        return postPullRequests(input, connection, err)
 }
 
+// PostPullRequestsByProjectName
+// @Summary create pull requests by project name
+// @Description Create pull request by project name. The webhook connection 
will be created automatically if it does not exist.<br/>
+// @Description example1: {"id": "pr1","baseRepoId": "webhook:1","headRepoId": 
"repo_fork1","status": "MERGED","originalStatus": "OPEN","displayTitle": 
"Feature: Add new functionality","description": "This PR adds new 
features","url": "https://github.com/org/repo/pull/1","authorName": 
"johndoe","authorId": "johnd123","mergedByName": "janedoe","mergedById": 
"janed123","parentPrId": "","pullRequestKey": 1,"createdDate": 
"2025-02-20T16:17:36Z","mergedDate": "2025-02-20T17:17:36Z","closedDat [...]
+// @Description "baseRepoId" should be equal to "webhook:{connectionId}" for 
consistent DORA calculations
+// @Tags plugins/webhook
+// @Param body body WebhookPullRequestReq 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/pull_requests [POST]
+func PostPullRequestsByProjectName(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       connection, err, shouldReturn := getOrCreateConnection(input, 
"pull_requests")
+       if shouldReturn {
+               return nil, err
+       }
+
+       return postPullRequests(input, connection, err)
+}
+
 func postPullRequests(input *plugin.ApiResourceInput, connection 
*models.WebhookConnection, err errors.Error) (*plugin.ApiResourceOutput, 
errors.Error) {
        if err != nil {
                return nil, err
diff --git a/backend/plugins/webhook/impl/impl.go 
b/backend/plugins/webhook/impl/impl.go
index 9a6768358..93f2ac5e0 100644
--- a/backend/plugins/webhook/impl/impl.go
+++ b/backend/plugins/webhook/impl/impl.go
@@ -131,5 +131,11 @@ func (p Webhook) ApiResources() 
map[string]map[string]plugin.ApiResourceHandler
                "projects/:projectName/deployments": {
                        "POST": api.PostDeploymentsByProjectName,
                },
+               "projects/:projectName/issues": {
+                       "POST": api.PostIssuesByProjectName,
+               },
+               "projects/:projectName/pull_requests": {
+                       "POST": api.PostPullRequestsByProjectName,
+               },
        }
 }

Reply via email to