public List <ProcessedPullRequest> GetPullRequestCloseData(int startMonth = 6, int startYear = 2010, string repository = "")
        {
            var repoService = new RepositoryManagementService();

            var pulls = string.IsNullOrWhiteSpace(repository)
                ? repoService.GetAllIssues(true).ToList()
                : repoService.GetAllIssues(true).Where(x => x.RepositoryName == repository).ToList();

            var date       = new DateTime(startYear, startMonth, 1);
            var prsCreated = pulls.Where(x => x.CreateDateTime >= date).ToList();

            var processedPullRequests = new List <ProcessedPullRequest>();

            foreach (var pr in prsCreated)
            {
                if (pr.State != "closed")
                {
                    // still open, continue
                    continue;
                }

                var processedPr = new ProcessedPullRequest();
                processedPr.Number     = pr.Number;
                processedPr.Repository = pr.RepositoryName;
                processedPr.Title      = pr.Title;
                if (pr.ClosedDateTime.HasValue)
                {
                    processedPr.CloseDateTime = pr.ClosedDateTime.Value;
                }
                processedPr.ClosedByUser = pr.CloseUser?.Login;

                // GitHub marks all merged PRs as "closed", so we want to differentiate: if there's no "merged" event then it was closed without merging
                if (pr.Events.Any(y => y.Name == "merged") == false)
                {
                    var closeEvent = pr.Events.LastOrDefault(y => y.Name == "closed");
                    processedPr.ClosedByUser = closeEvent?.Actor?.Login;
                    processedPr.CloseType    = "closed";
                }

                // There was a "merged" event
                if (pr.Events.Any(y => y.Name == "merged"))
                {
                    var mergeEvent = pr.Events.LastOrDefault(y => y.Name == "merged");
                    processedPr.ClosedByUser = mergeEvent?.Actor?.Login;
                    processedPr.CloseType    = "merged";
                }

                processedPullRequests.Add(processedPr);
            }

            return(processedPullRequests);
        }
        public List <ApproveddPullRequest> GetApprovedRequestCloseData(int startMonth = 6, int startYear = 2010, string repository = "")
        {
            var repoService = new RepositoryManagementService();
            var date        = new DateTime(startYear, startMonth, 1);

            var approvedPulls = string.IsNullOrWhiteSpace(repository)
                ? repoService.GetAllIssues(true).Where(x => x.CreateDateTime >= date && x.State != "closed" && x.Reviews.Any(y => y.State == "APPROVED")).ToList()
                : repoService.GetAllIssues(true).Where(x => x.CreateDateTime >= date && x.State != "closed" && x.Reviews.Any(y => y.State == "APPROVED") && x.RepositoryName == repository).ToList();

            var approvedPullRequestData = new List <ApproveddPullRequest>();

            foreach (var pull in approvedPulls)
            {
                var approvals     = pull.Reviews.Where(x => x.State == "APPROVED").ToList();
                var approvalNames = new List <string>();
                foreach (var approval in approvals)
                {
                    if (approvalNames.Contains(approval.Actor.Login) == false)
                    {
                        approvalNames.Add(approval.Actor.Login);
                    }
                }
                var firstApproval = approvals.OrderBy(x => x.CreateDateTime).First();
                var approvers     = string.Join(",", approvalNames);
                approvedPullRequestData.Add(new ApproveddPullRequest
                {
                    Number           = pull.Number,
                    Repository       = pull.RepositoryName,
                    Title            = pull.Title,
                    ApprovedDateTime = firstApproval.CreateDateTime,
                    ApprovedByUser   = approvers
                });
            }

            return(approvedPullRequestData);
        }