VSTS Rest API从Changeset API返回特定项 [英] VSTS Rest API return specific item from Changeset API

查看:120
本文介绍了VSTS Rest API从Changeset API返回特定项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用REST API来返回从特定变更集更改的所有文件,我真正想做的只是返回具有已知路径的特定项目的URL属性.

I'm calling the REST API to return all of the files that are changed from a particular changeset, what I really want to do is just return the URL property of a specific item that has a known path.

所以我现在拥有的是Changeset API调用

So what I have now is the Changeset API calling

https://someplace.visualstudio.com/_apis/tfvc/changesets/19483/changes

返回类似

{
  "count": 10,
  "value": [
    {
      "item": {
        "version": 19483,
        "size": 882,
        "hashValue": "ACWU0KSlO+jbsSJB5IwU4Q==",
        "path": "$/WaveDatabases/MasterData/Custom Scripts/2017-07-17-120218 28 user/MigrationScript.sql",
        "url": "https://someplace.visualstudio.com/_apis/tfvc/items/$/WaveDatabases/MasterData/Custom%20Scripts/2017-07-17-120218%2028%20user/MigrationScript.sql?versionType=Changeset&version=19483"
      },
      "changeType": "add, edit, encoding"
    },
    {
      "item": {
        "version": 19483,
        "size": 55,
        "hashValue": "Wur9rYW/rRYcvRWoVUZO7A==",
        "path": "$/WaveDatabases/MasterData/Custom Scripts/2017-07-17-120218 28 user/ReadonlyMetadata.json",
        "url": "https://someplace.visualstudio.com/_apis/tfvc/items/$/WaveDatabases/MasterData/Custom%20Scripts/2017-07-17-120218%2028%20user/ReadonlyMetadata.json?versionType=Changeset&version=19483"
      },
      "changeType": "add, edit, encoding"
    },
    {
      "item": {
        "version": 19483,
        "size": 379,
        "hashValue": "vHCQymsTXiZVuLMpeoShNg==",
        "path": "$/WaveDatabases/MasterData/Tables/Cust.test.sql",
        "url": "https://someplace.visualstudio.com/_apis/tfvc/items/$/WaveDatabases/MasterData/Tables/Cust.test.sql?versionType=Changeset&version=19483"
      },
      "changeType": "edit"
    }
  ]
}

这将返回该变更集中所有文件的数组.我知道在这个变更集中,在某个未知文件夹下总会有一个名为MigrationScript.sql的文件.我想要做的是找到一种方法,该方法将仅在其中包含MigrationScript.sql的数组中返回该1个元素.另外,我只想返回该1元素的url属性.

This returns an array of all of the files in that changeset. I know that in this changeset there will always be a file called MigrationScript.sql underneath some unknown folder. What I want to do is to find a way that will just return that 1 element in the array that has the MigrationScript.sql in it. Additional I want to only return the url property for that 1 element.

这需要通过URL完成,因为要使用此工具,我无法编写代码来解析结果.

This needs to be accomplished through the URL because of the tools that want to use this I can't write code to parse out the results.

推荐答案

您无法直接通过Changeset REST API URL完成此操作.

You can’t accomplish it through the Changeset REST API URL directly.

您可以构建一个Web API应用程序,以使用REST API检索数据,然后返回所需的相应数据,然后您可以在该工具中指定Web API URL.

You can build a web API app to retrieve data by using REST API, then return the corresponding data that you want, after that you can specify web API URL in that tool.

简单代码(使用 Microsoft Team Foundation Server扩展客户端程序包)

var u = new Uri("https://starain.visualstudio.com");
     VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[personal access token]"));           
 var connection = new VssConnection(u, c);
            var tfvcClient = connection.GetClient<TfvcHttpClient>();
           var changes= tfvcClient.GetChangesetChangesAsync(id: 1130).Result;
            foreach(var currentChange in changes.Where(ci=>ci.Item.Path.EndsWith("UnitTest1.cs")))
            {
                string url = currentChange.Item.Url;
            }

这篇关于VSTS Rest API从Changeset API返回特定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆