【问题标题】:GitHub's GraphQL API: How can I get all of the commits I've contributed to a particular public repo?GitHub 的 GraphQL API:如何获取我对特定公共存储库所做的所有提交?
【发布时间】:2019-07-12 10:18:55
【问题描述】:

我正在尝试查询 GitHub 的 GraphQL API (v4)。此 API 的哪个 GraphQL 查询可用于获取我对特定公共存储库所做的所有提交?

【问题讨论】:

    标签: github graphql github-graphql


    【解决方案1】:

    我想出了解决办法。 (下面显示的解决方案是用于从master 获取相关提交,但可以很容易地适应其他qualifiedName 值。)

    首先,执行初始查询以获取用户 ID:

    query {
      viewer {
        id
      }
    }
    

    然后可以使用以下查询来获取对特定存储库的所有贡献提交:

    query($repository_owner:String!, $repository_name:String!, $user_id:ID!) {
        repository(owner: $repository_owner, name: $repository_name) {
            ref(qualifiedName: "master") {
                target {
                    ... on Commit {
                        history(author: {id: $user_id}) {
                            totalCount
                            nodes {
                                id
                                authoredDate
                                message
                            }
                        }
                    }
                }
            }
        }
    }
    

    查询变量采用以下形式:

    {
      "repository_owner": "REPOSITORY_OWNER_STRING",
      "repository_name": "REPOSITORY_NAME_STRING",
      "user_id": "USER_ID_FROM_STEP_1"
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 2020-03-16
      • 2019-12-18
      • 1970-01-01
      • 2022-08-19
      • 2019-11-17
      • 2018-06-25
      • 2018-08-06
      • 2022-07-30
      相关资源
      最近更新 更多