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; } // notifications are disabled or stack is hidden. if (ctx.Stack.DisableNotifications || ctx.Stack.IsHidden) { return; } if (ShouldQueueNotification(ctx)) { await _notificationQueue.EnqueueAsync(new EventNotificationWorkItem { EventId = ctx.Event.Id, IsNew = ctx.IsNew, IsRegression = ctx.IsRegression, TotalOccurrences = ctx.Stack.TotalOccurrences }).AnyContext(); } var webHooks = await _webHookRepository.GetByOrganizationIdOrProjectIdAsync(ctx.Event.OrganizationId, ctx.Event.ProjectId).AnyContext(); foreach (var hook in webHooks.Documents) { 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, WebHookId = hook.Id, Url = hook.Url, Type = WebHookType.General, Data = await _webHookDataPluginManager.CreateFromEventAsync(context).AnyContext() }; await _webHookNotificationQueue.EnqueueAsync(notification).AnyContext(); using (_logger.BeginScope(new Dictionary <string, object> { { "Web Hook Notification", notification } })) _logger.LogTrace("Web hook queued: project={project} url={Url}", ctx.Event.ProjectId, hook.Url); } }
public async Task CreateFromEventAsync(Version version, bool expectData) { var settings = GetService <JsonSerializerSettings>(); settings.Formatting = Formatting.Indented; var data = await _webHookData.CreateFromEventAsync(GetWebHookDataContext(version)); if (expectData) { string filePath = $@"..\..\Plugins\WebHookData\v{version}.event.expected.json"; ApprovalsUtility.VerifyFile(filePath, JsonConvert.SerializeObject(data, settings)); } else { Assert.Null(data); } }
public async Task CreateFromEventAsync(Version version, bool expectData) { var settings = GetService <JsonSerializerSettings>(); settings.Formatting = Formatting.Indented; object data = await _webHookData.CreateFromEventAsync(GetWebHookDataContext(version)); if (expectData) { string filePath = Path.GetFullPath(Path.Combine("..", "..", "..", "Plugins", "WebHookData", $"v{version}.event.expected.json")); ApprovalsUtility.VerifyFile(filePath, JsonConvert.SerializeObject(data, settings)); } else { Assert.Null(data); } }
public async Task CreateFromEventAsync(string version, bool expectData) { var settings = GetService <JsonSerializerSettings>(); settings.Formatting = Formatting.Indented; object data = await _webHookData.CreateFromEventAsync(GetWebHookDataContext(version)); if (expectData) { string filePath = Path.GetFullPath(Path.Combine("..", "..", "..", "Plugins", "WebHookData", $"{version}.event.expected.json")); string expectedContent = File.ReadAllText(filePath); string actualContent = JsonConvert.SerializeObject(data, settings); Assert.Equal(expectedContent, actualContent); } else { Assert.Null(data); } }
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)) { await _notificationQueue.EnqueueAsync(new EventNotificationWorkItem { EventId = ctx.Event.Id, IsNew = ctx.IsNew, IsCritical = ctx.Event.IsCritical(), IsRegression = ctx.IsRegression, TotalOccurrences = ctx.Stack.TotalOccurrences, ProjectName = ctx.Project.Name }).AnyContext(); } foreach (WebHook hook in (await _webHookRepository.GetByOrganizationIdOrProjectIdAsync(ctx.Event.OrganizationId, ctx.Event.ProjectId).AnyContext()).Documents) { 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, WebHookId = hook.Id, Url = hook.Url, Data = await _webHookDataPluginManager.CreateFromEventAsync(context).AnyContext() }; await _webHookNotificationQueue.EnqueueAsync(notification).AnyContext(); _logger.Trace().Project(ctx.Event.ProjectId).Message("Web hook queued: project={0} url={1}", ctx.Event.ProjectId, hook.Url).Property("Web Hook Notification", notification).Write(); } }