【发布时间】:2019-05-25 16:05:04
【问题描述】:
我正在为 TFS 创建一个服务器端代码审查策略,目前它适用于通过 Visual Studio 运行的任何签入,但是当有人尝试通过 Web UI 签入时它不起作用。
该策略在签入时查找关联的工作项,然后查看该工作项以确认其符合特定要求。我可以从 Visual Studio 签入通过
获取相关的工作项public EventNotificationStatus ProcessEvent(IVssRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
{
statusCode = 0;
statusMessage = string.Empty;
properties = new ExceptionPropertyCollection();
var checkinNotification = notificationEventArgs as CheckinNotification;
if (notificationType == NotificationType.DecisionPoint && notificationEventArgs is CheckinNotification)
{
bool isNullComment = false;
bool isCheckinContains = false;
var service = requestContext.GetService<ILocationService>();
TfsTeamProjectCollection tfsTeamProjectCollection = new TfsTeamProjectCollection(GetTfsUri(requestContext));
WorkItemStore workitemStore = tfsTeamProjectCollection.GetService<WorkItemStore>();
var changes = checkinNotification.GetSubmittedItems(requestContext);
isCheckinContains = changes.Any(change => change.ToUpper().Contains("$/"));
if (isCheckinContains)
{
isNullComment = string.IsNullOrEmpty(checkinNotification.Comment.ToString());
//Read all associated workitem id's
var assoWorkItems = checkinNotification.NotificationInfo.WorkItemInfo.Select(x => x.Id);
}
}
}
但是,这不适用于 Web UI。在针对 Visual Studio 和 Web UI 运行代码时,我注意到的主要区别是请求上下文引用了一个非常不同的 URL。
Visual Studio 请求上下文 URL:http://localhost:8080/tfs/DefaultCollection/VersionControl/v5.0/repository.asmx
Web Ui 请求上下文:http://localhost:8080/tfs/DefaultCollection/_apis/tfvc/changesets
我认为我需要使用不同的命名空间和方法来使用 Web UI 访问签入内的信息。
我一直在尝试使用“Microsoft.VisualStudio.Services.WebApi”命名空间从 Web UI 获取数据,但我在网上找不到任何关于如何获取正在尝试处理的签入信息的信息
【问题讨论】:
-
“不是变更集”是什么意思? 签入是用户执行的创建变更集的操作。没有可以检索的称为“签入”的实体。
标签: c# visual-studio tfs tfvc