public async Task <IActionResult> Trigger([FromForm] string ruleName, CancellationToken token) { var rule = _options.Value.Rules.FirstOrDefault(x => x.Name.Equals(ruleName, StringComparison.OrdinalIgnoreCase)); if (rule == null) { _log.LogWarning($"Tried to trigger {ruleName} rule but could not find it in the configuration"); return(NotFound()); } var eventLog = await _eventLogRepository.CreateManualAsync(token); await _executionRequestRepository.Create(rule, eventLog.Id, token); return(Ok()); }
public async Task <EventProcessorResult> Process(Guid eventLog, PushEventPayload payload, CancellationToken token) { try { var rule = _ruleMatcher.Match(payload.Ref, payload.Repository?.Url); if (rule != null) { await _executionRequestRepository.Create(rule, eventLog, token); return(new EventProcessorResult(true, $"{rule.Name} rule matched", rule)); } } catch (Exception ex) { _log.LogError(ex, "Unexpected error while trying to execute script"); return(new EventProcessorResult(false, $"Unexpected error while trying to process event: {ex.Message}")); } return(new EventProcessorResult(false, "No matching rule")); }