我正在尝试找出一种在TFS2012中查找代码审查请求/响应项的详细信息的方法。
我可以通过以下方式查询所有代码审查请求/响应项:
const string TfsUri = "http://mytfsserver:8080/tfs/Default ProjectCollection";
var tfs = new TfsTeamProjectCollection(new Uri(TfsUri));
var store = tfs.GetService<WorkItemStore>();
var versionStore = tfs.GetService<Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer>();
var queryText = "SELECT [System.Id],
FROM WorkItems
WHERE [System.WorkItemType] = 'Code Review Request'
or [System.WorkItemType] = 'Code Review Response'";
var query = new Query(store, queryText);
var result = query.RunQuery().OfType<WorkItem>();
这给了我一个WorkItem
类型的列表。当我循环遍历result.FirstOrDefault().Fields
属性时,它确实为我提供了一些关于ShelveSet的有用信息,这些信息与代码审查相关,也就是“关联上下文”。使用此信息,我可以查询ShelveSet:
var versionStore = tfs.GetService<VersionControlServer>();
var shelveset = versionStore.QueryShelvesets("someCodeReviewId_xxxx","someUserName");
这给了我一个ShelveSet
项目,但这就是我被卡住的地方。
我已经研究了Microsoft.TeamFoundation.CodeReview.Components
和Microsoft.TeamFoundation.CodeReview.Controls
库提供的Microsoft.TeamFoundation.CodeReview
名称空间,但这对我也没有进一步的帮助。
我的问题是:我如何通过TFS找到在代码审查期间对ShelveSet所做的实际注释(包括常规注释和文件注释)?
发布于 2013-05-08 15:32:53
我没有代码示例,但根据this discussion的说法,您应该能够使用Microsoft.TeamFoundation.Discussion.Client名称空间中的功能获得代码审查注释。
具体地说,可以通过DiscussionThread类访问注释。而且您应该能够使用IDiscussionManager查询讨论。
发布于 2013-10-30 03:19:27
我们有了从TFS中提取代码评审注释的新需求,下面是我们实现的一个简短示例。必须通过另一种方法查询workItemId。您甚至可以在Visual Studio中或通过UI中的TFS查询来查找它。这是可用内容和我们正在使用的内容的一小部分。我找到this link to be helpful after digging through MSDN了。
public List<CodeReviewComment> GetCodeReviewComments(int workItemId)
{
List<CodeReviewComment> comments = new List<CodeReviewComment>();
Uri uri = new Uri(URL_TO_TFS_COLLECTION);
TeamFoundationDiscussionService service = new TeamFoundationDiscussionService();
service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri));
IDiscussionManager discussionManager = service.CreateDiscussionManager();
IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemId, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null);
var output = discussionManager.EndQueryByCodeReviewRequest(result);
foreach (DiscussionThread thread in output)
{
if (thread.RootComment != null)
{
CodeReviewComment comment = new CodeReviewComment();
comment.Author = thread.RootComment.Author.DisplayName;
comment.Comment = thread.RootComment.Content;
comment.PublishDate = thread.RootComment.PublishedDate.ToShortDateString();
comment.ItemName = thread.ItemPath;
comments.Add(comment);
}
}
return comments;
}
static void CallCompletedCallback(IAsyncResult result)
{
// Handle error conditions here
}
public class CodeReviewComment
{
public string Author { get; set; }
public string Comment { get; set; }
public string PublishDate { get; set; }
public string ItemName { get; set; }
}
https://stackoverflow.com/questions/16063271
复制相似问题