【问题标题】:Creating custom after check-in policy in TFS2013 for code review notifications在 TFS2013 中为代码审查通知创建自定义签入后策略
【发布时间】:2015-12-22 17:30:37
【问题描述】:

我知道我们可以在 TFS 2013 中创建自定义签入策略,这将限制用户签入代码而无需进行代码审查。

我公司对开发人员有一个要求,我必须开发一些东西,将特定文件(数据库更新)检查到 TFS,然后将电子邮件通知发送给一组高级开发人员进行代码审查。此外,电子邮件通知应说明上次代码审查的时间以及由谁执行。

关于如何解决这个问题的任何想法。过去,我创建了一个策略来在签入之前检查文件的有效性,我使用 PolicyBase 和 Evaluate 方法来执行此操作,我很困惑一旦签入成功,我可以捕获哪个类/方法来放置我的代码。

除了为文件有效性而编写的代码外,我没有其他代码。我在登记入住政策后找不到任何有用的帖子。或者,这可以在服务器本身上进行配置?

【问题讨论】:

    标签: visual-studio checkin-policy


    【解决方案1】:

    您可以创建一个侦听器来侦听 CheckInEvent,而不是 Checkin 策略。触发事件后,发出通知。这些服务器端插件正在实现ISubscriber interface,请参阅this blog 发布如何编写和调试它们。

    这是来自this blog的代码,显示了响应签入事件的代码示例实现,您可以参考:

    namespace Sample.SourceControl.Server.PlugIns
    {
        public class CodeCheckInEventHandler : ISubscriber
        {
            public string Name
            {
                get { return "CodeCheckInEventHandler"; }
            }
    
            public SubscriberPriority Priority
            {
                get { return SubscriberPriority.Normal; }
            }
    
            public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out Microsoft.TeamFoundation.Common.ExceptionPropertyCollection properties)
            {
                statusCode = 0;
                properties = null;
                statusMessage = String.Empty;
                try
                {
                    if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
                    {
                        CheckinNotification ev = notificationEventArgs as CheckinNotification;
                        TeamFoundationApplication.Log(string.Format("New Changeset was checked in by {0}. ID: {1}, comments: {2}", ev.ChangesetOwnerName, ev.Changeset, ev.Comment), 123, System.Diagnostics.EventLogEntryType.Information);
                    }
                }
                catch (Exception ex)
                {
                    TeamFoundationApplication.LogException("Sample.SourceControl.Server.PlugIns.CodeCheckInEventHandler encountered an exception", ex);
                }
                return EventNotificationStatus.ActionPermitted;
            }
    
            public Type[] SubscribedTypes()
            {
                return new Type[1] { typeof(CheckinNotification) };
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-13
      • 2017-01-08
      • 2010-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多