How do I count the number of pull requests I've submitted to a repository on bitbucket

烂漫一生 提交于 2020-05-15 19:43:12

问题


Bitbucket doesn't expose this information in the web interface, so I'll likely need to find it using the API.


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/27117153/how-do-i-count-the-number-of-pull-requests-ive-submitted-to-a-repository-on-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!