Is there a way to get the equivalent of a git diff on a pull request in Azure DevOps? - Stack Overflow

GitHub has and endpoint like this {Name}{repoName}pulls{prId} that will return a git diff on a pull

GitHub has and endpoint like this /{Name}/{repoName}/pulls/{prId} that will return a git diff on a pull request if you set the Accept request header to application/vnd.github.diff

diff --git a/README b/README
index c57eff55..980a0d5f 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-Hello World!
\ No newline at end of file
+Hello World!

Does Azure DevOps have a similar endpoint that I can request to get the git diff? If not, are there any ideas to how I could possible generate the diff?

I've tried different things without success. For example as suggested here but ended up with error messages like "The controller for path '/xxx/_apis/git/repositories/yyy/pullRequests/zzz/diffs' was not found or does not implement IController."

And the MS documentation for the rest API does not seem to have an example that returns the diff, but only a list of changed files .1&tabs=HTTP#examples

GitHub has and endpoint like this https://api.github/repos/{Name}/{repoName}/pulls/{prId} that will return a git diff on a pull request if you set the Accept request header to application/vnd.github.diff

diff --git a/README b/README
index c57eff55..980a0d5f 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-Hello World!
\ No newline at end of file
+Hello World!

Does Azure DevOps have a similar endpoint that I can request to get the git diff? If not, are there any ideas to how I could possible generate the diff?

I've tried different things without success. For example as suggested here https://techcommunity.microsoft/discussions/azure/azure-git-get-the-pr-difference-in-global-diff-format/4294686 but ended up with error messages like "The controller for path '/xxx/_apis/git/repositories/yyy/pullRequests/zzz/diffs' was not found or does not implement IController."

And the MS documentation for the rest API does not seem to have an example that returns the diff, but only a list of changed files https://learn.microsoft/en-us/rest/api/azure/devops/git/diffs/get?view=azure-devops-rest-7.1&tabs=HTTP#examples

Share Improve this question asked Jan 31 at 9:52 Simon KSimon K 3153 silver badges14 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

There is no Azure DevOps REST API can get the differences of contents for modified files on a pull request.

The current documented Azure DevOps REST API for Git can only get the list of all modified files on a pull request. for example, you can use the API "Pull Request Iteration Changes - Get" to list all the modified files from all changes/iterations on a pull request.

If your projects really need such an API, I recommend you try to report a feature request on Developer Community. This will make it more convenient for the Azure DevOps engineer teams to receive and understand your ideas. And your feedback also could be helpful for improving the Azure DevOps products.


There is not such an endpoint in ADO.

Here's is a workaround that I have made.

If the server, running the code has git, I just use the source and target commit id's to run a git diff

// Get the commit id's
var sourceCommitId = pullRequest.LastMergeSourceCommit.CommitId;  
var targetCommitId = pullRequest.LastMergeTargetCommit.CommitId;
// And then run git diff...
var commitRange = $"{targetCommitId}..{sourceCommitId}";
var process = new Process
{
  StartInfo = new ProcessStartInfo
  {
    FileName = "git",
    Arguments = $"diff {commitRange}",
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    WorkingDirectory = targetFolder
    }
};
           
process.Start();
var gitDiff = process.StandardOutput.ReadToEnd();
process.WaitForExit();

The above assumes that git is on the computer and you've first made a git clone on the repository

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745270551a4619718.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信