Beispiel #1
0
        /// <inheritdoc />
        public async Task <Context> Create(string repoPath)
        {
            // get historical changes
            var historicalChanges = gitEngine.GetGitHistoricalChangesToParent(repoPath);
            var context           = DefaultContext.Value.ShallowCopy();

            // if there are no history changes into the repo then return the default context.
            if (historicalChanges.Count == 0)
            {
                return(context);
            }

            // do the quantification based on th default context to get accurate numbers
            IPullRequestQuantifier prQuantifier = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(historicalChanges.Values.SelectMany(v => v));
            await prQuantifier.Quantify(quantifierInput);

            context.AdditionPercentile = AdditionDeletionPercentile(historicalChanges, true);
            context.DeletionPercentile = AdditionDeletionPercentile(historicalChanges, false);
            context.FormulaPercentile  = FormulaPercentile(historicalChanges);

            return(context);
        }
Beispiel #2
0
        public async Task Quantify_NoChanges_ReturnsZeroCounts()
        {
            // Arrange
            var prQuantifier    = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));

            // Act
            var quantifierResult = await prQuantifier.Quantify(quantifierInput);

            // Assert
            Assert.Equal("No Changes", quantifierResult.Label);
            Assert.Equal(0, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(0, quantifierResult.QuantifiedLinesDeleted);
        }
Beispiel #3
0
        public async Task Quantify_FilesWithPlusMinusContent()
        {
            // Arrange
            gitRepoHelpers.AddUntrackedFileToRepoWithContent("fake.cs", "-text\n+add\nnormal\n-44");
            var prQuantifier    = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));

            // Act
            var quantifierResult = await prQuantifier.Quantify(quantifierInput);

            // Assert
            Assert.True(!string.IsNullOrEmpty(quantifierResult.Label));
            Assert.Equal(4, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(0, quantifierResult.QuantifiedLinesDeleted);
        }
Beispiel #4
0
        public async Task Quantify_UntrackedFilesOnly()
        {
            // Arrange
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 2);
            var prQuantifier    = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));

            // Act
            var quantifierResult = await prQuantifier.Quantify(quantifierInput);

            // Assert
            Assert.True(!string.IsNullOrEmpty(quantifierResult.Label));
            Assert.Equal(2, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(0, quantifierResult.QuantifiedLinesDeleted);
        }
Beispiel #5
0
        public async Task Quantify_IgnoreSpacesFalse()
        {
            // Arrange
            gitRepoHelpers.AddUntrackedFileToRepoWithContent("fake.cs", "some text\n\nmore text");
            context.LanguageOptions.IgnoreSpaces = false;
            var prQuantifier    = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));

            // Act
            var quantifierResult = await prQuantifier.Quantify(quantifierInput);

            // Assert
            Assert.True(!string.IsNullOrEmpty(quantifierResult.Label));
            Assert.Equal(3, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(0, quantifierResult.QuantifiedLinesDeleted);
        }