Bitbucket doesn't expose this information in the web interface, so I'll likely need to find it using the API.
How do I count the number of pull requests I've submitted to a repository on bitbucket
5.7k views Asked by ngoldbaum At
2
There are 2 answers
0
On
The following python code uses the requests library to interact with the bitbucket API. It should print the number of merged pull requests authored by the bitbucket account my_bb_username
. Note that you will need to edit url0
to point to the appropriate repository.
import requests
numprs = 0
url0 = "https://bitbucket.org/api/2.0/repositories/{username}/{reposlug}/pullrequests/?state=merged"
url = url0
while True:
r = requests.get(url)
if r.status_code != 200:
raise RuntimeError
data = r.json()
values = data['values']
for value in values:
if value['author']['username'] == 'my_bb_username':
print value['title']
numprs += 1
if 'next' in data.keys():
url = data['next']
else:
break
print numprs
If you want a list of all PRs, append ?state=merged,open,declined
to your API call. By default, the API will only include open PRs.
Some examples:
https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/pullrequests/?state=OPEN
https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/pullrequests/?state=MERGED
and search for the
size
entry in the response (eg: "size": 7)