Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create a dashboard listing pull requests with more than a specified number of lines

Hi Bitbucket community,

 

We need to create a dashboard with all pull requests that are bigger than a specified limit on the number of lines. Or all pull requests with the number of lines changed.

 

This could be a dashboard on bitbucket, data exported to google sheets, or a script run on the command line to create a local csv.

 

Please suggest the best possible way to go about this. We can write code if required.

 

Regards,

Magham

1 answer

0 votes

Hi @Rajesh Magham,

I believe that this should be possible if you write a script using our API.

If you are interested in pull requests of all repositories in a workspace, the first step would be to get all repositories of this workspace with the following endpoint:

Then, for each repository you can get its pull requests with the following endpoint:

Please note that by default, this endpoint returns only OPEN pull requests (this is also mentioned in the link above).
If you are interested in pull requests that are also MERGED or DECLINED, you will need to run additional queries to get pull requests in these states as well.
An example with curl to get pull requests in MEGRGED state:

curl -u <username>:<app-password> https://api.bitbucket.org/2.0/repositories/<workspace-id>/<repo-slug>/pullrequests?q=state+%3D+%22MERGED%22

When you have the list of pull requests, you can use the following endpoint for each pull request to get its diffstat:

An example call with curl would be the following (for a PR with id 2):

curl -u <username>:<app-password> -L https://api.bitbucket.org/2.0/repositories/<workspace-id>/<repo-slug>/pullrequests/2/diffstat

Please note that the -L parameter is needed in the call because this endpoint redirects to the repository diffstat.

The output of this call has the fields lines_removed and lines_added for each file of the pull request.
You will need to add these values for each file of the PR, in order to get the total number of lines of the PR's diff.


By default, each endpoint returns all the fields available for a resource, and that can be a lot of data.
You can use the fields parameter in the API calls, in order to return only the fields that are useful to you.
You can read more about that and find examples here:

If you have any questions, please feel free to let me know.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

74 views 2 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you