Forum Discussion

chamidu_sumanasekara's avatar
chamidu_sumanasekara
Copper Contributor
Nov 13, 2024

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 

 

  • chamidu_sumanasekara 

    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.1

    2. 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.1

    For a .diff format, parse and convert the JSON response

  • 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

  • rahul_chouhan's avatar
    rahul_chouhan
    Copper 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/{organization_name}/repo_name/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.

Resources