从TFS工作项工件链接获取TFS GIT提交详细信息

时间:2017-09-25 21:16:32

标签: azure-devops tfs2015 azure-devops-rest-api

是否可以利用TFS或TS REST api通过利用工作项提交来获取GIT提交的详细信息" ArtifiactLink"网址是什么?

1 个答案:

答案 0 :(得分:3)

因此,您希望基于工作项工件链接获取详细提交信息(而工件链接类型包含提交)。

您可以使用两个REST API实现此目的,详细步骤如下:

1。 Get the work item with full expanded

GET https://{instance}/DefaultCollection/_apis/wit/workitems/{id}?api-version1.0&$expand=all

对于TFS2015,格式如下:

GET http://tfsServer:8080/tfs/DefaultCollection/_apis/wit/workitems?ids={id}&$expand=all&api-version=1.0

对于VSTS,格式如下:

GET https://account.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=7&$expand=all&api-version=1.0

2。获取上述工作项中链接的提交和相关回购

在step1 REST API的响应中搜索,获取relArtifactLinkurlvstfs:///Git/Commit开头的部分。网址格式为

vstfs:///Git/Commit/{project ID}%2F{repo ID}%2F{commit ID}

例如REST API响应的一部分:

{
   "rel": "ArtifactLink",
   "url": "vstfs:///Git/Commit/b959f22b-eeb7-40dc-b37e-986377eaa86f%2F4cfde261-fec3-451c-9d41-a400ba816110%2Fb3c3c5b8718f403402be770cb3b5912df7c64dd6",
   "attributes": {
      "authorizedDate": "2017-09-26T03:14:03.98Z",
      "id": 92,
      "resourceCreatedDate": "2017-09-26T03:14:03.98Z",
      "resourceModifiedDate": "2017-09-26T03:14:03.98Z",
      "revisedDate": "9999-01-01T00:00:00Z",
      "name": "Fixed in Commit"
    }
}

项目ID为b959f22b-eeb7-40dc-b37e-986377eaa86f,回购ID为2F4cfde261-fec3-451c-9d41-a400ba816110,提交ID为b3c3c5b8718f403402be770cb3b5912df7c64dd6

3。获取提交详细信息

使用您在第2步中获得的项目ID,repo ID和提交ID到get a single commit

GET https://{instance}/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version={version}

对于TFS 2015,格式如下:

GET http://tfsServer:8080/tfs/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version=1.0

对于VSTS,格式如下:

GET https://account.visualstudio.com/DefaultCollection/{project ID}/_apis/git/repositories/{repo ID}/commits/{commit ID}?api-version=1.0