| 160 | } |
| 161 | |
| 162 | func 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 | |
| 188 | func migrateToken(hostname, username string, tokenSource tokenSource) error { |
| 189 | // If token is not currently stored in the keyring do not migrate it, |