簡體   English   中英

在TFS2013中為代碼檢查通知創建自定義簽入后策略

[英]Creating custom after check-in policy in TFS2013 for code review notifications

我知道我們可以在TFS 2013中創建自定義簽入策略,該策略將限制用戶簽入代碼而無需進行代碼審查。

我公司對開發人員的要求是,我必須開發將特定文件(數據庫更新)檢查到TFS的東西,然后將電子郵件通知發送給一組高級開發者進行代碼檢查。 此外,電子郵件通知還應告知上次執行代碼審查的時間以及執行者。

關於如何解決這個問題的任何想法。 過去,我創建了一個在簽入之前檢查文件有效性的策略,我曾使用PolicyBase和Evaluate方法來執行此操作,但我困惑於一旦簽入成功,我可以陷阱哪種類/方法來放置我的代碼。

除了為文件有效性而編寫的代碼外,我沒有任何代碼。 辦理入住手續后,我找不到任何有用的信息。 或者,這可以在服務器本身上配置?

代替簽入策略,您可以創建一個偵聽器來偵聽CheckInEvent。 觸發事件后,發出通知。 這些服務器端插件正在實現ISubscriber接口 ,請參閱此博客文章如何編寫和調試它們。

這是此博客中的代碼,顯示了響應Check-in事件的示例代碼實現,您可以參考它:

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) };
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM