MCPcopy Create free account
hub / github.com/cloudbase/garm / Do

Method Do

util/github/scalesets/client.go:84–119  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

82}
83
84func (s *ScaleSetClient) Do(req *http.Request) (*http.Response, error) {
85 if s.httpClient == nil {
86 return nil, fmt.Errorf("http client is not initialized")
87 }
88
89 resp, err := s.httpClient.Do(req) //nolint:gosec // G704 - URL is constructed from GitHub API endpoints
90 if err != nil {
91 return nil, fmt.Errorf("failed to dispatch HTTP request: %w", err)
92 }
93
94 if resp.StatusCode >= 200 && resp.StatusCode < 300 {
95 return resp, nil
96 }
97
98 var body []byte
99 if resp != nil {
100 defer resp.Body.Close()
101 body, err = io.ReadAll(resp.Body)
102 if err != nil {
103 return nil, fmt.Errorf("failed to read body: %w", err)
104 }
105 }
106
107 switch resp.StatusCode {
108 case 404:
109 return nil, runnerErrors.NewNotFoundError("resource %s not found: %q", req.URL.String(), string(body))
110 case 400:
111 return nil, runnerErrors.NewBadRequestError("bad request while calling %s: %q", req.URL.String(), string(body))
112 case 409:
113 return nil, runnerErrors.NewConflictError("conflict while calling %s: %q", req.URL.String(), string(body))
114 case 401, 403:
115 return nil, runnerErrors.ErrUnauthorized
116 default:
117 return nil, fmt.Errorf("request to %s failed with status code %d: %q", req.URL.String(), resp.StatusCode, string(body))
118 }
119}

Callers 15

GetRunnerMethod · 0.95
ListAllRunnersMethod · 0.95
GetRunnerByNameMethod · 0.95
RemoveRunnerMethod · 0.95
AcquireJobsMethod · 0.95
GetAcquirableJobsMethod · 0.95
CreateMessageSessionMethod · 0.95
DeleteMessageSessionMethod · 0.95
GetRunnerScaleSetByIDMethod · 0.95
ListRunnerScaleSetsMethod · 0.95

Calls 2

CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected