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);
        }
        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.Enqueue(new EventNotification {
                Event        = ctx.Event,
                IsNew        = ctx.IsNew,
                IsCritical   = ctx.Event.IsCritical(),
                IsRegression = ctx.IsRegression,
                //TotalOccurrences = ctx.Stack.TotalOccurrences,
                ProjectName = ctx.Project.Name
            });

            foreach (WebHook hook in _webHookRepository.GetByOrganizationIdOrProjectId(ctx.Event.OrganizationId, 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();

                // TODO: Should we be using the hook's project id and organization id?
                var context = new WebHookDataContext(hook.Version, ctx.Event, ctx.Organization, ctx.Project, ctx.Stack, ctx.IsNew, ctx.IsRegression);
                _webHookNotificationQueue.Enqueue(new WebHookNotification {
                    OrganizationId = ctx.Event.OrganizationId,
                    ProjectId      = ctx.Event.ProjectId,
                    Url            = hook.Url,
                    Data           = _webHookDataPluginManager.CreateFromEvent(context)
                });
            }
        }
Пример #3
0
        public override async Task ProcessAsync(EventContext ctx)
        {
            // if they don't have premium features, then we don't need to queue notifications
            if (!ctx.Organization.HasPremiumFeatures)
            {
                return;
            }

            if (ShouldQueueNotification(ctx))
            {
                _notificationQueue.Enqueue(new EventNotificationWorkItem {
                    EventId          = ctx.Event.Id,
                    IsNew            = ctx.IsNew,
                    IsCritical       = ctx.Event.IsCritical(),
                    IsRegression     = ctx.IsRegression,
                    TotalOccurrences = ctx.Stack.TotalOccurrences,
                    ProjectName      = ctx.Project.Name
                });
            }

            foreach (WebHook hook in _webHookRepository.GetByOrganizationIdOrProjectId(ctx.Event.OrganizationId, ctx.Event.ProjectId))
            {
                if (!ShouldCallWebHook(hook, ctx))
                {
                    continue;
                }

                var context      = new WebHookDataContext(hook.Version, ctx.Event, ctx.Organization, ctx.Project, ctx.Stack, ctx.IsNew, ctx.IsRegression);
                var notification = new WebHookNotification {
                    OrganizationId = ctx.Event.OrganizationId,
                    ProjectId      = ctx.Event.ProjectId,
                    Url            = hook.Url,
                    Data           = _webHookDataPluginManager.CreateFromEvent(context)
                };

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