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

Function getUsername

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

Source from the content-addressed store, hash-verified

168}
169
170func getUsername(c *config.Config, hostname, token string, transport http.RoundTripper) (string, error) {
171 username, _ := c.Get(append(hostsKey, hostname, "user"))
172 if username != "" && username != "x-access-token" {
173 return username, nil
174 }
175 opts := ghAPI.ClientOptions{
176 Host: hostname,
177 AuthToken: token,
178 Transport: transport,
179 }
180 client, err := ghAPI.NewGraphQLClient(opts)
181 if err != nil {
182 return "", err
183 }
184 var query struct {
185 Viewer struct {
186 Login string
187 }
188 }
189 err = client.Query("CurrentUser", &query, nil)
190 if err != nil {
191 return "", err
192 }
193 return query.Viewer.Login, nil
194}
195
196func migrateToken(hostname, username string, tokenSource tokenSource) error {
197 // 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