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

abeizn pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v1.0 by this push:
     new 914d9249c fix(webhook): rollback database when webhook's name is same 
(#7778) (#7780)
914d9249c is described below

commit 914d9249c5d570dc93e7ddb495cddea75f213a9e
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 24 16:25:19 2024 +0800

    fix(webhook): rollback database when webhook's name is same (#7778) (#7780)
    
    * fix(webhook): rollback database when webhook's name is same
    
    * fix(webhook): update error messages
    
    Co-authored-by: Lynwee <[email protected]>
---
 backend/plugins/webhook/api/connection.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/backend/plugins/webhook/api/connection.go 
b/backend/plugins/webhook/api/connection.go
index f3c9e9116..acb8a76a5 100644
--- a/backend/plugins/webhook/api/connection.go
+++ b/backend/plugins/webhook/api/connection.go
@@ -21,6 +21,7 @@ import (
        "fmt"
        "net/http"
        "strconv"
+       "strings"
 
        "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
@@ -44,6 +45,12 @@ func PostConnections(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        tx := basicRes.GetDal().Begin()
        err := connectionHelper.CreateWithTx(tx, connection, input)
        if err != nil {
+               if err := tx.Rollback(); err != nil {
+                       logger.Error(err, "transaction Rollback")
+               }
+               if strings.Contains(err.Error(), "the connection name already 
exists (400)") {
+                       return nil, errors.BadInput.New(fmt.Sprintf("A webhook 
with name %s already exists.", connection.Name))
+               }
                return nil, err
        }
        logger.Info("connection: %+v", connection)

Reply via email to