You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/01/09 06:56:44 UTC

(incubator-devlake) branch main updated: fix(github): fix resp when testing an existed connection (#6772)

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

abeizn 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 c26273ace fix(github): fix resp when testing an existed connection (#6772)
c26273ace is described below

commit c26273ace6634d94c4eef429b2ca38573d35e4b6
Author: Lynwee <li...@merico.dev>
AuthorDate: Tue Jan 9 14:56:39 2024 +0800

    fix(github): fix resp when testing an existed connection (#6772)
---
 backend/plugins/github/api/connection_api.go | 32 ++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/backend/plugins/github/api/connection_api.go b/backend/plugins/github/api/connection_api.go
index 2b9e9f98d..44af6961c 100644
--- a/backend/plugins/github/api/connection_api.go
+++ b/backend/plugins/github/api/connection_api.go
@@ -344,20 +344,38 @@ func testExistingConnection(ctx context.Context, conn models.GithubConn) (*Githu
 		for _, token := range tokens {
 			testGithubConn := conn
 			testGithubConn.Token = token
-			if tokenTestResult, err := testGithubConnAccessTokenAuth(ctx, testGithubConn); err != nil {
-				return nil, errors.Convert(err)
-			} else {
-				githubApiResponse.Tokens = append(githubApiResponse.Tokens, tokenTestResult)
-				if tokenTestResult.Success {
-					githubApiResponse.Success = tokenTestResult.Success
-					githubApiResponse.Message = tokenTestResult.Message
+			tokenTestResult, err := testGithubConnAccessTokenAuth(ctx, testGithubConn)
+			if err != nil {
+				// generate a failed message for current token
+				tokenTestResult = &GitHubTestConnResult{
+					AuthMethod:     models.AccessToken,
+					AppId:          testGithubConn.AppId,
+					InstallationID: testGithubConn.InstallationID,
+					Token:          testGithubConn.Sanitize().Token,
+					Success:        false,
+					Message:        err.Error(),
+					Login:          "",
+					Warning:        true,
+					Installations:  nil,
 				}
 			}
+			githubApiResponse.Tokens = append(githubApiResponse.Tokens, tokenTestResult)
 		}
 	} else {
 		return nil, errors.BadInput.New("invalid authentication method")
 	}
 
+	// resp.success is true by default
+	githubApiResponse.Success = true
+	githubApiResponse.Message = "success"
+	for _, token := range githubApiResponse.Tokens {
+		if !token.Success {
+			githubApiResponse.Success = false
+			githubApiResponse.Message = token.Message
+			githubApiResponse.Causes = append(githubApiResponse.Causes, token.Message)
+		}
+	}
+
 	return githubApiResponse, nil
 }