GetUser returns the user associated with the given token.
(ctx context.Context)
| 115 | |
| 116 | // GetUser returns the user associated with the given token. |
| 117 | func (a *API) GetUser(ctx context.Context) (*User, error) { |
| 118 | req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/user", nil) |
| 119 | if err != nil { |
| 120 | return nil, fmt.Errorf("error creating request: %w", err) |
| 121 | } |
| 122 | |
| 123 | a.setHeaders(req) |
| 124 | resp, err := a.do(ctx, req, "/user") |
| 125 | if err != nil { |
| 126 | return nil, fmt.Errorf("error making request: %w", err) |
| 127 | } |
| 128 | defer resp.Body.Close() |
| 129 | |
| 130 | if resp.StatusCode != http.StatusOK { |
| 131 | return nil, api.HandleHTTPError(resp) |
| 132 | } |
| 133 | |
| 134 | b, err := io.ReadAll(resp.Body) |
| 135 | if err != nil { |
| 136 | return nil, fmt.Errorf("error reading response body: %w", err) |
| 137 | } |
| 138 | |
| 139 | var response User |
| 140 | if err := json.Unmarshal(b, &response); err != nil { |
| 141 | return nil, fmt.Errorf("error unmarshalling response: %w", err) |
| 142 | } |
| 143 | |
| 144 | return &response, nil |
| 145 | } |
| 146 | |
| 147 | // RepositoryOwner represents owner of a repository |
| 148 | type RepositoryOwner struct { |
nothing calls this directly
no test coverage detected