From ddab946e07c6df43666202e548c8e909ce288cdd Mon Sep 17 00:00:00 2001 From: Amy Palamountain Date: Sat, 15 Feb 2014 20:59:09 +1300 Subject: [PATCH] Line up with the api - what is this all about :lipstick: --- .../Clients/StatisticsClientTests.cs | 4 +- .../Clients/StatisticsClientTests.cs | 8 ++-- Octokit/Clients/IStatisticsClient.cs | 8 ++-- Octokit/Clients/StatisticsClient.cs | 12 ++--- Octokit/Models/Response/Participation.cs | 48 +++++++++++++++++++ Octokit/Models/Response/WeeklyCommitCounts.cs | 11 ----- Octokit/Octokit-Mono.csproj | 2 +- Octokit/Octokit-MonoAndroid.csproj | 2 +- Octokit/Octokit-Monotouch.csproj | 2 +- Octokit/Octokit-netcore45.csproj | 2 +- Octokit/Octokit.csproj | 2 +- 11 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 Octokit/Models/Response/Participation.cs delete mode 100644 Octokit/Models/Response/WeeklyCommitCounts.cs diff --git a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs index 523d9f72..f129ab94 100644 --- a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs @@ -62,11 +62,11 @@ namespace Octokit.Tests.Integration.Clients } [IntegrationTest] - public async Task CanGetCommitCountsPerWeek() + public async Task CanGetParticipationStatistics() { var repository = await CreateRepository(); await CommitToRepository(repository); - var weeklyCommitCounts = await _client.Statistics.GetCommitCountsPerWeek(repository.Owner, repository.Name); + var weeklyCommitCounts = await _client.Statistics.GetParticipation(repository.Owner, repository.Name); Assert.NotNull(weeklyCommitCounts); Assert.NotNull(weeklyCommitCounts.All); Assert.NotNull(weeklyCommitCounts.Owner); diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index 388ae75b..91e1cd64 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -118,23 +118,23 @@ namespace Octokit.Tests.Clients var client = Substitute.For(); var statisticsClient = new StatisticsClient(client); - statisticsClient.GetCommitCountsPerWeek("username", "repositoryName"); + statisticsClient.GetParticipation("username", "repositoryName"); - client.Received().GetQueuedOperation(expectedEndPoint, Args.CancellationToken); + client.Received().GetQueuedOperation(expectedEndPoint, Args.CancellationToken); } [Fact] public async Task ThrowsIfGivenNullOwner() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetCommitCountsPerWeek(null, "repositoryName")); + await AssertEx.Throws(() => statisticsClient.GetParticipation(null, "repositoryName")); } [Fact] public async Task ThrowsIfGivenNullRepositoryName() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetCommitCountsPerWeek("owner", null)); + await AssertEx.Throws(() => statisticsClient.GetParticipation("owner", null)); } } diff --git a/Octokit/Clients/IStatisticsClient.cs b/Octokit/Clients/IStatisticsClient.cs index 5534f837..88ae7b62 100644 --- a/Octokit/Clients/IStatisticsClient.cs +++ b/Octokit/Clients/IStatisticsClient.cs @@ -63,8 +63,8 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// Returns from oldest week to now - Task GetCommitCountsPerWeek(string owner, string repositoryName); + /// Returns from oldest week to now + Task GetParticipation(string owner, string repositoryName); /// /// Returns the total commit counts for the owner and total commit counts in total. @@ -72,8 +72,8 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request - /// Returns from oldest week to now - Task GetCommitCountsPerWeek(string owner, string repositoryName, CancellationToken cancellationToken); + /// Returns from oldest week to now + Task GetParticipation(string owner, string repositoryName, CancellationToken cancellationToken); /// /// Returns a list of the number of commits per hour in each day diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index 49651ca2..bb27a955 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -101,10 +101,10 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// Returns from oldest week to now - public Task GetCommitCountsPerWeek(string owner, string repositoryName) + /// Returns from oldest week to now + public Task GetParticipation(string owner, string repositoryName) { - return GetCommitCountsPerWeek(owner, repositoryName, CancellationToken.None); + return GetParticipation(owner, repositoryName, CancellationToken.None); } /// @@ -113,14 +113,14 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request - /// Returns from oldest week to now - public async Task GetCommitCountsPerWeek(string owner, string repositoryName, CancellationToken cancellationToken) + /// Returns from oldest week to now + public async Task GetParticipation(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName); - return await ApiConnection.GetQueuedOperation(endpoint,cancellationToken); + return await ApiConnection.GetQueuedOperation(endpoint,cancellationToken); } /// diff --git a/Octokit/Models/Response/Participation.cs b/Octokit/Models/Response/Participation.cs new file mode 100644 index 00000000..d0a0478a --- /dev/null +++ b/Octokit/Models/Response/Participation.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Octokit +{ + /// + /// Returns the total commit counts for the owner and total commit counts in total in the last 52 weeks + /// + public class Participation + { + /// + /// Returns the commit counts made each week, for the last 52 weeks + /// + public IEnumerable All { get; set; } + + /// + /// Returns the commit counts made by the owner each week, for the last 52 weeks + /// + public IEnumerable Owner { get; set; } + + /// + /// The total number of commits made by the owner in the last 52 weeks. + /// + /// + public int TotalCommitsByOwner() + { + return Owner.Sum(); + } + + /// + /// The total number of commits made by contributors in the last 52 weeks. + /// + /// + public int TotalCommitsByContributors() + { + return All.Sum() - Owner.Sum(); + } + + /// + /// The total number of commits made in the last 52 weeks. + /// + /// + public int TotalCommits() + { + return All.Sum(); + } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/WeeklyCommitCounts.cs b/Octokit/Models/Response/WeeklyCommitCounts.cs deleted file mode 100644 index 4532e0de..00000000 --- a/Octokit/Models/Response/WeeklyCommitCounts.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace Octokit -{ - public class WeeklyCommitCounts - { - public IEnumerable All { get; set; } - - public IEnumerable Owner { get; set; } - } -} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index e5a2b777..d67ef61f 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -139,7 +139,6 @@ - @@ -275,6 +274,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index eaf3fad6..c27473ee 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -281,10 +281,10 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 2dc53bcb..77c169ba 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -276,10 +276,10 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 246c419f..71d0a665 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -239,7 +239,6 @@ - @@ -273,6 +272,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index edb86ebb..b4900a5c 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -199,7 +199,7 @@ - +