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

Method GetUser

internal/codespaces/api/api.go:118–150  ·  view source on GitHub ↗

GetUser returns the user associated with the given token.

(ctx context.Context)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected