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

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.

1 answer

1 accepted

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

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.

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.

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.

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

Nice one! Thanks for sharing.

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

638 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot