You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by gi...@apache.org on 2024/07/24 08:24:48 UTC

(incubator-devlake) branch release-v0.21-auto-cherry-pick-7778 created (now 6849ca0f6)

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

github-bot pushed a change to branch release-v0.21-auto-cherry-pick-7778
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


      at 6849ca0f6 fix(webhook): rollback database when webhook's name is same (#7778)

This branch includes the following new commits:

     new 6849ca0f6 fix(webhook): rollback database when webhook's name is same (#7778)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-devlake) 01/01: fix(webhook): rollback database when webhook's name is same (#7778)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch release-v0.21-auto-cherry-pick-7778
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 6849ca0f69964bc9f6a13637d98c4e45c9007105
Author: Lynwee <15...@qq.com>
AuthorDate: Wed Jul 24 16:24:29 2024 +0800

    fix(webhook): rollback database when webhook's name is same (#7778)
    
    * fix(webhook): rollback database when webhook's name is same
    
    * fix(webhook): update error messages
---
 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)