/// <summary>
 ///     Builds the initial lines of the report, containing the project name, the date range, and commit stats
 /// </summary>
 /// <param name="projectName">The name of the project</param>
 private static void BuildReportHeader(string projectName)
 {
     Sb.AppendLine($"Git log for {projectName} from {_start.ToShortDateString()} to {_end.ToShortDateString()}");
     Sb.AppendLine($"Total Commits: {_commits.Count}");
     Sb.AppendLine($"Average Commits Per Day: {Commits.CalculateAverageCommitsPerDay(_commits, _start, _end)}");
     Sb.AppendLine();
 }
        /// <summary>
        ///     Exports git log to an Excel spreadsheet
        /// </summary>
        /// <param name="path">The path to the git repositiory</param>
        /// <param name="fileName">The desired filename of the generated spreadsheet</param>
        /// <param name="from">The starting date</param>
        /// <param name="to">The ending date</param>
        public void ExportGitLog(string path,
                                 string fileName,
                                 DateTime from,
                                 DateTime to)
        {
            _start      = from;
            _end        = to;
            ProjectName = string.Empty;

            using (_repo = new Repository(path))
            {
                ProjectName = _repo.Config.Get <string>("core.ProjectName").Value;

                _commits = (from c in _repo.Commits
                            where c.Committer.When.DateTime >= _start && c.Committer.When.DateTime <= _end
                            orderby c.Committer.When.DateTime descending
                            select c).ToList();

                var report = new FileInfo(Path.Combine(fileName));
                if (report.Exists)
                {
                    report.Delete();
                    report = new FileInfo(fileName);
                }

                using (var package = new ExcelPackage(report))
                {
                    if (_commits.Any())
                    {
                        foreach (var day in DateTimeExtensions.EachDay(_start, _end))
                        {
                            var currentCommits =
                                _commits.Where(c => c.Committer.When.DateTime.Date == day.Date).ToList();

                            if (!currentCommits.Any())
                            {
                                continue;
                            }

                            var ws = package.Workbook.Worksheets.Add(day.ToString("dddd, MM-dd"));

                            // Headers
                            ws.Cells[1, 1, 1, 2].Merge = true;
                            var titleCell = ws.Cells[1, 1];
                            titleCell.Value           = currentCommits.First().Committer.When.DateTime.ToString("D");
                            titleCell.Style.Font.Bold = true;

                            ws.Cells[2, 1, 2, 2].Merge = true;
                            ws.Cells[2, 1].Value       = $"Commits: {currentCommits.Count}";

                            ws.Cells[2, 3, 2, 4].Merge = true;
                            ws.Cells[2, 3].Value       = $"Total Commits: {_commits.Count}";

                            ws.Cells[2, 5, 2, 6].Merge = true;
                            ws.Cells[2, 5].Value       =
                                $"Avg Per Day: {Commits.CalculateAverageCommitsPerDay(_commits, _start, _end)}";

                            ws.View.FreezePanes(3, 1);

                            BuildCommits(currentCommits, ws, 4);

                            ws.Cells[ws.Dimension.Address].AutoFitColumns();

                            ws.Column(2).Width = 60;
                        }
                    }
                    else
                    {
                        var ws = package.Workbook.Worksheets.Add("No Commits Found");

                        ws.Cells[1, 1, 1, 2].Merge = true;
                        ws.Cells[1, 1].Value       = "No Commits Found";

                        ws.Cells[1, 4, 1, 5].Merge = true;
                        ws.Cells[1, 4].Value       = $"Total Commits: {_commits.Count}";

                        ws.Cells[2, 4, 2, 5].Merge = true;
                        ws.Cells[2, 4].Value       = $"Avg Per Day: 0";
                    }

                    package.SaveAs(report);
                }
            }
        }