Ejemplo n.º 1
0
        private static CommitChangeStats GetChangeStats(string cmd, string projectDir)
        {
            if (!SoftwareCoUtil.IsGitProject(projectDir))
            {
                return(new CommitChangeStats());
            }
            CommitChangeStats stats = new CommitChangeStats();

            /**
             * example:
             * -mbp-2:swdc-vscode xavierluiz$ git diff --stat
             *  lib/KpmProviderManager.ts | 22 ++++++++++++++++++++--
             *  1 file changed, 20 insertions(+), 2 deletions(-)
             *
             *  for multiple files it will look like this...
             *  7 files changed, 137 insertions(+), 55 deletions(-)
             */
            List <string> results = SoftwareCoUtil.GetCommandResultList(cmd, projectDir);

            if (results == null || results.Count == 0)
            {
                // something went wrong, but don't try to parse a null or undefined str
                return(stats);
            }

            // just look for the line with "insertions" and "deletions"
            return(AccumulateChangeStats(results));
        }
Ejemplo n.º 2
0
        public static CommitChangeStats AccumulateChangeStats(List <string> results)
        {
            CommitChangeStats stats = new CommitChangeStats();

            if (results != null)
            {
                foreach (string line in results)
                {
                    string lineData = line.Trim();
                    lineData = Regex.Replace(lineData, @"\s+", " ");
                    // look for lines with insertion and deletion
                    if (lineData.IndexOf("changed") != -1 &&
                        (lineData.IndexOf("insertion") != -1 || lineData.IndexOf("deletion") != -1))
                    {
                        string[] parts = lineData.Split(' ');
                        // the 1st element is the number of files changed
                        int fileCount = int.Parse(parts[0]);
                        stats.fileCount   += fileCount;
                        stats.commitCount += 1;
                        for (int x = 0; x < parts.Count(); x++)
                        {
                            string part = parts[x];
                            if (part.IndexOf("insertion") != -1)
                            {
                                int insertions = int.Parse(parts[x - 1]);
                                stats.insertions += insertions;
                            }
                            else if (part.IndexOf("deletion") != -1)
                            {
                                int deletions = int.Parse(parts[x - 1]);
                                stats.deletions += deletions;
                            }
                        }
                    }
                }
            }

            return(stats);
        }
Ejemplo n.º 3
0
        public async Task DisplayProjectContributorSummaryDashboard()
        {
            string        file = FileManager.GetContributorDashboardFile();
            StringBuilder sb   = new StringBuilder();

            // fetch the git stats
            string projectDir = DocEventManager._solutionDirectory;

            RepoResourceInfo resourceInfo = GitUtilManager.GetResourceInfo(projectDir, false);
            string           identifier   = resourceInfo != null && resourceInfo.identifier != null ? resourceInfo.identifier : "Untitled";

            NowTime           nowTime              = SoftwareCoUtil.GetNowTime();
            string            email                = GitUtilManager.GetUsersEmail(projectDir);
            CommitChangeStats usersTodaysCommits   = GitUtilManager.GetTodaysCommits(projectDir, email);
            CommitChangeStats contribTodaysCommits = GitUtilManager.GetTodaysCommits(projectDir, null);

            CommitChangeStats usersYesterdaysCommits   = GitUtilManager.GetYesterdayCommits(projectDir, email);
            CommitChangeStats contribYesterdaysCommits = GitUtilManager.GetYesterdayCommits(projectDir, null);

            CommitChangeStats usersThisWeeksCommits   = GitUtilManager.GetThisWeeksCommits(projectDir, email);
            CommitChangeStats contribThisWeeksCommits = GitUtilManager.GetThisWeeksCommits(projectDir, null);


            string lastUpdatedStr = DateTime.Now.ToString("dddd, MMM d h:mm tt");

            sb.Append(getTableHeader("PROJECT SUMMARY", " (Last updated on " + lastUpdatedStr + ")", true));
            sb.Append("\n\n Project: ").Append(identifier).Append("\n\n");

            // TODAY
            String projectDate = DateTime.Now.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("Today (" + projectDate + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersTodaysCommits.commitCount, contribTodaysCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersTodaysCommits.fileCount, contribTodaysCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersTodaysCommits.insertions, contribTodaysCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersTodaysCommits.deletions, contribTodaysCommits.deletions));
            sb.Append("\n");

            // YESTERDAY
            String yesterday = nowTime.start_of_yesterday_dt.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("Yesterday (" + yesterday + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersYesterdaysCommits.commitCount, contribYesterdaysCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersYesterdaysCommits.fileCount, contribYesterdaysCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersYesterdaysCommits.insertions, contribYesterdaysCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersYesterdaysCommits.deletions, contribYesterdaysCommits.deletions));
            sb.Append("\n");

            // THIS WEEK
            String startOfWeek = nowTime.start_of_week_dt.ToString("MMM d, yyyy");

            sb.Append(getRightAlignedTableHeader("This week (" + startOfWeek + " to " + projectDate + ")"));
            sb.Append(getColumnHeaders(new List <string>()
            {
                "Metric", "You", "All Contributors"
            }));
            sb.Append(getRowNumberData("Commits", usersThisWeeksCommits.commitCount, contribThisWeeksCommits.commitCount));
            sb.Append(getRowNumberData("Files changed", usersThisWeeksCommits.fileCount, contribThisWeeksCommits.fileCount));
            sb.Append(getRowNumberData("Insertions", usersThisWeeksCommits.insertions, contribThisWeeksCommits.insertions));
            sb.Append(getRowNumberData("Deletions", usersThisWeeksCommits.deletions, contribThisWeeksCommits.deletions));
            sb.Append("\n");


            if (File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.Normal);
            }
            try
            {
                File.WriteAllText(file, sb.ToString(), System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }

            try
            {
                if (File.Exists(file))
                {
                    SoftwareCoPackage.ObjDte.ItemOperations.OpenFile(file);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("LaunchCodeTimeDashboardAsync, error : " + ex.Message, ex);
            }
        }
        public async Task RebuildGitMetricsAsync()
        {
            string dir = DocEventManager._solutionDirectory;

            if ((dir == null || dir.Equals("")) && SoftwareCoPackage.PLUGIN_READY)
            {
                dir = await DocEventManager.GetSolutionDirectory();
            }

            // if (dir == null || dir.Equals(""))
            // {
            // Uncommitted.Visibility = Visibility.Hidden;
            // CommittedToday.Visibility = Visibility.Hidden;
            // return;
            // } else
            // {
            // Uncommitted.Visibility = Visibility.Visible;
            // CommittedToday.Visibility = Visibility.Visible;
            // }

            string name = "";

            try
            {
                FileInfo fi = new FileInfo(dir);
                name = fi.Name;
            } catch (Exception e)
            {
                //
            }

            CommitChangeStats uncommited            = GitUtilManager.GetUncommitedChanges(dir);
            string            uncommittedInsertions = "Insertion(s): " + uncommited.insertions;
            string            uncommittedDeletions  = "Deletion(s): " + uncommited.deletions;

            if (Uncommitted.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Uncommitted, "uncommitted");

                UpdateNodeValue(parentItem, "uncommittedinsertions", uncommittedInsertions, "insertion.png");
                UpdateNodeValue(parentItem, "uncommitteddeletions", uncommittedDeletions, "deletion.png");
            }
            else
            {
                List <TreeViewItem> uncommitedChilren = new List <TreeViewItem>();
                uncommitedChilren.Add(BuildMetricNode("uncommittedinsertions", uncommittedInsertions, "insertion.png"));
                uncommitedChilren.Add(BuildMetricNode("uncommitteddeletions", uncommittedDeletions, "deletion.png"));
                TreeViewItem uncommittedParent = BuildMetricNodes("uncommitted", "Open changes", uncommitedChilren);
                Uncommitted.Items.Add(uncommittedParent);
            }

            string            email               = GitUtilManager.GetUsersEmail(dir);
            CommitChangeStats todaysStats         = GitUtilManager.GetTodaysCommits(dir, email);
            string            committedInsertions = "Insertion(s): " + todaysStats.insertions;
            string            committedDeletions  = "Deletion(s): " + todaysStats.deletions;
            string            committedCount      = "Commit(s): " + todaysStats.commitCount;
            string            committedFilecount  = "Files changed: " + todaysStats.fileCount;

            if (CommittedToday.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(CommittedToday, "committed");

                UpdateNodeValue(parentItem, "committedinsertions", committedInsertions, "insertion.png");
                UpdateNodeValue(parentItem, "committeddeletions", committedDeletions, "deletion.png");
                UpdateNodeValue(parentItem, "committedcount", committedCount, "commit.png");
                UpdateNodeValue(parentItem, "committedfilecount", committedFilecount, "files.png");
            }
            else
            {
                List <TreeViewItem> committedChilren = new List <TreeViewItem>();
                committedChilren.Add(BuildMetricNode("committedinsertions", committedInsertions, "insertion.png"));
                committedChilren.Add(BuildMetricNode("committeddeletions", committedDeletions, "deletion.png"));
                committedChilren.Add(BuildMetricNode("committedcount", committedCount, "commit.png"));
                committedChilren.Add(BuildMetricNode("committedfilecount", committedFilecount, "files.png"));
                TreeViewItem committedParent = BuildMetricNodes("committed", "Committed today", committedChilren);
                CommittedToday.Items.Add(committedParent);
            }
        }