[Go] GitHub Graphql 获得仓库列表

curl 例子

curl --location 'https://github.com/api/graphql' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 213123123123123' \
--data '{"query":"{\n  viewer {\n    login\n  }\n  organization(login: \"组织名\") {\n    name\n    databaseId\n    teams(first: 100) {\n      totalCount\n      nodes {\n        members {\n          nodes {\n            name\n            databaseId\n            url\n          }\n        }\n        name\n        teamsUrl\n        repositories(first: 100) {\n          totalCount\n          nodes {\n            databaseId\n            collaborators(first: 10) {\n              totalCount\n              edges {\n                 node {\n                     id\n                     email\n                     name\n                 }\n              }\n              nodes {\n                 email\n              }\n            }\n            description\n            nameWithOwner\n            name\n            defaultBranchRef {\n                name\n            }\n            owner {\n              id\n              login\n            }\n          }\n        }\n      }\n    }\n    repositories(last: 100) {\n      totalCount\n      edges {\n        node {\n          name\n          collaborators {\n            totalCount\n          }\n        }\n      }\n      nodes {\n        databaseId\n        nameWithOwner\n        \n      }\n    }\n  }\n}","variables":{}}'

获得organization下所有的repositories

请求Github Enterprise的对应的给定组织名的API仓库列表,获得项目列表,长度最多返回100, 数据大于100,需要分页.

{
  viewer {
    login
  }
  organization(login: "组织名") {
    name
    databaseId
    teams(first: 100) {
      totalCount
      nodes {
        members {
          nodes {
            name
            databaseId
            url
          }
        }
        name
        teamsUrl
        repositories(first: 100) {
          totalCount
          nodes {
            databaseId
            collaborators(first: 10) {
              totalCount
              edges {
                 node {
                     id
                     email
                     name
                 }
              }
              nodes {
                 email
              }
            }
            description
            nameWithOwner
            name
            defaultBranchRef {
                name
            }
            owner {
              id
              login
            }
          }
        }
      }
    }
    repositories(last: 100) {
      totalCount
      edges {
        node {
          name
          collaborators {
            totalCount
          }
        }
      }
      nodes {
        databaseId
        nameWithOwner
        
      }
    }
  }
}

结果为:

{
    "data": {
        "viewer": {
            "login": "登录名"
        },
        "organization": {
            "name": "组织名",
            "databaseId": 7949,
            "teams": {
                "totalCount": 0,
                "nodes": []
            },
            "repositories": {
                "totalCount": 193,
                "edges": [
                    {
                        "node": {
                            "name": "具体的项目1",
                            "collaborators": null
                        }
                    }
                ],
                "nodes": [
                    {
                        "databaseId": 99388,
                        "nameWithOwner": "组织名/具体的项目2"
                    },
                    {
                        "databaseId": 100522,
                        "nameWithOwner": "组织名/具体的项目3"
                    }
                ]
            }
        }
    },
    "errors": [
        {
            "type": "FORBIDDEN",
            "path": [
                "organization",
                "repositories",
                "edges",
                0,
                "node",
                "collaborators"
            ],
            "locations": [
                {
                    "line": 56,
                    "column": 11
                }
            ],
            "message": "You do not have permission to view repository collaborators."
        },
        {
            "type": "FORBIDDEN",
            "path": [
                "organization",
                "repositories",
                "edges",
                1,
                "node",
                "collaborators"
            ],
            "locations": [
                {
                    "line": 56,
                    "column": 11
                }
            ],
            "message": "You do not have permission to view repository collaborators."
        }
    ]
}

这里的FORBIDDEN说明当前login的用户权限不够.(自己想办法)