0

I know we can create custom check-in policy in TFS 2013 that will restrict the user to check-in the code without code review.

I have a requirement in our company for the developers where in I have to develop something where a specific file (database update) is checked to TFS, then a email notifications to be sent to a set of senior developers for code review. Also, the email notification should tell when was last code review been performed and by whom.

Any idea on how to go about solving this problem. In past I have created a policy to check for a file validity before check-in, I have used PolicyBase and Evaluate method to do so, I am confused which class/method can i trap to put my code once check-in is successful.

I have no code except the code that wrote for file validity. I couldn't find any helpful post on after check-in policies. Or, this can be configurable on server itself?

Sri Reddy
  • 6,832
  • 20
  • 70
  • 112

1 Answers1

0

Instead of Checkin policy, you can create a listener to listen to the CheckInEvent. Once the event is triggered, send out the notification. Those server-side plug-ins are implementing the ISubscriber interface, see this blog post how to write and debug them.

Here is a code from this blog shows a sample implementation of code responding to a Check-in event, you can refer to it:

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) };
        }
    }
}
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39