github icon indicating copy to clipboard operation
github copied to clipboard

Unable to list private repositories

Open deanwilson opened this issue 4 years ago • 3 comments

Hello, I'm unsure if this is user error (most likely) but I'm having issues including private repositories in the results of a repos.list call. I've tried using different scopes in the generated Personal access token, including adding one with all permissions enabled, but i am still unable to list private repositories.

require 'github_api'

username = 'deanwilson'
private_repo = 'private-test-repo_name'

config = {
  auto_pagination: true,
  oauth_token:     ENV['GITHUB_TOKEN'],
  user:            username
}

github = Github.new config

# get the private repo directly
foo = github.repos.get user: username, repo: private_repo

puts "Is #{private_repo} private? #{foo.private}"


# list _all_ repos
repos = github.repos.list
puts "Looking through #{repos.length} repos"

names = repos.map {|r| r.name }

if names.include? private_repo
  puts "Found private repo in list"
else
  puts "Didn't find private repo in list"
end

private_repos = repos.select {|r| r.private }
puts "Found #{private_repos.length} private repos"
__END__

bundle exec ruby lister
Is private-test-repo private? true
Looking through 87 repos
Didn't find private repo in list
Found 0 private repos

This is an individual github user but it is also assicatyed with a small number of orgs. I am only attempting to list the users own repos.

Any advice on this would be appreciated.

Thank you for your time.

deanwilson avatar Jul 14 '20 09:07 deanwilson

If i change user: username to org: 'actual-org-name it does return private repositories that are present in the specified organisation.

deanwilson avatar Jul 14 '20 09:07 deanwilson

wadl20090202.pdf

trucktank avatar Aug 05 '20 10:08 trucktank

Same thing for me, tried switching user to be org but same result still can't list private repositories.

I, [2021-03-13T20:03:19.585025 #18918]  INFO -- request: GET https://api.github.com/orgs/xxx/repos?type=private&per_page=50
I, [2021-03-13T20:03:19.585083 #18918]  INFO -- request: Accept: "application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"

scalp42 avatar Mar 14 '21 04:03 scalp42