我在本地使用TFS 2017更新1。我在提交的日志注释中使用#ID,以便关联工作项ID (用户故事、任务等)。用GIT提交源代码。它可以正常工作(我可以从工作项界面看到提交的链接)。
我想使用TFS SDK API和tfs聚合器,以便更好地管理GIT提交(例如,当程序员完成特定的自定义git提交消息时,自动转换到工作项的自定义状态)。
如何从Microsoft.TeamFoundation.WorkItemTracking.Client访问git提交的消息/日志,以便能够解析除所描述的那些here之外的自定义消息(例如“修复#123”或“关闭#123")?
发布于 2019-11-14 20:05:05
你不能只用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语法,因为在TFS2017中不支持。
https://stackoverflow.com/questions/58853432
复制相似问题