From 71029212b9457d48b326f49f7b09f5c7e524ffd4 Mon Sep 17 00:00:00 2001 From: Amy Palamountain Date: Sun, 16 Feb 2014 14:33:08 +1300 Subject: [PATCH] :lipstick: for commit activities --- .../Clients/StatisticsClientTests.cs | 6 ++--- .../Clients/StatisticsClientTests.cs | 6 ++--- Octokit/Clients/IStatisticsClient.cs | 12 +++++----- Octokit/Clients/StatisticsClient.cs | 17 +++++++------- Octokit/Models/Response/CommitActivity.cs | 17 ++++++++++++++ .../Models/Response/WeeklyCommitActivity.cs | 22 ++++++++++++++++++- Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 11 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 Octokit/Models/Response/CommitActivity.cs diff --git a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs index 13fc0a01..141adaf4 100644 --- a/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/StatisticsClientTests.cs @@ -42,11 +42,11 @@ namespace Octokit.Tests.Integration.Clients { var repository = await CreateRepository(); await CommitToRepository(repository); - var commitActivities = await _client.Statistics.GetCommitActivityForTheLastYear(repository.Owner, repository.Name); + var commitActivities = await _client.Statistics.GetCommitActivity(repository.Owner, repository.Name); Assert.NotNull(commitActivities); - Assert.True(commitActivities.Count() == 52); + Assert.True(commitActivities.Activity.Count() == 52); - var thisWeek = commitActivities.Last(); + var thisWeek = commitActivities.Activity.Last(); Assert.True(thisWeek.Total == 1); Assert.NotNull(thisWeek.Days); } diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index fb4d995a..eb42efa7 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -58,7 +58,7 @@ namespace Octokit.Tests.Clients var client = Substitute.For(); var statisticsClient = new StatisticsClient(client); - statisticsClient.GetCommitActivityForTheLastYear("username", "repositoryName"); + statisticsClient.GetCommitActivity("username", "repositoryName"); client.Received().GetQueuedOperation>(expectedEndPoint, Args.CancellationToken); } @@ -67,14 +67,14 @@ namespace Octokit.Tests.Clients public async Task ThrowsIfGivenNullOwner() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetCommitActivityForTheLastYear(null, "repositoryName")); + await AssertEx.Throws(() => statisticsClient.GetCommitActivity(null, "repositoryName")); } [Fact] public async Task ThrowsIfGivenNullRepositoryName() { var statisticsClient = new StatisticsClient(Substitute.For()); - await AssertEx.Throws(() => statisticsClient.GetCommitActivityForTheLastYear("owner", null)); + await AssertEx.Throws(() => statisticsClient.GetCommitActivity("owner", null)); } } diff --git a/Octokit/Clients/IStatisticsClient.cs b/Octokit/Clients/IStatisticsClient.cs index 45e22114..24ce787b 100644 --- a/Octokit/Clients/IStatisticsClient.cs +++ b/Octokit/Clients/IStatisticsClient.cs @@ -25,21 +25,21 @@ namespace Octokit Task> GetContributors(string owner, string repositoryName, CancellationToken cancellationToken); /// - /// Returns a list of last year of commit activity by . + /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository - /// A list of - Task> GetCommitActivityForTheLastYear(string owner, string repositoryName); + /// The last year of + Task GetCommitActivity(string owner, string repositoryName); /// - /// Returns a list of last year of commit activity by . + /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request - /// A list of - Task> GetCommitActivityForTheLastYear(string owner, string repositoryName, CancellationToken cancellationToken); + /// The last year of + Task GetCommitActivity(string owner, string repositoryName, CancellationToken cancellationToken); /// /// Returns a weekly aggregate of the number of additions and deletions pushed to a repository. diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index 2241def4..ec6af044 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -43,30 +43,31 @@ namespace Octokit } /// - /// Returns a list of last year of commit activity by . + /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository - /// A list of - public Task> GetCommitActivityForTheLastYear(string owner, string repositoryName) + /// The last year of + public Task GetCommitActivity(string owner, string repositoryName) { - return GetCommitActivityForTheLastYear(owner, repositoryName, CancellationToken.None); + return GetCommitActivity(owner, repositoryName, CancellationToken.None); } /// - /// Returns a list of last year of commit activity by . + /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request - /// A list of - public async Task> GetCommitActivityForTheLastYear(string owner, string repositoryName, CancellationToken cancellationToken) + /// The last year of + public async Task GetCommitActivity(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); - return await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); + var activity = await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); + return new CommitActivity(activity); } /// diff --git a/Octokit/Models/Response/CommitActivity.cs b/Octokit/Models/Response/CommitActivity.cs new file mode 100644 index 00000000..2b5161c4 --- /dev/null +++ b/Octokit/Models/Response/CommitActivity.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace Octokit +{ + public class CommitActivity + { + public CommitActivity(IEnumerable activity) + { + Activity = activity; + } + + /// + /// Returns the last year of commit activity grouped by week. + /// + public IEnumerable Activity { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/WeeklyCommitActivity.cs b/Octokit/Models/Response/WeeklyCommitActivity.cs index 8f94a37d..da4d9e69 100644 --- a/Octokit/Models/Response/WeeklyCommitActivity.cs +++ b/Octokit/Models/Response/WeeklyCommitActivity.cs @@ -1,14 +1,34 @@ +using System; using System.Collections.Generic; +using System.Linq; namespace Octokit { public class WeeklyCommitActivity { - //The days array is a group of commits per day, starting on Sunday. + /// + /// The days array is a group of commits per day, starting on Sunday. + /// public IEnumerable Days { get; set; } + /// + /// Totally number of commits made this week. + /// public int Total { get; set; } + /// + /// The week of commits + /// public int Week { get; set; } + + /// + /// Get the number of commits made on any + /// + /// The day of the week + /// The number of commits made + public int GetCommitCountOn(DayOfWeek dayOfWeek) + { + return Days.ElementAt((int)dayOfWeek); + } } } \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 72113a07..745c2f44 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -277,6 +277,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 070a61de..fd1227c5 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -287,6 +287,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index fda4b0fb..77910035 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -282,6 +282,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index dbf32c21..f0d9515f 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -275,6 +275,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 16b654da..b14e0d2e 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -125,6 +125,7 @@ +