简体   繁体   English

有没有办法通过 Azure Devops API 获取提交的原始差异?

[英]Is there a way to get the raw diff of a commit via the Azure Devops API?

As part of our application, we're building an ability to integrate with Azure DevOps' REST API. One key component that we're interested in is being able to see actual diffs of specific commits, so that we can look at and analyze the line content.作为我们应用程序的一部分,我们正在构建与 Azure DevOps' REST API 集成的能力。我们感兴趣的一个关键组件是能够看到特定提交的实际差异,以便我们可以查看和分析行内容。 We've already created this integration for GitHub, GitLab, and Bitbucket, and each time it was easy: There's a fairly simple diff endpoint for each that takes in a specific commit ID and diffs it (sometimes with a specific parent commit).我们已经为 GitHub、GitLab 和 Bitbucket 创建了这个集成,每次都很简单:每个都有一个相当简单的差异端点,它接受特定的提交 ID 并对其进行差异化(有时与特定的父提交)。

I've not had much luck finding this same functionality in Azure DevOps, however: The diffs endpoint has some data related to this, but it is really just an overview of which files changed and the high-level nature of those changes, along with the IDs of specific blobs that represent the files in each state (before and after).然而,我在 Azure DevOps 中找到相同功能的运气并不好:diffs 端点一些与此相关的数据,但它实际上只是对更改了哪些文件以及这些更改的高级性质的概述,以及表示每个 state(之前和之后)中文件的特定 blob 的 ID。

It's theoretically possible to use those blobs to manually construct what I'm after, and indeed I've been able to query for the before and after blobs to get a diff on each file.理论上可以使用这些 blob 手动构建我想要的内容,事实上我已经能够查询之前之后的 blob 以获得每个文件的差异。 But that's two separate endpoint queries per file -- take a twenty-file commit, and suddenly we'd need 40 API calls just to construct a reasonable diff.但这是每个文件两个单独的端点查询——提交 20 个文件,突然间我们需要 40 次 API 调用来构造一个合理的差异。 That doesn't really fit our performance needs, unfortunately.不幸的是,这并不能真正满足我们的性能需求。

Is there a separate API endpoint or technique that lets us get to the raw diff?是否有单独的 API 端点或技术让我们了解原始差异? It doesn't need to be a raw diff a la git diff directly, just anything that lets us see the before and after state of each line (rather than each file) with minimal API calls (preferably just one).它不需要直接是git diff的原始差异,只需让我们看到每(而不是每个文件)的 state 之前和之后的任何东西,只需最少的 API 调用(最好只有一个)。 I've done much scouring through the docs and here on StackOverflow, and not found anything that accomplishes this.我已经通过文档和 StackOverflow 上的此处进行了大量搜索,但没有找到任何可以实现此目的的东西。

There is no existing Rest API to meet your needs.没有现成的Rest API满足您的需求。 But you could refer to the following steps to get the content of the git diff.但是您可以参考以下步骤获取git diff的内容。

Step1: You could use the Rest API to get the commit id .第 1 步:您可以使用 Rest API 获取提交 ID

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.0

Step2: You could use the Rest API to get the commit by commit id .第 2 步:您可以使用 Rest API 通过提交 ID 获取提交

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?changeCount={changeCount}&api-version=5.0

In the Rest API Result, you need to record the value of “parentsid”, “path” .在 Rest API Result中,需要记录“parentsid”、“path”的值。

Step3: You could use the following API to get the diff content. Step3:您可以使用以下 API 获取差异内容。

Post https://dev.azure.com/Organization/Project /_api/_versioncontrol/fileDiff?__v=5&diffParameters={value}&repositoryId={repositoryid}

The {value} is Json type. {value} 是 Json 类型。

Here is an example:这是一个例子:

{"originalPath":"filepath","originalVersion":"Parentsid","modifiedPath":"filepath","modifiedVersion":"commitid","partialDiff":true,"includeCharDiffs":true}

You could add the value to the API URL.您可以将该值添加到 API URL。

Then run the API and the result will contains the git diff content.然后运行 API,结果将包含 git diff 内容。 (2 means remove, 1 means add) (2表示删除,1表示添加)

Here is a result sample:这是一个结果示例:

API 结果

This is the ticket I refer to, hope it helps you.这是我参考的ticket ,希望对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM