Forum Discussion
Azure Git get the PR difference in global diff format
Hi,
I am looking for an API or workaround to get the difference of a PR in global diff format.
a functionality similar to github
/repos/{repo name}/pulls/{PR number}.diff
6 Replies
Hi, Azure DevOps does not expose the exact same .diff style endpoint as GitHub for pull requests. The usual route is to use the Git REST APIs to get the PR iterations and changes, or fetch the source and target refs locally and generate the diff with Git. If you need standard unified diff output, generating it locally is often the cleanest approach.
- rahul_chouhanCopper Contributor
In above replied we will get response in the form of changes in pr like addition, deletion , But we need response in form diff format changed files content which are belongs to pull request .
In github we will
request : https://github.com/Accelerite-Business-Unit-PSL/psl_test_repo_1/pull/16.diff
response:
diff --git a/file1.txt b/file1.txt new file mode 100644 index 0000000..f69e1d1 --- /dev/null +++ b/file1.txt @@ -0,0 +1,7 @@ +sample 1 +123 + +456 +789 +def +123 \ No newline at end of file diff --git a/file2.txt b/file2.txt new file mode 100644 index 0000000..dd6937b --- /dev/null +++ b/file2.txt @@ -0,0 +1,6 @@ +sample 1 +123 +456 +789 +def +123 \ No newline at end of file diff --git a/file3.txt b/file3.txt new file mode 100644 index 0000000..fc9be2a --- /dev/null +++ b/file3.txt @@ -0,0 +1,5 @@ +sample 1 +123 +456789 +def +123 diff --git a/random.txt b/random.txt new file mode 100644 index 0000000..f73bbf5 --- /dev/null +++ b/random.txt @@ -0,0 +1,6 @@ +abc +123 +456 +789 +def +123 \ No newline at end of file diff --git a/tests/bin/external_trogdor_command_example.py b/tests/bin/external_trogdor_command_example.py index a4b801a..42afc05 100644 --- a/tests/bin/external_trogdor_command_example.py +++ b/tests/bin/external_trogdor_command_example.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # test data addition +# new test data # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership.
Try this under Azure DevOps:
curl -u {username}:{personal_access_token} \
-H "Accept: application/json" \
https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/diffs?api-version=6.0- balasubramanimIron Contributor
To get a PR diff in Azure DevOps
1. Get PR Diff JSON - Use this API to get the diff in JSON format
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}/diff?api-version=7.1-preview.12. Alternative - Compare branches directly
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/diffs/commits?baseVersion={targetBranch}&targetVersion={sourceBranch}&api-version=7.1-preview.1For a .diff format, parse and convert the JSON response
- asuraceCopper Contributor
unfortunately both approach don't work for me.
It looks like the api changes.
Any suggestion?
- wangnicole
Microsoft
Have you got the answer? I have this issue as well.