1

Currently I don't see any easy way to generate a report that has the list of admins for each repo within a GitHub org. The below example works for me great to retrieve the list of admins for a single repo :

curl https://my-github-url/api/v3/repos/my-org/my-repo/collaborators?per_page=100 \
     -H "Authorization: Token my-valid-token" | \
     jq '[ .[] | select(.permissions.admin == true) | .login ]'

Is there a way to iterate this for all the repos under that org and then generate a fancy report probably like a html tabular report or probably excel type

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Ashley
  • 1,447
  • 3
  • 26
  • 52

1 Answers1

1

You can use GraphQL API to reduce the number of request using the following :

{
  organization(login: "your-org") {
    repositories(first: 100) {
      nodes {
        nameWithOwner
        collaborators(first: 100) {
          totalCount
          edges {
            permission
            node {
              login
              name
            }
          }
          pageInfo {
            endCursor
            hasNextPage
          }
        }
      }
    }
  }
}

which gives :

{
  "data": {
    "organization": {
      "repositories": {
        "nodes": [
          {
            "nameWithOwner": "Your-Org/Your-Repo",
            "collaborators": {
              "totalCount": 18,
              "edges": [
                {
                  "permission": "ADMIN",
                  "node": {
                    "login": "johndoe",
                    "name": "John Doe"
                  }
                },
                ............................
              ]
            }
          }
        ]
      }
    }
  }
}

An example using , and :

#!/bin/bash

token="YOUR_TOKEN"
org="YOUR_ORG"

query='{
  organization(login: \"'$org'\") {
    repositories(first: 100) {
      nodes {
        nameWithOwner
        collaborators(first: 100) {
          totalCount
          edges {
            permission
            node {
              login
              name
            }
          }
          pageInfo {
            endCursor
            hasNextPage
          }
        }
      }
    }
  }
}
'
curl -s -H "Authorization: token $token" \
     -H  "Content-Type:application/json" \
     -d '{ 
          "query": "'"${query//[$'\n|\r\n']}"'"
      }' https://api.github.com/graphql | jq '.data.organization.repositories.nodes[] | 
        {
            repo: .nameWithOwner, 
            users: [
                .collaborators.edges[] | 
                select(.permission == "ADMIN") | 
                .node
            ]
        }'

If you have more than 100 repo or more than 100 collaborators, you would need to manage pagination

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
  • Thanks Bertrand. That worked great for me for an org with just five repos. I got the correct list of admins. However i need to try this for an org with 500 plus repositories. How do i use pagination to do so. I am fully novice in this area? – Ashley Oct 10 '20 at 01:27