MCPcopy Index your code
hub / github.com/cli/cli / GetRepository

Method GetRepository

internal/codespaces/api/api.go:162–190  ·  view source on GitHub ↗

GetRepository returns the repository associated with the given owner and name.

(ctx context.Context, nwo string)

Source from the content-addressed store, hash-verified

160
161// GetRepository returns the repository associated with the given owner and name.
162func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error) {
163 req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+strings.ToLower(nwo), nil)
164 if err != nil {
165 return nil, fmt.Errorf("error creating request: %w", err)
166 }
167
168 a.setHeaders(req)
169 resp, err := a.do(ctx, req, "/repos/*")
170 if err != nil {
171 return nil, fmt.Errorf("error making request: %w", err)
172 }
173 defer resp.Body.Close()
174
175 if resp.StatusCode != http.StatusOK {
176 return nil, api.HandleHTTPError(resp)
177 }
178
179 b, err := io.ReadAll(resp.Body)
180 if err != nil {
181 return nil, fmt.Errorf("error reading response body: %w", err)
182 }
183
184 var response Repository
185 if err := json.Unmarshal(b, &response); err != nil {
186 return nil, fmt.Errorf("error unmarshalling response: %w", err)
187 }
188
189 return &response, nil
190}
191
192// Codespace represents a codespace.
193// You can see more about the fields in this type in the codespaces api docs:

Callers

nothing calls this directly

Calls 5

setHeadersMethod · 0.95
doMethod · 0.95
HandleHTTPErrorFunction · 0.92
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected