【问题标题】:Get TFS associated work item of a checkin (not changeset)获取签入的 TFS 相关工作项(不是变更集)
【发布时间】: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


【解决方案1】:

如您所见,网络编辑体验使用了一组不同的 API。使用较新的 API 时,服务器端策略显然不会得到处理,因为服务器端插件是一种受支持但并非真正推荐的功能。

因此,基本上,您的策略不适用于 Web UI,并且无法实现。您可以建议 Microsoft 通过在 UserVoice 上发布一些内容来增加支持,但仅此而已。

【讨论】:

    猜你喜欢
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    相关资源
    最近更新 更多