Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of Repos (Public and Private) for an Organization on Github

I am trying to get a list of all repos associated with an organization using the github api gem in my rails application. I use omniauth to authenticate a user and then I am able to access a list of their organizations as well as a list of the user's repos but I am trying to get a list of repos for the user's organizations (which they have administrative access to).

There was one question on stackoverflow that seemed hopeful and it answered my question for accessing info for an organization's repo that I already have the name of but what about repos that I don't have a name for?

Any ideas how to list all repos for an org using the github api gem?

like image 727
topher Avatar asked Jan 28 '13 22:01

topher


2 Answers

Are you able to fetch the info using plain curl? E.g. try:

curl -u "your_username" https://api.github.com/orgs/:your_organization/repos?type=private

(this should list only private repos, substitute private with all to list all repos, as per the API docs: http://developer.github.com/v3/repos/#list-organization-repositories).

If this works, then you are just having trouble making it work using the ruby library?

If you don't know which organizations a user belongs to, use this API to find out: http://developer.github.com/v3/orgs/#list-user-organizations

like image 83
Ivan Zuzak Avatar answered Sep 28 '22 06:09

Ivan Zuzak


I was able to do this using GitHub's GraphQL API:

{
  organization(login: "<my-org-name>") {
    repositories(first: 100) {
      totalCount
      edges {
        node {
          name
          isArchived
        }
      }
    }
  }
}

I found GitHub's GraphQL Explorer to be really useful for quickly figuring this out.

One option for execution is GitHub's gh CLI which can run this query and you can then manipulate the output with jq or something.

Note that you'll need to implement pagination for more than 100 repos :)

like image 23
ryantuck Avatar answered Sep 28 '22 04:09

ryantuck