isCollaborator checks if the user is a collaborator of the repository identified by owner and repo client must be authorized with user's auth token
(ctx context.Context, owner, repo string, client *github.Client, user *github.User)
| 999 | // isCollaborator checks if the user is a collaborator of the repository identified by owner and repo |
| 1000 | // client must be authorized with user's auth token |
| 1001 | func (s *Server) isCollaborator(ctx context.Context, owner, repo string, client *github.Client, user *github.User) (bool, error) { |
| 1002 | githubUserName := user.GetLogin() |
| 1003 | // repo belongs to the user's personal account |
| 1004 | if owner == githubUserName { |
| 1005 | return true, nil |
| 1006 | } |
| 1007 | |
| 1008 | // repo belongs to an org |
| 1009 | isCollaborator, resp, err := client.Repositories.IsCollaborator(ctx, owner, repo, user.GetLogin()) |
| 1010 | if err != nil { |
| 1011 | // user client does not have access to the repository |
| 1012 | if resp != nil && (resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden) { |
| 1013 | return false, nil |
| 1014 | } |
| 1015 | return false, err |
| 1016 | } |
| 1017 | return isCollaborator, nil |
| 1018 | } |
| 1019 | |
| 1020 | func (s *Server) redirectLogin(w http.ResponseWriter, r *http.Request) { |
| 1021 | redirectURL := s.admin.URLs.AuthLogin(r.URL.RequestURI(), false) |
no outgoing calls
no test coverage detected