예제 #1
0
파일: Program.cs 프로젝트: Banashek/PRStats
        public static async Task SampleUsage(string token)
        {
            // Sample Usage of Library
            var orgname = "lodash";

            // Retrieve all pull requests into memory
            var pullRequester = new PullRequester(token, orgname, Utils.getGHClient);
            var prs           = await pullRequester.GetAllPRsForOrg();

            // Print how many pull requests each repository has
            // Console.WriteLine("Results for the " + orgname + " organization");
            // Console.WriteLine("--------------------------------------------");
            // foreach (var r in prs.Repositories)
            // {
            //     Console.WriteLine(r.Key.Name + " has " + r.Value.ToList().Count.ToString() + " total pull requests.");
            // }
            // Console.WriteLine("\n\n");



            // The following is a demo for just the Lodash repository
            var pullRequestsForLodash = prs.Repositories.First().Value;
            var testDate = new DateTime(2017, 10, 1);

            // How many pull requests week over week since 2017-08-01 ?
            PullRequestInfo.LogNumberOfPRsMergedWeekOverWeekByCreatedAt(pullRequestsForLodash, testDate);
            Console.WriteLine("\n\n");

            // What was the average time between the creation and the merge of a pull request?
            // (Open pull requests that have not been closed are weighted based on the time between their created_at date and the current date)
            PullRequestInfo.LogCreationToMergeTimeAverageWeekOverWeekByCreatedAt(prs.Repositories.First().Value, testDate);
            Console.WriteLine("\n\n");

            // What was the average time between the creation of the first commit and the merge of a pull request?
            // (Open pull requests that have not been closed are weighted based on the time between their commit's created_at date and the current date)
            PullRequestInfo.LogFirstCommitToMergeTimeAverageWeekOverWeekByCreatedAt(pullRequester, prs.Repositories.First().Value, testDate).Wait();
            Console.WriteLine("\n\n");
        }
예제 #2
0
        public static async Task LogFirstCommitToMergeTimeAverageWeekOverWeekByCreatedAt(PullRequester pr, IEnumerable <PullRequest> prs, DateTime dt)
        {
            var prsByWeek = PRsWeekOverWeekByCreatedAt(prs, dt);

            Console.WriteLine("Average time between first commit and merge of a Pull Request week-over-week (open PRs counted) from " + dt.ToShortDateString() + " until now");
            Console.WriteLine("--------------------------------------------------------");
            foreach (var w in prsByWeek)
            {
                System.Console.WriteLine(w.Key.ToShortDateString() + " has " + w.Value.Count.ToString() + " values.");
                string avg;
                if (w.Value.Count > 0)
                {
                    foreach (var p in w.Value)
                    {
                        p.Commits = await pr.GetFirstCommitForPR(p);

                        string mDate = p.MergedAt.HasValue ? p.MergedAt.Value.ToShortDateString() : "never";
                        System.Console.WriteLine("\t" + p.Number + "'s first commit " + p.Commits.First().Sha + " was created at " + p.Commits.First().Details.Committer.CommitDate.ToShortDateString() + " and was merged at " + mDate + " for a timespan of " + timeSpanToDaysAndHoursString(p.FirstCommitToMergeTime()));
                    }

                    avg = w.Value.Aggregate(new TimeSpan(), (x, y) => x.Add(y.CreationToMergeTime()), (x) => x).TotalHours.ToString("N1");
                }
                else
                {
                    avg = "0";
                }
                Console.WriteLine(w.Key.ToShortDateString() + " has an average create-to-merge time of " + avg + " hours");
            }
        }