在Visual Studio中,我通常通过Source Control Explorer打开Changeset,通过Go to Changeset打开Changeset,然后在Team Explorer窗口中选择Actions-> Request Review,其中显示Changeset。
在C#中,我有代码可以让我查询所有变更集:
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
vcs.QueryHistory(...)
现在我有一个Changeset实例列表。 如何实现“请求审核”功能?
我尝试创建代码审核请求,如下所示:
Project teamProject = _workItemStore.Projects["XYZ"];
WorkItemType workItemType = teamProject.WorkItemTypes["Code Review Request"];
var request = new WorkItem(workItemType) { Title = "Testreview" };
request.Fields["Associated Context Type"].Value = "Changeset";
request.Fields["Associated Context"].Value = "5169";
request.Fields["Assigned To"].Value = "Joe Doe";
request.AreaPath = @"XYZ\Test";
request.IterationPath = @"XYZ\Test\1.5";
request.Save();
这会创建一个非常类似于Visual Studio中的代码审查请求,但无法执行Code Review。我错过了什么?
答案 0 :(得分:1)
据我所知,您正在使用软件包Microsoft.TeamFoundationServer.ExtendedClient
。您的工作方向正确,但是还需要一个名为Code Review Response
的工作项目。有关创建这两个工作项的信息,请参阅博客文章Tfs Extensibility - Automatically Create Code Reviews on Checkin。这篇文章对工作项字段值有很大帮助。这是帖子中的基本代码部分:
var type = project.WorkItemTypes["Code Review Response"];
var workItem = new WorkItem(type) { Title = checkinNotification.Comment };
workItem.Fields["System.AssignedTo"].Value = "Betty"; //todo pick someone better
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
var result = workItem.Validate();
foreach (Field item in result)
{
//insert some form of logging here
}
workItem.Save();
var responseId = workItem.Id;
type = project.WorkItemTypes["Code Review Request"];
workItem = new WorkItem(type) { Title = checkinNotification.Comment };
workItem.Fields["System.AssignedTo"].Value = checkinNotification.ChangesetOwner.DisplayName;
workItem.Fields["Microsoft.VSTS.CodeReview.ContextType"].Value = "Changeset";
workItem.Fields["Microsoft.VSTS.CodeReview.Context"].Value = checkinNotification.Changeset;
workItem.Fields["System.AreaPath"].Value = project.Name; //todo: may want a better location from source path
workItem.Fields["System.IterationPath"].Value = project.Name;
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
WorkItemLinkTypeEnd linkTypeEnd = workitemStore.WorkItemLinkTypes.LinkTypeEnds["Child"];
workItem.Links.Add(new RelatedLink(linkTypeEnd, responseId));
workItem.Save();
有关代码审阅的实际注释使用了讨论服务(请参见Creating code review request through API)。有关讨论服务的Microsoft文档:Microsoft.TeamFoundation.Discussion.Client。 在此命名空间中,查看类DiscussionThread
我希望这会有所帮助。