diff --git a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs index f129ab94..13fc0a01 100644 --- a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs @@ -56,9 +56,9 @@ namespace Octokit.Tests.Integration.Clients { var repository = await CreateRepository(); await CommitToRepository(repository); - var commitActivities = await _client.Statistics.GetAdditionsAndDeletionsPerWeek(repository.Owner, repository.Name); + var commitActivities = await _client.Statistics.GetCodeFrequency(repository.Owner, repository.Name); Assert.NotNull(commitActivities); - Assert.True(commitActivities.Any()); + Assert.True(commitActivities.AdditionsAndDeletionsByWeek.Any()); } [IntegrationTest] diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index 91e1cd64..fb4d995a 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -88,7 +88,7 @@ namespace Octokit.Tests.Clients var client = Substitute.For(); var statisticsClient = new StatisticsClient(client); - statisticsClient.GetAdditionsAndDeletionsPerWeek("username", "repositoryName"); + statisticsClient.GetCodeFrequency("username", "repositoryName"); client.Received().GetQueuedOperation>(expectedEndPoint, Args.CancellationToken); } @@ -97,14 +97,14 @@ namespace Octokit.Tests.Clients public async Task ThrowsIfGivenNullOwner() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetAdditionsAndDeletionsPerWeek(null, "repositoryName")); + await AssertEx.Throws(() => statisticsClient.GetCodeFrequency(null, "repositoryName")); } [Fact] public async Task ThrowsIfGivenNullRepositoryName() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetAdditionsAndDeletionsPerWeek("owner", null)); + await AssertEx.Throws(() => statisticsClient.GetCodeFrequency("owner", null)); } } diff --git a/Octokit/Clients/IStatisticsClient.cs b/Octokit/Clients/IStatisticsClient.cs index 88ae7b62..45e22114 100644 --- a/Octokit/Clients/IStatisticsClient.cs +++ b/Octokit/Clients/IStatisticsClient.cs @@ -47,7 +47,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// Returns a weekly aggregate of the number additions and deletion - Task> GetAdditionsAndDeletionsPerWeek(string owner, string repositoryName); + Task GetCodeFrequency(string owner, string repositoryName); /// /// Returns a weekly aggregate of the number of additions and deletions pushed to a repository. @@ -56,7 +56,7 @@ namespace Octokit /// The name of the repository /// A token used to cancel this potentially long running request /// Returns a weekly aggregate of the number additions and deletion - Task> GetAdditionsAndDeletionsPerWeek(string owner, string repositoryName, CancellationToken cancellationToken); + Task GetCodeFrequency(string owner, string repositoryName, CancellationToken cancellationToken); /// /// Returns the total commit counts for the owner and total commit counts in total. diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index bb27a955..2241def4 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -75,9 +75,9 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// Returns a weekly aggregate of the number additions and deletion - public Task> GetAdditionsAndDeletionsPerWeek(string owner, string repositoryName) + public Task GetCodeFrequency(string owner, string repositoryName) { - return GetAdditionsAndDeletionsPerWeek(owner, repositoryName, CancellationToken.None); + return GetCodeFrequency(owner, repositoryName, CancellationToken.None); } /// @@ -87,13 +87,14 @@ namespace Octokit /// The name of the repository /// A token used to cancel this potentially long running request /// Returns a weekly aggregate of the number additions and deletion - public async Task> GetAdditionsAndDeletionsPerWeek(string owner, string repositoryName, CancellationToken cancellationToken) + public async Task GetCodeFrequency(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName); - return await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); + var rawFrequencies = await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); + return new CodeFrequency(rawFrequencies); } /// diff --git a/Octokit/Models/Response/AdditionsAndDeletions.cs b/Octokit/Models/Response/AdditionsAndDeletions.cs new file mode 100644 index 00000000..908bb496 --- /dev/null +++ b/Octokit/Models/Response/AdditionsAndDeletions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; + +namespace Octokit +{ + public class AdditionsAndDeletions + { + public AdditionsAndDeletions(IList additionsAndDeletions) + { + Ensure.ArgumentNotNull(additionsAndDeletions, "additionsAndDeletions"); + if (additionsAndDeletions.Count != 3) + { + throw new ArgumentException("Addition and deletion aggregate must only contain three data points."); + } + Timestamp = additionsAndDeletions[0]; + Additions = additionsAndDeletions[1]; + Deletions = additionsAndDeletions[2]; + } + + public int Timestamp { get; private set; } + + public int Additions { get; private set; } + + public int Deletions { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/CodeFrequency.cs b/Octokit/Models/Response/CodeFrequency.cs new file mode 100644 index 00000000..f8dbc8f5 --- /dev/null +++ b/Octokit/Models/Response/CodeFrequency.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Octokit +{ + public class CodeFrequency + { + public CodeFrequency(IEnumerable> rawFrequencies) + { + Ensure.ArgumentNotNull(rawFrequencies, "rawFrequencies"); + AdditionsAndDeletionsByWeek = rawFrequencies.Select(point => new AdditionsAndDeletions(point)).ToList(); + } + + /// + /// A weekly aggregate of the number of additions and deletions pushed to a repository. + /// + public IEnumerable AdditionsAndDeletionsByWeek { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index d67ef61f..72113a07 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -275,6 +275,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index c27473ee..070a61de 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -285,6 +285,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 77c169ba..fda4b0fb 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -280,6 +280,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 71d0a665..dbf32c21 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -273,6 +273,8 @@ + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index b4900a5c..16b654da 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -107,6 +107,7 @@ + @@ -123,6 +124,7 @@ +