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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With