简体   繁体   中英

GitHub's GraphQL API: How can I get all of the commits I've contributed to a particular public repo?

I'm trying to query GitHub's GraphQL API (v4). What GraphQL query for this API can be used to get all of the commits I've contributed to a particular public repo?

I figured out the solution. (The solution shown below is for getting relevant commits from master , but can easily be adapted for other qualifiedName values.)

First, perform an initial query to obtain user ID:

query {
  viewer {
    id
  }
}

Then the following query can be used to get all contributed commits to a particular repository:

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
                        }
                    }
                }
            }
        }
    }
}

The query variables take the following form:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM