MCPcopy
hub / github.com/apache/devlake / Do

Method Do

backend/helpers/pluginhelper/api/api_client.go:320–400  ·  view source on GitHub ↗

Do FIXME ...

(
	method string,
	path string,
	query url.Values,
	body interface{},
	headers http.Header,
)

Source from the content-addressed store, hash-verified

318
319// Do FIXME ...
320func (apiClient *ApiClient) Do(
321 method string,
322 path string,
323 query url.Values,
324 body interface{},
325 headers http.Header,
326) (*http.Response, errors.Error) {
327 uri, err := GetURIStringPointer(apiClient.endpoint, path, query)
328 if err != nil {
329 return nil, errors.Default.Wrap(err, fmt.Sprintf("Unable to construct URI from %s, %s, %s", apiClient.endpoint, path, query))
330 }
331 // process body
332 var reqBody io.Reader
333 if body != nil {
334 reqJson, err := json.Marshal(body)
335 if err != nil {
336 return nil, errors.Default.Wrap(err, fmt.Sprintf("unable to serialize API request body for %s", *uri))
337 }
338 reqBody = bytes.NewBuffer(reqJson)
339 }
340 var req *http.Request
341 if apiClient.ctx != nil {
342 req, err = errors.Convert01(http.NewRequestWithContext(apiClient.ctx, method, *uri, reqBody))
343 } else {
344 req, err = errors.Convert01(http.NewRequest(method, *uri, reqBody))
345 }
346 if err != nil {
347 return nil, errors.Default.Wrap(err, fmt.Sprintf("unable to create API request for %s", *uri))
348 }
349 req.Header.Set("Content-Type", "application/json")
350
351 // populate headers
352 if apiClient.headers != nil {
353 for name, value := range apiClient.headers {
354 req.Header.Set(name, value)
355 }
356 }
357 for name, values := range headers {
358 for _, value := range values {
359 req.Header.Add(name, value)
360 }
361 }
362
363 var res *http.Response
364 // authFunc
365 if apiClient.authFunc != nil {
366 err = apiClient.authFunc(req)
367 if err != nil {
368 apiClient.logError(err, "[api-client] authFunc returned error for %s", req.URL.String())
369 return nil, err
370 }
371 }
372 // before send
373 if apiClient.beforeRequest != nil {
374 err = apiClient.beforeRequest(req)
375 if err != nil {
376 apiClient.logError(err, "[api-client] beforeRequest returned error for %s", req.URL.String())
377 return nil, err

Callers 15

GetMethod · 0.95
PostMethod · 0.95
CalculateMethod · 0.80
DoAsyncMethod · 0.80
ConnectLocalServerFunction · 0.80
forceSendHttpRequestMethod · 0.80
sendHttpRequestFunction · 0.80
putBatchDataFunction · 0.80
doMethod · 0.80
refreshTokenMethod · 0.80
listInstallationsFunction · 0.80
getInstallationTokenFunction · 0.80

Implementers 2

ApiClientbackend/helpers/pluginhelper/api/api_c
refreshApiClientbackend/plugins/github/token/refresh_a

Calls 7

logErrorMethod · 0.95
logDebugMethod · 0.95
GetURIStringPointerFunction · 0.85
WrapMethod · 0.80
CloseMethod · 0.65
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected