Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of pull requests between 2 commits

I want to make a tool that retrieves all the pull requests (title and body) done between 2 commits in SourceTree. What I have is the hash of 2 commits. I am able to get every commit hash inbetween with a single git log. I can call Github's API and list all pull requests of the repository but, from there I have a problem.

The two ways of doing seem to be by matching a range of dates or by parsing the commits associated with the pull request and see if they match but that doesn't seem like a clean solution.

Does anyone know of a way to accomplish this? Thank you.

like image 709
user2663041 Avatar asked Dec 10 '16 19:12

user2663041


People also ask

How do I get a list of commits in a pull request?

You can list the pull requests associated with a commit using GET /repos/:owner/:repo/commits/:commit_sha/pulls , which will show the pull requests which the given commit is associated with. This does mean that you'll need to check every commit to see if its associated with the PR.

How do I find local pull requests?

To check out a pull request locally, use the gh pr checkout subcommand. Replace pull-request with the number, URL, or head branch of the pull request.


1 Answers

You can get the PR numbers, by using the git log command plus grep (if grep is available to you).

git log --oneline commit1...commit2 | grep 'Merge pull request #'

Keep in mind that you can replace commit1 and commit2 with an actual tag or release.

If you want to get the title and body, you will have to extract the number from the above and then call the github API GET /repos/:owner/:repo/pulls/:number (see https://developer.github.com/v3/pulls/)

To find total count of PRs run:

git log --oneline commit1...commit2 | grep 'Merge pull request #' | wc -l
like image 128
Daniel Avatar answered Oct 17 '22 23:10

Daniel