MCPcopy Create free account
hub / github.com/dolthub/doltgresql / SearchCode

Function SearchCode

testing/dumps/scraper/main.go:132–159  ·  view source on GitHub ↗

SearchCode executes the query against the API, returning all items that were found.

(ctx context.Context, hc *http.Client, token string, page int, perPage int)

Source from the content-addressed store, hash-verified

130
131// SearchCode executes the query against the API, returning all items that were found.
132func SearchCode(ctx context.Context, hc *http.Client, token string, page int, perPage int) ([]Item, error) {
133 params := url.Values{}
134 params.Set("q", query)
135 params.Set("page", strconv.Itoa(page))
136 params.Set("per_page", strconv.Itoa(perPage))
137
138 req, _ := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/search/code?"+params.Encode(), nil)
139 SetHeaders(req, token)
140 resp, err := hc.Do(req)
141 if err != nil {
142 return nil, err
143 }
144 defer resp.Body.Close()
145 if HandleRate(resp) {
146 return SearchCode(ctx, hc, token, page, perPage)
147 }
148 var sr CodeSearchResult
149 if err = json.NewDecoder(resp.Body).Decode(&sr); err != nil {
150 return nil, err
151 }
152 if resp.StatusCode != 200 {
153 if sr.Message != "" {
154 return nil, fmt.Errorf("search error: %s (HTTP %d)", sr.Message, resp.StatusCode)
155 }
156 return nil, fmt.Errorf("search error: HTTP %d", resp.StatusCode)
157 }
158 return sr.Items, nil
159}
160
161// GetContent gets the ContentFile from the given URL.
162func GetContent(ctx context.Context, hc *http.Client, token string, contentsURL string) (*ContentFile, error) {

Callers 1

mainFunction · 0.85

Calls 7

SetHeadersFunction · 0.85
HandleRateFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.65
SetMethod · 0.45
EncodeMethod · 0.45
NewDecoderMethod · 0.45

Tested by

no test coverage detected