14

I wanna query all repositories in my organization on github private, i try to use

query {

  organization(login:"my-org-name") {
    id
    name
    url

    repositories(first:100) {
        nodes {
        id
        name
      }

    }

  }
}

However it returns

{
  "data": {
    "organization": {
      "id": "MDEyOk*********************U4ODUw",
      "name": "my-org-name",
      "url": "https://github.com/my-org-name",
      "repositories": {
        "nodes": []
      }
    }
  }
}

can't find any repositories. I test it on Github Developer, https://developer.github.com/v4/explorer/

Jini Gary Lee
  • 171
  • 1
  • 6

4 Answers4

9

you can achieve using search end point (you need to be authenticated)

query myOrgRepos($queryString: String!) {
  search(query: $queryString, type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
        }
      }
    }
  }
}

with query variables

{
  "queryString": "org:my_org"
}

Note that as expected you do not get the list repositories of your organization, you get the list of your organization list that you have access

Juan Rada
  • 3,513
  • 1
  • 26
  • 26
  • With pagination via the `gh api` cli and and org of more than 700 repos this search query takes 15-16 seconds while `organization(login: "***") { repositories(first: 100, after: $endCursor) { nodes { nameWithOwner } pageInfo { endCursor hasNextPage }}}}` was (still long) 10 seconds - any idea how to interact in a more timely fashion? `gh api -X GET '/orgs/***/repos?per_page=100' --paginate` seems much faster at 8 seconds - any idea how to get this info faster? – nhed Nov 24 '21 at 04:45
4

The GraphQL Explorer is an OAuth Application that needs to be given permission to access your organization data.

You can grant this access directly for the GraphQL API Explorer or navigate to it from your Settings -> Applications -> Authorized OAuth Apps

oauth apps

Note that a personal access token (PAT) does not have this restriction, so this isn't required for an application using your token.

osowskit
  • 5,904
  • 2
  • 29
  • 38
0

Here my example.

You have to be Authenticated to do this request.

url: https://api.github.com/graphql

header: Authorization bearer token

method: POST

query {
    viewer {
        avatarUrl
        login
        resourcePath
        url
        bio
        company
        createdAt
        location
        followers(first: 100) {
            nodes {
                name
                url
            }
        }
        repositories(first: 100) {
            nodes {
                name
                description
                url
                createdAt
                collaborators(first: 5) {
                    nodes {
                        name  
                    }
                    totalCount
                }
            }
            totalCount
        }
    }
}
Max
  • 393
  • 4
  • 4
0

Try this (type your org instead of your_org):

    {
  repositoryOwner(login: "your_org") {
    ... on Organization {
      repositories(first: 100) {
        totalCount
        pageInfo {
          endCursor
          hasNextPage
        }
        nodes {
          id
          name
          stars: stargazerCount
          forks: forkCount
          created_at: createdAt          
          organization: owner {
            login
          }
          repo_url: url
        }
      }
    }
  }
}