Reputation: 305
GitHub has and endpoint like this https://api.github.com/repos/{orgName}/{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.com/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.com/en-us/rest/api/azure/devops/git/diffs/get?view=azure-devops-rest-7.1&tabs=HTTP#examples
Upvotes: 1
Views: 102
Reputation: 305
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
Upvotes: 0
Reputation: 13944
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.
Upvotes: 0