jjNford
jjNford

Reputation: 5270

Getting Private Repos From Organization with GitHub API V3

I am having trouble obtaining and organizing private repos. I am using API V3 with this method: http://share.jjnford.com/HhIZ

I am using the jQuery.getJSON command and passing my OAuth2 access token to the API URL but am only getting public repositories returns.

Also if I fork a private organization repository to a user account (context) and pull the users repositories all the repos (public & private) show up except the private repo forked from an organization.

Can anybody help me out with this... it is my last hurdle...

Thanks in advance!

Upvotes: 13

Views: 8032

Answers (2)

I could not find a correct answer for this at the time, and I don't want to ask for the scope "repo" since it's too overkill for my application, it asks for code read/write permssions. Here's what worked for me (I'm using Ruby along with the octokit gem (https://github.com/octokit/octokit.rb)), special thanks to Ivan from the github dev support:

1.- During Oauth, ask for the "read:org" scope and get the Oauth 2 token from Github

2.- initialize octokit's client:

client = Octokit::Client.new(access_token: my_oauth2_token)

3.- Retrieve the user's organizations, we can do it because of the "read:org" scope

organizations = client.organizations

4.- For each organization, retrieve a Github admin Team to which this user belongs. And then, use this Team to retrieve the repos available

organizations.each do |organization|
    admin_team = client.organization_teams(organization[:id]).select { |repo| repo[:permission] == 'admin' }.first
    org_repos << client.team_repositories(admin_team[:id])
end

Yes, you will definitely need more requests to gather all the available repos, but as I said before, In my case, I did not want to ask for the "user" scope.

Note: Yes, the user have to be a member of an "admin" Team within a given Organization to be able to see the private repos.

Upvotes: 0

jjNford
jjNford

Reputation: 5270

I have found the problem and corrected it. According the the GitHub API V3 there are multiple scopes that can be used. It seems the the "user" scope is not valid anymore. Once I used just the "repo" scope everything was retrieved correctly (private org repos, and private forked org repos).

Upvotes: 3

Related Questions