簡體   English   中英

獲取簽入的TFS關聯工作項(非變更集)

[英]Get TFS associated work item of a checkin (not changeset)

我正在為TFS創建服務器端代碼審查策略,並且當前使它適用於通過Visual Studio運行的任何簽入,但是當有人嘗試通過Web UI簽入時,該策略不起作用。

該策略在簽入中尋找一個關聯的工作項目,然后在該工作項目中進行瀏覽以確認其滿足特定要求。 我可以通過Visual Studio Check in的獲取相關的工作項

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獲取數據,但是我無法在線找到有關如何獲取試圖處理的簽入信息的任何信息。

如您所見,Web編輯體驗使用了一組不同的API。 當使用較新的API時,服務器端策略顯然不會得到處理,因為服務器端插件是受支持的(但並非真正推薦的)標題已棄用的功能。

因此,基本上,您的政策不適用於Web UI,也沒有辦法實現。 您可以建議Microsoft通過在UserVoice上發布一些內容來增加支持,僅此而已。

暫無
暫無

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

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