(ctx context.Context, accessToken string)
| 253 | } |
| 254 | |
| 255 | func (p *GitHubProvider) hasRepoAccess(ctx context.Context, accessToken string) error { |
| 256 | // https://developer.github.com/v3/repos/#get-a-repository |
| 257 | |
| 258 | type permissions struct { |
| 259 | Pull bool `json:"pull"` |
| 260 | Push bool `json:"push"` |
| 261 | } |
| 262 | |
| 263 | type repository struct { |
| 264 | Permissions permissions `json:"permissions"` |
| 265 | Private bool `json:"private"` |
| 266 | } |
| 267 | |
| 268 | endpoint := p.makeGitHubAPIEndpoint("/repos/"+p.Repo, nil) |
| 269 | |
| 270 | var repo repository |
| 271 | err := requests.New(endpoint.String()). |
| 272 | WithContext(ctx). |
| 273 | WithHeaders(makeGitHubHeader(accessToken)). |
| 274 | Do(). |
| 275 | UnmarshalInto(&repo) |
| 276 | |
| 277 | if err != nil { |
| 278 | return err |
| 279 | } |
| 280 | |
| 281 | // Every user can implicitly pull from a public repo, so only grant access |
| 282 | // if they have push access or the repo is private and they can pull |
| 283 | if repo.Permissions.Push || (repo.Private && repo.Permissions.Pull) { |
| 284 | return nil |
| 285 | } |
| 286 | |
| 287 | return errors.New("user doesn't have repository access") |
| 288 | } |
| 289 | |
| 290 | func (p *GitHubProvider) hasUser(ctx context.Context, accessToken string) (bool, error) { |
| 291 | // https://developer.github.com/v3/users/#get-the-authenticated-user |
no test coverage detected