git的访问消息如何从Microsoft.TeamFoundation.WorkItemTracking.Client提交?

我在内部使用TFS 2017 Update 1。我在提交的日志注释中使用#ID,以便将(用户故事,任务等的)工作项ID与源代码的GIT提交相关联。它正常工作(我可以从workitem界面中看到要提交的链接)。

我想将TFS SDK API与tfs聚合器一起使用,以便更好地管理GIT提交(例如,当程序员完成特定的自定义git提交消息时,自动过渡到自定义工作状态)。

如何从microsoft.TeamFoundation.WorkItemTracking.Client访问git commit的消息/日志,以便能够解析除here之外的自定义消息(例如,“修复#123”或“关闭#123”) ?

pengsy333 回答:git的访问消息如何从Microsoft.TeamFoundation.WorkItemTracking.Client提交?

您不能仅通过WorkItemHttpClient来获得提交注释,可以与GitHttpClient一起获得。首先,使用WorkItemHttpClient获取工作项链接,然后使用GitHttpClient获取提交ID和评论。

一个工作示例:

VssClientCredentials cred = new VssClientCredentials();
VssConnection tfs = new VssConnection(new Uri("http://tfs-server:8080/tfs/collection"),cred);
var workItemClient = tfs.GetClient<WorkItemTrackingHttpClient>();
var gitClient = tfs.GetClient<GitHttpClient>();
int workItemId = 1213;

var workItem = workItemClient.GetWorkItemAsync("Project-Name",workItemId,expand: WorkItemExpand.Relations).Result;
// We need to retrieve the commit id from the links,debug the following line to understand what I did
var commitId = wit.Relations.Where(r => r.Url.Contains("Git")).FirstOrDefault().Url.Split('%')[2].Remove(0,2);
var commit = gitClient.GetCommitAsync("Project-Name",commitId,"Repo-Name").Result;
string comment = commit.comment;

顺便说一句,您不能使用Fixes #123语法,因为TFS 2017不支持该语法。

本文链接:https://www.f2er.com/3103875.html

大家都在问