【问题标题】:How to associate reviewed Work Item while check in programmatically in TFS如何在 TFS 中以编程方式签入时关联已审核的工作项
【发布时间】:2016-11-14 17:06:23
【问题描述】:

我创建了 TFS 2012 服务器端事件处理程序来执行代码审查策略。 我能够为代码审查请求和响应创建工作项。但 完成审核过程后,当我要签入已审核的代码时,在 Visual Studio 2013 的团队资源管理器窗口的相关工作项部分中无法看到已审核的工作项。以下是我的代码,

var workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
WorkItemType wiType = workItemStore.Projects[0].WorkItemTypes["Code Review Request"];
WorkItem workItem = new WorkItem(wiType);
workItem.Fields["System.AssignedTo"].Value = "XXXXXX"; 
//ev.ChangesetOwner.DisplayName;
workItem.Fields["Microsoft.VSTS.CodeReview.ContextType"].Value = "Shelveset";
workItem.Fields["Microsoft.VSTS.CodeReview.Context"].Value = shelveset.Name;
workItem.Fields["Microsoft.VSTS.CodeReview.ContextOwner"].Value = shelveset.OwnerName;
workItem.Fields["System.AreaPath"].Value = project.Name;
workItem.Fields["System.IterationPath"].Value = project.Name;
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
workItem.Fields["System.Description"].Value = "Code Review Request  ";
workItem.Fields["System.Title"].Value = "Code Review Request " + System.DateTime.Now.ToString();
var invalidFields = workItem.Validate();
if (workItem.IsValid())
  workItem.Save();
var responseId = workItem.Id;
var type = workItemStore.Projects[0].WorkItemTypes["Code Review Response"]; 
workItem = new WorkItem(type);
workItem.Fields["System.AssignedTo"].Value = "xxxxxxxx"; 
workItem.Fields["System.AreaPath"].Value = project.Name; 
workItem.Fields["System.IterationPath"].Value = project.Name;
workItem.Fields["System.State"].Value = "Requested";
workItem.Fields["System.Reason"].Value = "New";
workItem.Fields["Microsoft.VSTS.Common.ReviewedBy"].Value = "xxxxxxxx";
workItem.Fields["System.Title"].Value = "Code Review Response " + System.DateTime.Now.ToString();
WorkItemLinkTypeEnd linkTypeEnd = workItemStore.WorkItemLinkTypes.LinkTypeEnds["Parent"];
workItem.Links.Add(new RelatedLink(linkTypeEnd, responseId));
if (workItem.IsValid())
  workItem.Save();

【问题讨论】:

  • 您的意思是要在签入期间将工作项链接到变更集吗?
  • 您要实现的详细流程是什么?您如何将 Code Review 请求与代码相关联?

标签: c# tfs


【解决方案1】:

似乎您没有将您的工作项链接到相关的更改。以下代码显示了如何执行此操作:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace APPI
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://xxx.xxx.xxx.xxx:8080/tfs/DefaultCollection";
            TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(url));
            WorkItemStore wis = ttpc.GetService<WorkItemStore>();
            VersionControlServer vcs = ttpc.GetService<VersionControlServer>();
            int wid = 82;
            int cid = 332;
            WorkItem wi = wis.GetWorkItem(wid);
            Changeset cs = vcs.GetChangeset(cid);
            ExternalLink el = new ExternalLink(wis.RegisteredLinkTypes["Fixed in Changeset"], cs.ArtifactUri.AbsoluteUri);
            wi.Links.Add(el);
            wi.Save();     
        }
    }
}

关于TFS - VS Extension: Add work item to pending changes via API 的类似问题,请查看此链接:C# Programmatically Checking in code changes with TFS API while associating the changeset to a Work Item

【讨论】:

猜你喜欢
  • 2011-02-20
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-28
  • 2015-04-29
  • 2011-11-29
相关资源
最近更新 更多