Пример #1
0
        private static async Task Quantify(
            IEnumerable <Organization> organizations,
            string clonePath)
        {
            var repositories = organizations.Select(o =>
                                                    o.Projects.Select(p =>
                                                                      p.Repositories.Select(r => new
            {
                Organization = o.Name,
                Project      = p.Name,
                Repository   = r.Name
            })))
                               .SelectMany(a => a)
                               .SelectMany(a => a);

            var gitEngine      = new GitEngine();
            var quantifyClient = new QuantifyClient(string.Empty);

            foreach (var repository in repositories)
            {
                var saveResultsToDatabase = new Dictionary <string, QuantifierResult>();

                var repoPath    = Path.Combine(clonePath, repository.Repository);
                var commitsSha1 = gitEngine.GetAllCommits(repoPath).Select(c => c.Sha).ToArray();
                Console.WriteLine($"Total commits to evaluate : {commitsSha1.Length}. Repo name {repository.Repository}.");

                foreach (var commitSha1 in commitsSha1)
                {
                    try
                    {
                        var quantifierResult = await quantifyClient.Compute(repoPath, commitSha1);

                        saveResultsToDatabase[commitSha1] = quantifierResult;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }

                await SaveToCsv(
                    saveResultsToDatabase,
                    Path.Combine(clonePath, $"{repository.Repository}_QuantifierResults.csv"));
            }
        }
Пример #2
0
        public void GetAllCommits_Successful()
        {
            // Arrange
            IGitEngine gitEngine = new GitEngine();

            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 2);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 4);
            gitRepoHelpers.CommitFilesToRepo();
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 5);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 2);

            // Act
            var commits = gitEngine.GetAllCommits(gitRepoHelpers.RepoPath).ToArray();

            // Assert
            Assert.NotEmpty(commits);
            Assert.Equal(2, commits.Length);
        }