public void Generate(Analysis analysis)
        {
            Console.WriteLine("Generating Text file report...");
            StringBuilder sb = new StringBuilder();

            FileCommitsList     = analysis.FileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename);
            UserfileCommitsList = analysis.UserfileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename).ThenBy(fc => fc.Username);

            var totalCommits    = FileCommitsList.Sum(fc => fc.CommitCount);
            var numberOfAuthors = UserfileCommitsList.Select(ufc => ufc.Username).Distinct().Count();

            sb.AppendLine($"{Title}\n");
            sb.AppendLine($"Report created: {analysis.CreatedDate.ToString("yyyy-MM-dd")}");
            sb.AppendLine($"First commit: {analysis.FirstCommitDate.ToString("yyyy-MM-dd")}");
            sb.AppendLine($"Latest commit: {analysis.LatestCommitDate.ToString("yyyy-MM-dd")}");
            sb.AppendLine($"Number of commits: {totalCommits}");
            sb.AppendLine($"Lines of code analyzed: {analysis.LinesOfCodeanalyzed}");
            sb.AppendLine($"Number of authors: {numberOfAuthors}");
            sb.AppendLine($"Analysis time(milliseconds): {analysis.AnalysisTime}");
            sb.AppendLine();

            var folderCommitsList = analysis.FolderCommits.Values.OrderByDescending(fc => fc.FileChanges);

            foreach (var folder in folderCommitsList.Take(NumberOfFilesToList))
            {
                var folderName  = string.Format("{0,50}", folder.FolderName);
                var changeCount = string.Format("{0,5}", analysis.FolderCommits[folder.FolderName].FileChanges);
                var percentage  = string.Format("{0,5:#0.00}", ((double)analysis.FolderCommits[folder.FolderName].FileChanges / (double)totalCommits) * 100);
                sb.AppendLine($"{folderName}: {changeCount} ({percentage}%)");
            }

            foreach (var fileChange in FileCommitsList.Take(50))
            {
                sb.AppendLine("");
                string fileInfo = "File has been deleted";
                if (fileChange.FileExists)
                {
                    var linesOfCode          = fileChange.LinesOfCode > 0 ? fileChange.LinesOfCode.ToString() : "N/A";
                    var cyclomaticComplexity = fileChange.CyclomaticComplexity > 0 ? fileChange.CyclomaticComplexity.ToString() : "N/A";
                    var methodCount          = fileChange.MethodCount > 0 ? fileChange.MethodCount.ToString() : "N/A";
                    fileInfo = $"Lines of code: {linesOfCode} - Cyclomatic Complexity: {cyclomaticComplexity} - Method count: {methodCount}";
                }
                sb.AppendLine($"{fileChange.Filename}: {fileChange.CommitCount} - Latest commit: {fileChange.LatestCommit.ToString("yyyy-MM-dd")} - {fileInfo}\n");
                foreach (var userfileChange in UserfileCommitsList.Where(ufc => ufc.Filename == fileChange.Filename))
                {
                    var username    = string.Format("{0,20}", userfileChange.Username);
                    var changeCount = string.Format("{0,3}", userfileChange.CommitCount);
                    var percentage  = string.Format("{0,5:#0.00}", ((double)userfileChange.CommitCount / (double)fileChange.CommitCount) * 100);
                    sb.AppendLine($"    {username}: {changeCount} ({percentage}%)");
                }
            }

            SystemIO.WriteAllText($"{ReportFilename}.txt", sb.ToString());
        }
Ejemplo n.º 2
0
        private void AddSectionCommitsForEachFile(ExcelWorksheet sheet)
        {
            Header(sheet, $"Top {NumberOfFilesToList} most changed files");

            int rowCounter = 3;

            foreach (var fileChange in FileCommitsList.Take(NumberOfFilesToList))
            {
                rowCounter = AddSectionCommitsForFile(sheet, fileChange, rowCounter);
            }
        }
Ejemplo n.º 3
0
        public void Generate(Analysis analysis)
        {
            Console.WriteLine("Generating HTML report...");
            if (analysis == null)
            {
                throw new ArgumentException("Parameter analysis is null.", nameof(analysis));
            }
            this.FileCommitsList     = analysis.FileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename);
            this.UserfileCommitsList = analysis.UserfileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename).ThenBy(fc => fc.Username);
            var key = 1;

            foreach (var username in analysis.UserfileCommits.Values.Select(fc => fc.Username).Distinct().OrderBy(un => un))
            {
                UserNameKey.Add(username, key++);
            }
            ;
            this.FolderCommits     = analysis.FolderCommits;
            this.FolderCommitsList = analysis.FolderCommits.Values.OrderByDescending(fc => fc.FileChanges);

            StringBuilder sb = new StringBuilder();

            AddHeader(sb, analysis);
            AddNavTabs(sb);
            sb.AppendLine("<div class=\"tab-content\">");
            sb.AppendLine("<div role=\"tabpanel\" class=\"tab-pane active\" id=\"commitsForEachSubfolder\">");
            AddSectionCommitsForEachFolder(sb);
            sb.Append($"<h2 id=\"mostChangedFiles\">Top {NumberOfFilesToList} most changed files</h2>");
            var sectionCounter = 1;

            foreach (var fileChange in FileCommitsList.Take(NumberOfFilesToList))
            {
                AddSectionCommitsForEachFile(sb, fileChange, sectionCounter++);
            }
            sb.AppendLine("</div>");
            sb.AppendLine("<div role=\"tabpanel\" class=\"tab-pane\" id=\"projectStatistics\">");
            AddSectionProjectStatistics(sb, analysis);
            AddSectionCommitsForEachDay(sb, analysis.CommitsEachDay);
            AddSectionLinesChangedEachDay(sb, analysis.LinesOfCodeAddedEachDay, analysis.LinesOfCodeDeletedEachDay);
            AddSectionCodeAge(sb, analysis.CodeAge);
            if (analysis.Tags.Any())
            {
                AddSectionTags(sb, analysis.Tags);
            }
            if (analysis.Branches.Any())
            {
                AddSectionBranches(sb, analysis.Branches);
            }
            AddSectionFileTypes(sb, analysis.FileTypes);
            sb.AppendLine("</div>");
            sb.AppendLine("</div>");
            AddFooter(sb);

            SystemIO.WriteAllText($"{ReportFilename}.html", sb.ToString());
        }
Ejemplo n.º 4
0
        public void Generate(Analysis analysis)
        {
            Console.WriteLine("Generating Markdown report...");
            StringBuilder sb = new StringBuilder();

            FileCommitsList     = analysis.FileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename);
            UserfileCommitsList = analysis.UserfileCommits.Values.OrderByDescending(fc => fc.CommitCount).ThenBy(fc => fc.Filename).ThenBy(fc => fc.Username);

            sb.AppendLine($"# {Title}\n");
            sb.AppendLine($"Report created: {analysis.CreatedDate.ToString("yyyy-MM-dd")}\n");

            var totalCommits    = FileCommitsList.Sum(fc => fc.CommitCount);
            var numberOfAuthors = UserfileCommitsList.Select(ufc => ufc.Username).Distinct().Count();

            sb.AppendLine($"## Statistics\n");
            sb.AppendLine("| | |");
            sb.AppendLine("|---:|----:|");
            sb.AppendLine($"| First commit | {analysis.FirstCommitDate.ToString("yyyy-MM-dd")} |");
            sb.AppendLine($"| Latest commit | {analysis.LatestCommitDate.ToString("yyyy-MM-dd")} |");
            sb.AppendLine($"| Number of commits | {totalCommits} |");
            sb.AppendLine($"| Lines of code analyzed | {analysis.LinesOfCodeanalyzed} |");
            sb.AppendLine($"| Number of authors | {numberOfAuthors} |");
            sb.AppendLine($"| Analysis time(milliseconds) | {analysis.AnalysisTime} |");
            sb.AppendLine();

            sb.AppendLine("## File changes for each sub-folder");
            var folderCommitsList = analysis.FolderCommits.Values.OrderByDescending(fc => fc.FileChanges);

            foreach (var folder in folderCommitsList.Take(NumberOfFilesToList))
            {
                var folderName  = string.Format("{0,50}", folder.FolderName);
                var changeCount = string.Format("{0,5}", analysis.FolderCommits[folder.FolderName].FileChanges);
                var percentage  = string.Format("{0,5:#0.00}", ((double)analysis.FolderCommits[folder.FolderName].FileChanges / (double)totalCommits) * 100);
                sb.AppendLine($"{folderName}: {changeCount} ({percentage}%)");
            }
            sb.AppendLine($"{string.Format("{0,51}", "---------------")} {string.Format("{0,6}", "-----")} {string.Format("{0,7}", "------")}");
            var total = string.Format("{0,5}", totalCommits);

            sb.AppendLine($"{string.Format("{0,50}", "Total number of Commits analyzed")}: {total} ({string.Format("{0,5:##0.0}", 100)}%)\n");

            sb.AppendLine("---\n");

            foreach (var fileChange in FileCommitsList.Take(50))
            {
                var linesOfCode          = fileChange.LinesOfCode > 0 ? fileChange.LinesOfCode.ToString() : "N/A";
                var cyclomaticComplexity = fileChange.CyclomaticComplexity > 0 ? fileChange.CyclomaticComplexity.ToString() : "N/A";
                var methodCount          = fileChange.MethodCount > 0 ? fileChange.MethodCount.ToString() : "N/A";
                sb.AppendLine($"### {fileChange.Filename}\n");
                sb.AppendLine("| | |");
                sb.AppendLine("|---:|----:|");
                sb.AppendLine($"| Latest commit | {fileChange.LatestCommit.ToString("yyyy-MM-dd")} |");
                sb.AppendLine($"| Commits | {fileChange.CommitCount} |");
                if (fileChange.FileExists)
                {
                    sb.AppendLine($"| Lines of code | {linesOfCode} |");
                    sb.AppendLine($"| Cyclomatic Complexity | {cyclomaticComplexity} |");
                    sb.AppendLine($"| Method count | {methodCount} |");
                }
                else
                {
                    sb.AppendLine($"| File has been deleted | |");
                }
                sb.AppendLine();

                sb.AppendLine("__Commits by user:__\n");
                sb.AppendLine($"| Name | Commits | Percentage |");
                sb.AppendLine($"|-----:|--------:|-----------:|");
                foreach (var userfileChange in UserfileCommitsList.Where(ufc => ufc.Filename == fileChange.Filename))
                {
                    var username    = string.Format("{0,20}", userfileChange.Username);
                    var changeCount = string.Format("{0,3}", userfileChange.CommitCount);
                    var percentage  = string.Format("{0,5:#0.00}", ((double)userfileChange.CommitCount / (double)fileChange.CommitCount) * 100);
                    sb.AppendLine($"| {username} | {changeCount} | {percentage}% |");
                }
                sb.AppendLine();
            }

            sb.AppendLine("## Code age\n");
            sb.AppendLine("| Code age(months) | Filechanges |");
            sb.AppendLine("|---:|---:|");
            var maxAge = analysis.CodeAge.AsEnumerable().OrderByDescending(kvp => kvp.Key).First().Key;

            for (var month = 0; month <= maxAge; month++)
            {
                var fileChanges = analysis.CodeAge.ContainsKey(month) ? analysis.CodeAge[month] : 0;
                sb.AppendLine($"|{month}|{fileChanges}|");
            }
            sb.AppendLine();

            if (analysis.Tags.Any())
            {
                var tagsOrdered = analysis.Tags.AsEnumerable().OrderByDescending(kvp => kvp.Key).ThenBy(kvp => kvp.Value);
                sb.AppendLine("## Tags\n");
                sb.AppendLine("| Name | Date |");
                sb.AppendLine("|:---|----:|");
                foreach (var kvp in tagsOrdered)
                {
                    sb.AppendLine($"| {kvp.Value} | {kvp.Key.ToString("yyyy-MM-dd")} |");
                }
                sb.AppendLine();
            }

            if (analysis.Branches.Any())
            {
                sb.AppendLine("## Branches\n");
                sb.AppendLine("| Name |");
                sb.AppendLine("|:---|");
                foreach (var branch in analysis.Branches)
                {
                    sb.AppendLine($"| {branch} |");
                }
                sb.AppendLine();
            }

            var fileTypesOrdered = analysis.FileTypes.AsEnumerable().OrderByDescending(kvp => kvp.Value).ThenBy(kvp => kvp.Key);

            sb.AppendLine("## Number of files of each type\n");
            sb.AppendLine("| File type | Count |");
            sb.AppendLine("|---:|----:|");
            foreach (var kvp in fileTypesOrdered)
            {
                sb.AppendLine($"| {kvp.Key} | {kvp.Value} |");
            }

            SystemIO.WriteAllText($"{ReportFilename}.md", sb.ToString());
        }