我正在尝试通过 TFS REST API 以编程方式获取与 Git Commit 相关的工作项。我没有在网上找到示例,但 tfs 门户网站似乎通过使用“associatedWorkItems”api 调用来获取此信息...
当我针对给定的 Git 提交导航到我的 TFS 门户时:
http://{instance}/{collection}/{project}/_git/{repository}/commit/{commitId}
如果我检查网络流量,我会看到一个 POST 调用:
http://{instance}/{collection}/{projectId}/_api/_versioncontrol/associatedWorkItems?__v=5
在请求中发送这些主体形式参数:
- repositoryId (GUID) - 我已经有了这个
- versions - 类似于 GC27a36707252ac9db742cc259a1018b9750d8e9a2(这是什么?)
- __RequestVerificationToken - API 防伪 token 。
此调用返回 __wrappedArray 集合中的关联工作项列表。
有没有办法从 TFS REST API 调用它?如果是这样,我在哪里可以获得版本和 RequestVerificationToken 参数值?
这与我之前的问题有关: Get latest Associated Work Items for Git Commit using TFS REST API
更新:我尝试了@PatrickLu-MSFT 建议将“IncludeWorkItems”参数传递给 GetcommitsAsync
,但仍将 WorkItems 返回为 null:
GitQueryCommitsCriteria crit = new GitQueryCommitsCriteria();
crit.IncludeWorkItems = true;
crit.Ids = new List<string>(){"27a36707252ac9db742cc259a1018b9750d8e9a2"};
var commitTest = gitClient.GetCommitsAsync(repo.Id, crit).Result.FirstOrDefault();
//commitTest.WorkItems == null
最佳答案
不幸的是,如前所述,目前还没有这种直接显示与 GIT 提交关联的工作项的 Rest API 能力。
这里还有一个相关的用户语音供大家引用:
Rest API - Ability to show work items associated with a GIT commit
您从使用的网络流量中看到的 API,可能是一种内部方式。也可以从API版本来判断,_v=5
5肯定不是目前发布的Rest API版本。
作为解决方法,您可以尝试使用 .Net Client 来完成类似的任务。
在 GitHttpClientBase.GetCommitsAsync 中指定 GitQueryCommitsCriteria.IncludeWorkItems = true
在 GitCommitRef.WorkItems
中返回关联的工作项。注意:IncludeWorkItems 和 WorkItems 都有 [EditorBrowsable(EditorBrowsableState.Never)] stash 了编辑建议。
关于c# - TFS Git Commit 网页 API 调用获取相关 WorkItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48462508/