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

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


The following commit(s) were added to refs/heads/main by this push:
     new 1edd4c1d2 fix: sonarqube test connection can not effective (#7112)
1edd4c1d2 is described below

commit 1edd4c1d22b2359d239fc9bfc793dc1dddfbbb5d
Author: abeizn <[email protected]>
AuthorDate: Tue Mar 5 17:27:23 2024 +0800

    fix: sonarqube test connection can not effective (#7112)
    
    * fix: sonarqube test connection can not effective
    
    * fix: testConnection add check
---
 backend/plugins/sonarqube/api/connection_api.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/backend/plugins/sonarqube/api/connection_api.go 
b/backend/plugins/sonarqube/api/connection_api.go
index 29f26370c..9058ce3f7 100644
--- a/backend/plugins/sonarqube/api/connection_api.go
+++ b/backend/plugins/sonarqube/api/connection_api.go
@@ -19,6 +19,7 @@ package api
 
 import (
        "context"
+       "fmt"
        "net/http"
 
        "github.com/apache/incubator-devlake/core/errors"
@@ -95,6 +96,10 @@ func TestConnection(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        if testConnectionErr != nil {
                return nil, plugin.WrapTestConnectionErrResp(basicRes, 
testConnectionErr)
        }
+       if testConnectionResult.Status != http.StatusOK {
+               errMsg := fmt.Sprintf("Test connection fail, unexpected status 
code: %d", testConnectionResult.Status)
+               return nil, plugin.WrapTestConnectionErrResp(basicRes, 
errors.Default.New(errMsg))
+       }
        return &plugin.ApiResourceOutput{Body: testConnectionResult, Status: 
http.StatusOK}, nil
 }
 
@@ -116,6 +121,10 @@ func TestExistingConnection(input 
*plugin.ApiResourceInput) (*plugin.ApiResource
        if testConnectionErr != nil {
                return nil, plugin.WrapTestConnectionErrResp(basicRes, 
testConnectionErr)
        }
+       if testConnectionResult.Status != http.StatusOK {
+               errMsg := fmt.Sprintf("Test connection fail, unexpected status 
code: %d", testConnectionResult.Status)
+               return nil, plugin.WrapTestConnectionErrResp(basicRes, 
errors.Default.New(errMsg))
+       }
        return &plugin.ApiResourceOutput{Body: testConnectionResult, Status: 
http.StatusOK}, nil
 }
 

Reply via email to