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

REST API v2: It it possible to get Information about PR conflict

Hey.

How to get Information about PR conflict ith REST Api? 

1 answer

0 votes

Hello @arturkremens,

Thanks for reaching out.

You can list files involved in the pull request using diffstat endpoint:

/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/diffstat

Diff stat responses contain a record for every path modified by the PR. The field status will contain information about a conflict in that file diff, if there are any. Example response payload (I excluded some fields to make it smaller):

{
"values": [
{
"status": "merge conflict",
"old": {
"path": "z.txt",
"type": "commit_file"
},
"lines_removed": 0,
"lines_added": 4,
"new": {
"path": "z.txt",
"type": "commit_file"
},
"type": "diffstat"
}
],
"page": 1,
"size": 1
}

Now, if you need to find exact conflicting chunks you can get the diff of the PR in question using diff endpoint and get the unified diff back:

/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/diff

It will contain markers for conflicts. Example response payload:

diff --git a/z.txt b/z.txt
index 443c26a..d2eab11 100644
--- a/z.txt
+++ b/z.txt
@@ -1,3 +1,4 @@
+<<<<<<< destination:eace7ee877e62e0d85d6b59b6f3bcc8d6e63ca93
Hello world
Hello world
Hello world
@@ -9,3 +10,6 @@ Hello world
Hello world
Hello world
Hello world
+=======
+What if
+>>>>>>> source:92bd412da9b48d7bc34a5e295a073a20284d17fa

You can also limit it down to just one file by adding path query parameter:

/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/diff?path={path_to_file}

I hope this is what you're after. Let me know if you have any questions.

Cheers,
Daniil

Suggest an answer

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

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,826 views 0 7
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