The login name of the authenticated user will be readily available only if authentication info comes from the config file. With other upcoming authentication modes (for example, the GITHUB_TOKEN environment variable), the token is the only piece of information we got, so we would need to additionally query for the login name. Since `issue status` and `pr status` are the only commands that need the name of the authenticated user right now, have those commands explicitly query for the login name. This results in an additional API query, but simplifies Context implementation and future authentication approaches.
18 lines
311 B
Go
18 lines
311 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/shurcooL/githubv4"
|
|
)
|
|
|
|
func CurrentLoginName(client *Client) (string, error) {
|
|
var query struct {
|
|
Viewer struct {
|
|
Login string
|
|
}
|
|
}
|
|
v4 := githubv4.NewClient(client.http)
|
|
err := v4.Query(context.Background(), &query, nil)
|
|
return query.Viewer.Login, err
|
|
}
|