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

Function getUsername

internal/config/migration/multi_account.go:162–186  ·  view source on GitHub ↗
(c *config.Config, hostname, token string, transport http.RoundTripper)

Source from the content-addressed store, hash-verified

160}
161
162func getUsername(c *config.Config, hostname, token string, transport http.RoundTripper) (string, error) {
163 username, _ := c.Get(append(hostsKey, hostname, "user"))
164 if username != "" && username != "x-access-token" {
165 return username, nil
166 }
167 opts := ghAPI.ClientOptions{
168 Host: hostname,
169 AuthToken: token,
170 Transport: transport,
171 }
172 client, err := ghAPI.NewGraphQLClient(opts)
173 if err != nil {
174 return "", err
175 }
176 var query struct {
177 Viewer struct {
178 Login string
179 }
180 }
181 err = client.Query("CurrentUser", &query, nil)
182 if err != nil {
183 return "", err
184 }
185 return query.Viewer.Login, nil
186}
187
188func migrateToken(hostname, username string, tokenSource tokenSource) error {
189 // If token is not currently stored in the keyring do not migrate it,

Callers 1

DoMethod · 0.85

Calls 2

GetMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected