| 168 | } |
| 169 | |
| 170 | func 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 | |
| 196 | func migrateToken(hostname, username string, tokenSource tokenSource) error { |
| 197 | // If token is not currently stored in the keyring do not migrate it, |