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

Function testConnection

backend/plugins/gitee/api/connection.go:37–72  ·  view source on GitHub ↗
(ctx context.Context, connection models.GiteeConn)

Source from the content-addressed store, hash-verified

35}
36
37func testConnection(ctx context.Context, connection models.GiteeConn) (*GiteeTestConnResponse, errors.Error) {
38 // validate
39 if vld != nil {
40 if err := vld.Struct(connection); err != nil {
41 return nil, errors.Default.Wrap(err, "error validating target")
42 }
43 }
44 apiClient, err := helper.NewApiClientFromConnection(ctx, basicRes, &connection)
45 if err != nil {
46 return nil, err
47 }
48 res, err := apiClient.Get("user", nil, nil)
49 if err != nil {
50 return nil, err
51 }
52 resBody := &models.ApiUserResponse{}
53 err = helper.UnmarshalResponse(res, resBody)
54 if err != nil {
55 return nil, err
56 }
57
58 if res.StatusCode == http.StatusUnauthorized {
59 return nil, errors.HttpStatus(http.StatusBadRequest).New("StatusUnauthorized error when testing connection")
60 }
61
62 if res.StatusCode != http.StatusOK {
63 return nil, errors.HttpStatus(res.StatusCode).New("unexpected status code when testing connection")
64 }
65 connection = connection.Sanitize()
66 body := GiteeTestConnResponse{}
67 body.Success = true
68 body.Message = "success"
69 body.Connection = &connection
70 // output
71 return &body, nil
72}
73
74// TestConnection test gitee connection
75// @Summary test gitee connection

Callers 2

TestConnectionFunction · 0.70
TestExistingConnectionFunction · 0.70

Calls 4

WrapMethod · 0.80
GetMethod · 0.65
NewMethod · 0.65
SanitizeMethod · 0.45

Tested by 2

TestConnectionFunction · 0.56
TestExistingConnectionFunction · 0.56