public void GetGetByOrganizationIdOrProjectId()
        {
            RemoveData();

            _repository.Add(new WebHook {
                OrganizationId = TestConstants.OrganizationId, Url = "http://localhost:40000/test1", EventTypes = new[] { WebHookRepository.EventTypes.StackPromoted }
            });
            _repository.Add(new WebHook {
                OrganizationId = TestConstants.OrganizationId, ProjectId = TestConstants.ProjectId, Url = "http://localhost:40000/test", EventTypes = new[] { WebHookRepository.EventTypes.StackPromoted }
            });

            Assert.Equal(2, _repository.GetByOrganizationId(TestConstants.OrganizationId).Count);
            Assert.Equal(2, _repository.GetByOrganizationIdOrProjectId(TestConstants.OrganizationId, TestConstants.ProjectId).Count);
            Assert.Equal(1, _repository.GetByProjectId(TestConstants.ProjectId).Count);
        }
Пример #2
0
        public IHttpActionResult Promote(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            Stack stack = _stackRepository.GetById(id);

            if (stack == null || !CanAccessOrganization(stack.OrganizationId))
            {
                return(NotFound());
            }

            if (!_billingManager.HasPremiumFeatures(stack.OrganizationId))
            {
                return(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <WebHook> promotedProjectHooks = _webHookRepository.GetByProjectId(stack.ProjectId).Where(p => p.EventTypes.Contains(WebHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                return(NotImplemented("No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature."));
            }

            foreach (WebHook hook in promotedProjectHooks)
            {
                var context = new WebHookDataContext(hook.Version, stack, isNew: stack.TotalOccurrences == 1, isRegression: stack.IsRegressed);
                _webHookNotificationQueue.Enqueue(new WebHookNotification {
                    OrganizationId = hook.OrganizationId,
                    ProjectId      = hook.ProjectId,
                    Url            = hook.Url,
                    Data           = _webHookDataPluginManager.CreateFromStack(context)
                });
                // TODO: Add stats metrics for webhooks.
            }

            return(Ok());
        }
Пример #3
0
        public override void Process(EventContext ctx)
        {
            // if they don't have premium features, then we don't need to queue notifications
            if (!ctx.Organization.HasPremiumFeatures)
            {
                return;
            }

            _notificationQueue.EnqueueAsync(new EventNotification {
                Event        = ctx.Event,
                IsNew        = ctx.IsNew,
                IsCritical   = ctx.Event.IsCritical,
                IsRegression = ctx.IsRegression,
                //TotalOccurrences = ctx.Stack.TotalOccurrences,
                ProjectName = ctx.Project.Name
            }).Wait();

            // TODO: Get by organization id or project id.
            foreach (WebHook hook in _webHookRepository.GetByProjectId(ctx.Event.ProjectId))
            {
                bool shouldCall = hook.EventTypes.Contains(WebHookRepository.EventTypes.NewError) && ctx.IsNew ||
                                  hook.EventTypes.Contains(WebHookRepository.EventTypes.ErrorRegression) && ctx.IsRegression ||
                                  hook.EventTypes.Contains(WebHookRepository.EventTypes.CriticalError) && ctx.Event.Tags != null && ctx.Event.Tags.Contains("Critical");

                if (!shouldCall)
                {
                    continue;
                }

                Log.Trace().Project(ctx.Event.ProjectId).Message("Web hook queued: project={0} url={1}", ctx.Event.ProjectId, hook.Url).Write();

                _webHookNotificationQueue.EnqueueAsync(new WebHookNotification {
                    ProjectId = ctx.Event.ProjectId,
                    Url       = hook.Url,
                    Data      = WebHookEvent.FromEvent(ctx, _projectRepository, _stackRepository, _organizationRepository)
                }).Wait();
            }
        }
Пример #4
0
        public IHttpActionResult Promote(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            Stack stack = _stackRepository.GetById(id);

            if (stack == null || !CanAccessOrganization(stack.OrganizationId))
            {
                return(BadRequest());
            }

            if (!_billingManager.HasPremiumFeatures(stack.OrganizationId))
            {
                return(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <WebHook> promotedProjectHooks = _webHookRepository.GetByProjectId(stack.ProjectId).Where(p => p.EventTypes.Contains(WebHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                return(NotImplemented("No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature."));
            }

            foreach (WebHook hook in promotedProjectHooks)
            {
                _webHookNotificationQueue.EnqueueAsync(new WebHookNotification {
                    ProjectId = hook.ProjectId,
                    Url       = hook.Url,
                    Data      = WebHookStack.FromStack(stack, _projectRepository, _organizationRepository)
                });
            }

            return(Ok());
        }