cli/api/queries_user.go
Kynan Ware 16c6500c82 Add godoc comments to exported symbols in api/
Add documentation comments to all exported types, functions, methods,
constants, and variables in the api/ package to satisfy the godoclint
require-doc rule.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-04 15:47:48 -07:00

49 lines
1.3 KiB
Go

package api
// Organization represents a GitHub organization with a login name.
type Organization struct {
Login string
}
// CurrentLoginName returns the login name of the currently authenticated user.
func CurrentLoginName(client *Client, hostname string) (string, error) {
var query struct {
Viewer struct {
Login string
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
return query.Viewer.Login, err
}
// CurrentLoginNameAndOrgs returns the login name and organization memberships of the currently authenticated user.
func CurrentLoginNameAndOrgs(client *Client, hostname string) (string, []string, error) {
var query struct {
Viewer struct {
Login string
Organizations struct {
Nodes []Organization
} `graphql:"organizations(first: 100)"`
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
if err != nil {
return "", nil, err
}
orgNames := []string{}
for _, org := range query.Viewer.Organizations.Nodes {
orgNames = append(orgNames, org.Login)
}
return query.Viewer.Login, orgNames, nil
}
// CurrentUserID returns the node ID of the currently authenticated user.
func CurrentUserID(client *Client, hostname string) (string, error) {
var query struct {
Viewer struct {
ID string
}
}
err := client.Query(hostname, "UserCurrent", &query, nil)
return query.Viewer.ID, err
}