Sam Hakim
Sam Hakim

Reputation: 69

Check if user is a collaborator on a Github Project

I have a rails app and need to check if a specific user is a collaborator on a Github project, and also the list of GitHub projects a specific user can commit to. This is to verify if they can commit to the project (e.g., are admin or have push rights), and to help them pick off the projects they can commit to.

I tried using the rails gem "omniauth-github" with Github API[1], but it appears one needs to be a repo owner to verify a user's collaborator status.

GET /repos/:owner/:repo/collaborators/:username

Can you please recommend how to check if a user is a collaborator on a project using Github API and omniauth-github gem? Ideally, a user would authorize the app to obtain a list of repos where that user is an owner/collaborator, without also requiring the user to authorize the app to make changes (I don't need such powerful privileges).

Thanks

[1] https://developer.github.com/v3/repos/collaborators/#get

Upvotes: 1

Views: 1658

Answers (1)

Dan Kohn
Dan Kohn

Reputation: 34347

The developer needs to authorize your app to access Github on its behalf. Here is info on setting up authentication: https://developer.github.com/guides/getting-started/#authentication

You can test by getting a personal Oauth token. The query to see public repos to which a user can commit is:

curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com/user/repos?type=public

Update:

To access the same via the github_api gem, use:

Github.new oauth_token: current_user.credentials.token
repo_data = github.repos.list(type: 'public')

Upvotes: 1

Related Questions