Exemplo n.º 1
0
        public static string GetEventType(AzDOWorkItemUpdateTypes updateType)
        {
            string eventType;

            switch (updateType)
            {
            case AzDOWorkItemUpdateTypes.Create:
                eventType = "workitem.created";
                break;

            case AzDOWorkItemUpdateTypes.Update:
                eventType = "workitem.updated";
                break;

            case AzDOWorkItemUpdateTypes.Delete:
                eventType = "workitem.deleted";
                break;

            case AzDOWorkItemUpdateTypes.Restore:
                eventType = "workitem.restored";
                break;

            default:
                throw new NotImplementedException();
            }

            return(eventType);
        }
        public void CreateWebHook(string webHookLocation, AzDOWorkItemUpdateTypes updateType, Guid teamProjectId, string systemUniqueKey)
        {
            try
            {
                var eventType    = CreateWebHookSubscriptionRequest.GetEventType(updateType);
                var serviceHooks = ListSubscriptions().value
                                   .Where(o => o.publisherInputs.projectId == teamProjectId &&
                                          o.eventType == eventType &&
                                          o.consumerInputs.url.StartsWith(webHookLocation, StringComparison.InvariantCultureIgnoreCase));
                foreach (var serviceHook in serviceHooks)
                {
                    DeleteWebHook(serviceHook.id);
                }
                object request;
                switch (updateType)
                {
                case AzDOWorkItemUpdateTypes.Create:
                case AzDOWorkItemUpdateTypes.Update:
                    request = CreateWebHookSubscriptionRequest.CreateOrUpdateWorkItem(webHookLocation, updateType, teamProjectId, systemUniqueKey);
                    break;

                case AzDOWorkItemUpdateTypes.Delete:
                case AzDOWorkItemUpdateTypes.Restore:
                    request = CreateWebHookSubscriptionRequest.DeleteOrRestoreWorkItem(webHookLocation, updateType, teamProjectId, systemUniqueKey);
                    break;

                default:
                    throw new NotImplementedException();
                }
                Post($"/_apis/hooks/subscriptions?api-version=5.1", request);
            }
            catch (Exception ex)
            {
                string observeEx = ex.ToString();
                throw;
            }
        }
Exemplo n.º 3
0
        public static PayloadCreateOrUpdate CreateOrUpdateWorkItem(string webHookLocation, AzDOWorkItemUpdateTypes updateType, Guid teamProjectId, string systemUniqueKey)
        {
            var eventType = GetEventType(updateType);
            var result    = new PayloadCreateOrUpdate();

            result.eventType = eventType;
            result.publisherInputs.projectId = teamProjectId.ToString().ToLowerInvariant();
            result.consumerInputs.url        = webHookLocation;
            return(result);
        }