Home > Net >  How do i know the amount of how many recently accepted commits from pull request are accepted
How do i know the amount of how many recently accepted commits from pull request are accepted

Time:08-19

How do i know the amount of how many recently accepted commits from pull request are accepted. How do I do this automatically? I can't seem to find an API or a git command that does this.

For example, John recently did a pull request to a repo, and Mark(repo) owner accepted his pull request, with this 5 new total commits has been added. How do I get the "5" value.

CodePudding user response:

You can get information about pull requests using the GitHub API:

Pulls

The Pulls API allows you to list, view, edit, create, and even merge pull requests.

If you read the docs, you'll see there is even an API to list commits in a pull request. Given a pull request number, you can request:

https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/commits

This returns a JSON list of commits, so the answer to your question is "the length of the list". Using the github cli and jq, we can write, for example:

gh api /repos/git/git/pulls/1297/commits | jq length

This returns 2, the number of commits in pull request 1297 to the git/git repository.

You can use curl instead of the gh cli tool (although in the case you'll have to handle authentication yourself when necessary):

curl -sf https://api.github.com/repos/git/git/pulls/1297/commits | jq length
  •  Tags:  
  • git
  • Related