is there a way to get the Pull requests statistics ( Raised, Reviewed, Committed, Approved .. ) for a user for each of the repositories
I would be more interested if this query can be automated using python.
Thanks in advance
You can automate the retrieval of pull request statistics for a specific user across multiple repositories using the Bitbucket Cloud API (or Bitbucket Server/Data Center API, depending on your setup).
Using Python to Get PR Statistics
Set Up Authentication
If you’re using Bitbucket Cloud, you can authenticate using OAuth, App passwords, or personal access tokens. For Bitbucket Server/Data Center, use basic authentication or personal access tokens.
Query the API for Pull Requests
The Bitbucket Cloud API provides endpoints to retrieve pull requests, including their statuses (OPEN, MERGED, DECLINED) and approvals.
Filter by User and Repository
You can loop through all repositories and filter by the user ID to get the statistics you need.
Example Python Script
import requests
# Replace with your Bitbucket workspace and username
BITBUCKET_WORKSPACE = "your_workspace"
USERNAME = "target_username"
AUTH = ("your_username", "your_app_password") # Use OAuth or token-based auth if needed
def get_repos():
url = f"https://api.bitbucket.org/2.0/repositories/{BITBUCKET_WORKSPACE}"
response = requests.get(url, auth=AUTH)
return response.json().get("values", [])
def get_pull_requests(repo_slug):
url = f"https://api.bitbucket.org/2.0/repositories/{BITBUCKET_WORKSPACE}/{repo_slug}/pullrequests"
params = {"state": "MERGED"} # Change state to OPEN, DECLINED, etc., if needed
response = requests.get(url, params=params, auth=AUTH)
return response.json().get("values", [])
def get_user_pr_stats():
repos = get_repos()
stats = {"raised": 0, "reviewed": 0, "approved": 0}
for repo in repos:
repo_slug = repo["slug"]
prs = get_pull_requests(repo_slug)
for pr in prs:
if pr["author"]["username"] == USERNAME:
stats["raised"] += 1
# Check approvals
for participant in pr.get("participants", []):
if participant["user"]["username"] == USERNAME and participant["approved"]:
stats["approved"] += 1
# Count reviews (assuming comments or participation means review)
if any(p["user"]["username"] == USERNAME for p in pr.get("participants", [])):
stats["reviewed"] += 1
return stats
if __name__ == "__main__":
user_stats = get_user_pr_stats()
print(f"User PR Stats: {user_stats}")
What This Script Does
Next Steps
page
parameter in API).If you're looking for automated PR tracking across multiple systems, Getint offers integrations between Jira and Git Repos, ensuring that development workflows remain synchronized. Let us know if we can help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.