MCPcopy Create free account
hub / github.com/cli/cli / GetRepository

Method GetRepository

internal/codespaces/api/api.go:167–203  ·  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

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

Callers

nothing calls this directly

Calls 8

setHeadersMethod · 0.95
doMethod · 0.95
RepoPartsFromNWOFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
StringMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected