(ctx context.Context)
| 139 | } |
| 140 | |
| 141 | func (c *RepoAccessCache) viewerLoginFor(ctx context.Context) (string, error) { |
| 142 | c.viewerMu.Lock() |
| 143 | defer c.viewerMu.Unlock() |
| 144 | if c.viewerLogin != "" { |
| 145 | return c.viewerLogin, nil |
| 146 | } |
| 147 | if c.client == nil { |
| 148 | return "", fmt.Errorf("nil GraphQL client") |
| 149 | } |
| 150 | var query struct { |
| 151 | Viewer struct { |
| 152 | Login githubv4.String |
| 153 | } |
| 154 | } |
| 155 | if err := c.client.Query(ctx, &query, nil); err != nil { |
| 156 | return "", fmt.Errorf("failed to query viewer login: %w", err) |
| 157 | } |
| 158 | login := strings.ToLower(string(query.Viewer.Login)) |
| 159 | if login == "" { |
| 160 | return "", fmt.Errorf("viewer login returned empty") |
| 161 | } |
| 162 | c.viewerLogin = login |
| 163 | return c.viewerLogin, nil |
| 164 | } |
| 165 | |
| 166 | // setViewerLogin seeds the cached viewer login from a piggy-backed query response. |
| 167 | func (c *RepoAccessCache) setViewerLogin(login string) { |
no outgoing calls