Exemple #1
0
        public void CreateFromEvent(Version version, bool expectData)
        {
            var data = _webHookDataPluginManager.CreateFromEvent(GetWebHookDataContext(version));

            if (expectData)
            {
                string filePath = String.Format(@"..\..\Plugins\WebHookData\v{0}.event.expected.json", version);
                ApprovalsUtility.VerifyFile(filePath, JsonConvert.SerializeObject(data, Formatting.Indented));
            }
            else
            {
                Assert.Null(data);
            }
        }
        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)
                });
            }
        }
Exemple #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();
            }
        }