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

Method GetUser

internal/codespaces/api/api.go:117–145  ·  view source on GitHub ↗

GetUser returns the user associated with the given token.

(ctx context.Context)

Source from the content-addressed store, hash-verified

115
116// GetUser returns the user associated with the given token.
117func (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
148type RepositoryOwner struct {

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