GetRepository returns the repository associated with the given owner and name.
(ctx context.Context, nwo string)
| 160 | |
| 161 | // GetRepository returns the repository associated with the given owner and name. |
| 162 | func (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: |
nothing calls this directly
no test coverage detected