Reputation: 229
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.
Upvotes: 13
Views: 7034
Reputation: 3279
I would look into the official github cli tool.
https://cli.github.com/manual/gh_pr_list
With this you can lists PRs. if it is sufficient to search between dates instead of commits you can easily get all merged PRs between two dates like this:
gh pr list --base main --search "merged:2023-03-10..2023-03-15" --limit 100
Upvotes: 1
Reputation: 1205
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
Upvotes: 14