public async Task CanGetAdditionsAndDeletionsPerWeek()
 {
     using (var context = await _client.CreateRepositoryContext("public-repo"))
     {
         var repository = new RepositorySummary(context);
         await CommitToRepository(repository);
         var commitActivities = await _client.Repository.Statistics.GetCodeFrequency(repository.Owner, repository.Name);
         Assert.NotNull(commitActivities);
         Assert.True(commitActivities.AdditionsAndDeletionsByWeek.Any());
     }
 }
        public async Task CanCreateAndRetrieveEmptyContributors()
        {
            var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = false };
            using (var context = await _client.CreateRepositoryContext(newRepository))
            {
                var repository = new RepositorySummary(context);
                var contributors = await _client.Repository.Statistics.GetContributors(repository.Owner, repository.Name);

                Assert.NotNull(contributors);
                Assert.Empty(contributors);
            }
        }
Example #3
0
        public void Summary_RepoAtChangesetZero_ReportsParentIsZero()
        {
            CreateRepoWithTwoChangesets();
            Repo.Update(0);

            RepositorySummary summary = Repo.Summary();

            CollectionAssert.AreEqual(
                new[]
            {
                0,
            }, summary.ParentRevisionNumbers);
        }
Example #4
0
        public async Task CanGetAdditionsAndDeletionsPerWeek()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);

                var commitActivities = await _client.Repository.Statistics.GetCodeFrequency(repository.Owner, repository.Name);

                Assert.NotNull(commitActivities);
                Assert.True(commitActivities.AdditionsAndDeletionsByWeek.Any());
            }
        }
        public async Task CanGetPunchCardForRepository()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);

                var punchCard = await _client.Repository.Statistics.GetPunchCard(repository.Owner, repository.Name);

                Assert.NotNull(punchCard);
                Assert.NotNull(punchCard.PunchPoints);
            }
        }
        public async Task CanGetCommitActivityForTheLastYear()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);
                var commitActivities = await _client.Repository.Statistics.GetCommitActivity(repository.Owner, repository.Name);
                Assert.NotNull(commitActivities);
                Assert.Equal(52, commitActivities.Activity.Count);

                var thisWeek = commitActivities.Activity.Last();
                Assert.Equal(1, thisWeek.Total);
                Assert.NotNull(thisWeek.Days);
            }
        }
Example #7
0
        public async Task CanCreateAndRetrieveEmptyContributors()
        {
            var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
            {
                AutoInit = false
            };

            using (var context = await _client.CreateRepositoryContext(newRepository))
            {
                var repository   = new RepositorySummary(context);
                var contributors = await _client.Repository.Statistics.GetContributors(repository.Owner, repository.Name);

                Assert.NotNull(contributors);
                Assert.Empty(contributors);
            }
        }
Example #8
0
        public async Task <RepositorySummary> ReadRepositorySummaryAsync(string owner, string name)
        {
            var repositorySummary = new RepositorySummary();

            var ownerType = await ReadOwnerType(owner).ConfigureAwait(false);

            var cacheKey = GetRepositorySummaryCacheKey(owner, name);

            if (ownerType == OwnerType.Organization)
            {
                repositorySummary = await distributedCache.GetAsync <RepositorySummary>(cacheKey).ConfigureAwait(false);

                if (repositorySummary == null)
                {
                    logger.LogDebug($"retrieving {cacheKey} from source");

                    repositorySummary = await repositorySourceRepository.ReadRepositorySummaryAsync(owner, null, name).ConfigureAwait(false);

                    var cacheOptions = new DistributedCacheEntryOptions
                    {
                        SlidingExpiration = TimeSpan.FromSeconds(cachingSettings.Durations.RepositoryData)
                    };

                    await distributedCache.SetAsync(cacheKey, repositorySummary, cacheOptions).ConfigureAwait(false);
                }
            }
            else if (ownerType == OwnerType.User)
            {
                repositorySummary = await distributedCache.GetAsync <RepositorySummary>(cacheKey).ConfigureAwait(false);

                if (repositorySummary == null)
                {
                    logger.LogDebug($"retrieving {cacheKey} from source");

                    repositorySummary = await repositorySourceRepository.ReadRepositorySummaryAsync(null, owner, name).ConfigureAwait(false);

                    var cacheOptions = new DistributedCacheEntryOptions
                    {
                        SlidingExpiration = TimeSpan.FromSeconds(cachingSettings.Durations.RepositoryData)
                    };

                    await distributedCache.SetAsync(cacheKey, repositorySummary, cacheOptions).ConfigureAwait(false);
                }
            }

            return(repositorySummary);
        }
Example #9
0
        public async Task CanGetCommitActivityForTheLastYear()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);

                var commitActivities = await _client.Repository.Statistics.GetCommitActivity(repository.Owner, repository.Name);

                Assert.NotNull(commitActivities);
                Assert.Equal(52, commitActivities.Activity.Count);

                var thisWeek = commitActivities.Activity.Last();
                Assert.Equal(1, thisWeek.Total);
                Assert.NotNull(thisWeek.Days);
            }
        }
Example #10
0
        public void Summary_Merge_ReportsInMerge()
        {
            CreateRepositoryWithMergeConflicts();
            try
            {
                Repo.Merge(new MergeCommand()
                           .WithMergeTool(MergeTools.InternalMerge));
            }
            catch (NotSupportedException)
            {
                Assert.Inconclusive("Merge tool not supported in this version");
            }

            RepositorySummary summary = Repo.Summary();

            Assert.That(summary.IsInMerge, Is.True);
        }
Example #11
0
        public void Summary_Merge_ReportsCorrectParents()
        {
            CreateRepositoryWithMergeConflicts();

            try
            {
                Repo.Merge(new MergeCommand()
                           .WithMergeTool(MergeTools.InternalMerge));
            }
            catch (NotSupportedException)
            {
                Assert.Inconclusive("Merge tool not supported in this version");
            }

            RepositorySummary summary = Repo.Summary();

            CollectionAssert.AreEqual(new[] { 2, 1 }, summary.ParentRevisionNumbers);
        }
Example #12
0
        public void Summary_MergeWithConflicts_ReportsConflicts()
        {
            CreateRepositoryWithMergeConflicts();

            try
            {
                Repo.Merge(new MergeCommand()
                           .WithMergeTool(MergeTools.InternalMerge));
            }
            catch (NotSupportedException)
            {
                Assert.Inconclusive("Merge tool not supported in this version");
            }

            RepositorySummary summary = Repo.Summary();

            Assert.That(summary.NumberOfUnresolvedFiles, Is.EqualTo(1));
        }
        public async Task CanCreateAndRetrieveContributors()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);
                var contributors = await _client.Repository.Statistics.GetContributors(repository.Owner, repository.Name);

                Assert.NotNull(contributors);
                Assert.Equal(1, contributors.Count);

                var soleContributor = contributors.First();
                Assert.NotNull(soleContributor.Author);
                Assert.True(soleContributor.Author.Login == repository.Owner);

                Assert.Equal(1, soleContributor.Weeks.Count);
                Assert.Equal(1, soleContributor.Total);
            }
        }
Example #14
0
        public async Task CanCreateAndRetrieveContributors()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                var repository = new RepositorySummary(context);
                await CommitToRepository(repository);

                var contributors = await _client.Repository.Statistics.GetContributors(repository.Owner, repository.Name);

                Assert.NotNull(contributors);
                Assert.Equal(1, contributors.Count);

                var soleContributor = contributors.First();
                Assert.NotNull(soleContributor.Author);
                Assert.True(soleContributor.Author.Login == repository.Owner);

                Assert.Equal(1, soleContributor.Weeks.Count);
                Assert.Equal(1, soleContributor.Total);
            }
        }
 public async Task CanGetParticipationStatistics()
 {
     using (var context = await _client.CreateRepositoryContext("public-repo"))
     {
         var repository = new RepositorySummary(context);
         await CommitToRepository(repository);
         var weeklyCommitCounts = await _client.Repository.Statistics.GetParticipation(repository.Owner, repository.Name);
         Assert.Equal(52, weeklyCommitCounts.All.Count);
     }
 }
Example #16
0
        public async Task <CursorPagedResults <RepositorySummary> > ReadRepositorySummariesAsync(string organization, string user, int take, string endCursor)
        {
            string loginType = null;
            string login     = null;

            var query = @"
            query ($login: String!, $take: Int, $after: String) {
              #LOGIN_TYPE#(login: $login) {
                repositories(first: $take, after: $after, orderBy: {field: PUSHED_AT, direction: DESC}) {
                  nodes {
                      url
                      createdAt
                      pushedAt
                  }
                  pageInfo {
                    hasNextPage
                    endCursor
                  }
                }
              }
            }
            ";


            if (!string.IsNullOrWhiteSpace(user))
            {
                loginType = "user";
                login     = user;
            }
            else
            {
                loginType = "organization";
                login     = organization;
            }

            query = query.Replace("#LOGIN_TYPE#", loginType);

            var variables = new { login = login, take = take, after = endCursor };

            GraphQlNodesParent <Model.Github.GraphQL.Repository> graphQLRepositories = null;

            if (loginType == "user")
            {
                var graphQLUser = await graphQLClient.QueryAsync <Model.Github.GraphQL.User>(query, variables).ConfigureAwait(false);

                graphQLRepositories = graphQLUser.Repositories;
            }
            else
            {
                var graphQLOrganization = await graphQLClient.QueryAsync <Model.Github.GraphQL.Organization>(query, variables).ConfigureAwait(false);

                graphQLRepositories = graphQLOrganization.Repositories;
            }

            var cursorPagedResults = new CursorPagedResults <RepositorySummary>();

            cursorPagedResults.EndCursor  = graphQLRepositories.PageInfo.EndCursor;
            cursorPagedResults.MoreToRead = graphQLRepositories.PageInfo.HasNextPage;

            var results = new List <RepositorySummary>();

            foreach (var graphQLRepository in graphQLRepositories.Nodes)
            {
                var repositorySummary = new RepositorySummary
                {
                    CreatedAt = graphQLRepository.CreatedAt,
                    UpdatedAt = graphQLRepository.PushedAt.Value,
                    Url       = graphQLRepository.Url
                };

                results.Add(repositorySummary);
            }

            cursorPagedResults.Results = results;

            return(cursorPagedResults);
        }
        private async Task<Commit> CommitToRepository(RepositorySummary repositorySummary)
        {
            var owner = repositorySummary.Owner;
            var repository = repositorySummary.Name;
            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8
            };
            var blobResult = await _client.Git.Blob.Create(owner, repository, blob);

            var newTree = new NewTree();
            newTree.Tree.Add(new NewTreeItem
            {
                Type = TreeType.Blob,
                Mode = FileMode.File,
                Path = "README.md",
                Sha = blobResult.Sha
            });

            var treeResult = await _client.Git.Tree.Create(owner, repository, newTree);

            var newCommit = new NewCommit("test-commit", treeResult.Sha);

            var commit = await _fixture.Create(owner, repository, newCommit);
            return commit;
        }
 public async Task CanGetPunchCardForRepository()
 {
     using (var context = await _client.CreateRepositoryContext("public-repo"))
     {
         var repository = new RepositorySummary(context);
         await CommitToRepository(repository);
         var punchCard = await _client.Repository.Statistics.GetPunchCard(repository.Owner, repository.Name);
         Assert.NotNull(punchCard);
         Assert.NotNull(punchCard.PunchPoints);
     }
 }