使用 GitHub API 和脚本检索 GitHub 组织中每个回购的所有管理员的报告

Retrieve a report with all admins for each repo in a GitHub org using GitHub API and scripting

目前我没有看到任何简单的方法来生成包含 GitHub 组织中每个回购的管理员列表的报告。下面的示例对我来说非常有用,可以检索单个存储库的管理员列表:

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 ]'

有没有一种方法可以针对该组织下的所有回购协议进行迭代,然后生成可能类似于 html 表格报告或可能 excel 类型

的奇特报告

您可以使用 GraphQL API 来减少使用以下请求的数量:

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

给出:

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

使用 , 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
            ]
        }'

如果您有超过 100 个 repo 或超过 100 个协作者,则需要管理