Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Best way to automatically detect when a pull request resulted in conflict?

Andreas Borkenhagen December 4, 2014

I need to detect when a pull request couldn't be merged because of merge conflicts (as soon as possible). Do I have to poll the log files or is there any better way?

 Best way would be a plugin that is triggered on a conflicting pull request.

3 answers

1 accepted

2 votes
Answer accepted
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2014

Hi Andreas,

Depending on your use case, you could poll the list of open Pull Requests via the REST API:

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests

and then use the merge status end-point at:

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/merge

to determine which are conflicted.

I'd stagger how quickly you call merge end-point though. Calculating merge results can be a very expensive operation, depending on the size of the PR, so calling it to rapidly may hurt performance.

cheers,

Tim

Andreas Borkenhagen December 8, 2014

Is the merge processed multiple times when I call this REST resource? When I open the Pull Request via Browser/HTML the merge is processed only one time. Every further call of the Pull Requests page does not trigger any Git activities in the background afaik.

TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2014

The result is cached permanently, but calling it in quick succession for different PRs for which the merge result hasn't been calculated (of the same PR if the source or target branch is updated) could get expensive.

Andreas Borkenhagen December 8, 2014

I only have to retrieve the merge result for a few branches and only for Pull Requests that are still open, so I think this will be reasonable costs. I will give it a try and share my experience here. Thank you Tim.

Andreas Borkenhagen December 9, 2014

The Jenkins job that I'am using to retrieve information about the Pull Requests needs 2 seconds to complete. Thats absolutely acceptable.

TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2014

Nice one! Thanks for sharing.

0 votes
Pawel Nowicki June 27, 2019

The rest point 

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests

Has a section for merge conflicts, 

In the json output look for

"properties": {
    "openTaskCount": 0,
    "resolvedTaskCount": 0,
    "mergeResult": {
        "outcome": "CONFLICTED",
        "current": true
    }
},

0 votes
Aritra Chakraborty June 4, 2018

Link: https://community.atlassian.com/t5/Bitbucket-questions/REST-API-how-to-check-if-a-PR-has-conflict-s/qaq-p/716529

[Also copying the content in case the link becomes unavailable] 

Hey,

So was in the same pinch, checked source code of the pull request html page and found out that there is indeed an endpoint for checking conflicts. 

And that is *Drumroll please*

https://bitbucket.org/api/1.0/repositories/<org_or_profile>/<repo_name>/pullrequests/<pull_request_id>/conflict-status

For example I got the pull request id from:

https://api.bitbucket.org/2.0/repositories/<org_or_profile>/<repo_name>/pullrequests/?fields=values.id

Then used that ID in the above conflict-check endpoint. 

Cheers! 

Andreas Borkenhagen June 4, 2018

Hi Aritra,

thanks for trying to help in this case. I cannot open the link you posted even now, but it looks like the conent is for Bitbucket Cloud? The question was for Bitbucket Server and this resource doesn't exist for Bitbucket Server.

We now use a Git merge driver to detect conflicts in pull requests.

Best regards,
Andreas Gondek

Aritra Chakraborty June 4, 2018

Oh, sorry man. There was one trailing space after the URL. Anyway, Yeah thought the api endpoints will be there with a little variation. 

Can you check the

/conflict-status

is there or not, using your format of the request url? The funny thing is in the bitbucket cloud also the v1 REST api /pullrequests endpoint is not there.. but /pullrequests/ID/conflict-status is there. 

Anyway, sorry if I couldn't help you out. It seemed that it was a feasible and more than likely probable solution

Cheers,

Aritra

Andreas Borkenhagen June 5, 2018

I tested it:

 

{
    "message": "null for uri: ***/pull-requests/27/conflict-status",
    "status-code": 404
}

Bitbucket Cloud and Bitbucket Server don't share any code base, they are fully independent applications.

For this case the merge driver is the best solution, using the REST API was a totally wrong approach.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events