MCPcopy Index your code
hub / github.com/apache/devlake / testConnection

Function testConnection

backend/plugins/github/api/connection_api.go:147–177  ·  view source on GitHub ↗
(ctx context.Context, conn models.GithubConn)

Source from the content-addressed store, hash-verified

145}
146
147func testConnection(ctx context.Context, conn models.GithubConn) (*GithubTestConnResponse, errors.Error) {
148 if vld != nil {
149 if err := vld.StructExcept(conn, "GithubAppKey", "GithubAccessToken"); err != nil {
150 return nil, errors.Convert(err)
151 }
152 }
153 githubApiResponse := &GithubTestConnResponse{}
154 if conn.AuthMethod == models.AppKey {
155 if tokenTestResult, err := testGithubConnAppKeyAuth(ctx, conn); err != nil {
156 return nil, errors.Convert(err)
157 } else {
158 githubApiResponse.Success = tokenTestResult.Success
159 githubApiResponse.Message = tokenTestResult.Message
160 githubApiResponse.Login = tokenTestResult.Login
161 githubApiResponse.Installations = tokenTestResult.Installations
162 }
163 } else if conn.AuthMethod == models.AccessToken {
164 if tokenTestResult, err := testGithubConnAccessTokenAuth(ctx, conn); err != nil {
165 return nil, errors.Convert(err)
166 } else {
167 githubApiResponse.Success = tokenTestResult.Success
168 githubApiResponse.Warning = tokenTestResult.Warning
169 githubApiResponse.Message = tokenTestResult.Message
170 githubApiResponse.Login = tokenTestResult.Login
171 }
172 } else {
173 return nil, errors.BadInput.New("invalid authentication method")
174 }
175
176 return githubApiResponse, nil
177}
178
179type GitHubTestConnResult struct {
180 AuthMethod string `json:"auth_method"`

Callers 1

TestConnectionFunction · 0.70

Calls 4

testGithubConnAppKeyAuthFunction · 0.85
NewMethod · 0.65
ConvertMethod · 0.45

Tested by 1

TestConnectionFunction · 0.56