checkPushAccess checks if the user has push access to the repository via the REST permission endpoint.
(ctx context.Context, username, owner, repo string)
| 271 | |
| 272 | // checkPushAccess checks if the user has push access to the repository via the REST permission endpoint. |
| 273 | func (c *RepoAccessCache) checkPushAccess(ctx context.Context, username, owner, repo string) (bool, error) { |
| 274 | if c.restClient == nil { |
| 275 | return false, fmt.Errorf("nil REST client") |
| 276 | } |
| 277 | |
| 278 | permLevel, _, err := c.restClient.Repositories.GetPermissionLevel(ctx, owner, repo, username) |
| 279 | if err != nil { |
| 280 | return false, fmt.Errorf("failed to get user permission level: %w", err) |
| 281 | } |
| 282 | |
| 283 | // REST API maps "maintain" to "write" (and "triage" to "read") |
| 284 | // https://docs.github.com/en/rest/collaborators/collaborators#get-repository-permissions-for-a-user |
| 285 | permission := permLevel.GetPermission() |
| 286 | return permission == "admin" || permission == "write", nil |
| 287 | } |
| 288 | |
| 289 | func (c *RepoAccessCache) log(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr) { |
| 290 | if c == nil || c.logger == nil { |