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

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

arturkremens January 23, 2020

Hey.

How to get Information about PR conflict ith REST Api? 

1 answer

0 votes
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 23, 2020

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
AUG Leaders

Atlassian Community Events