public bool Process(PushEventPayload payload)
        {
            try
            {
                var rule = _ruleMatcher.Match(payload.Ref, payload.Repository?.Url);
                if (rule != null)
                {
                    _processExecutor.Execute(rule.Execute);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "Unexpected error while trying to execute script");
                return(false);
            }

            return(false);
        }
        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"));
        }
Ejemplo n.º 3
0
        public static int GetNumberOfCommitsToday(GitHubClient client, string username)
        {
            // only checks the last 30 events
            int count   = 0;
            var options = new ApiOptions();

            options.StartPage = 1;
            options.PageSize  = 30;
            options.PageCount = 1;

            IReadOnlyList <Activity> activities = client.Activity.Events.GetAllUserPerformed(username, options).Result;

            foreach (Activity a in activities)
            {
                if (a.CreatedAt.Date == GetTodaysDate())
                {
                    if (a.Type == "PushEvent")
                    {
                        PushEventPayload payload = (PushEventPayload)a.Payload;
                        count += payload.Commits.Count;
                    }

                    if (a.Type == "CreateEvent")
                    {
                        CreateEventPayload payload = (CreateEventPayload)a.Payload;
                        if (payload.RefType.StringValue == "repository")
                        {
                            count += 1;
                        }

                        if (payload.RefType.StringValue == "branch")
                        {
                            count += 2;
                        }
                    }
                }
            }

            return(count);
        }