From 815da312e854518af0f0a6d900794f91b12f05d4 Mon Sep 17 00:00:00 2001 From: Amy Palamountain Date: Sat, 1 Feb 2014 13:56:07 +1300 Subject: [PATCH] Get commit activity for the last year --- .../Clients/StatisticsClientTests.cs | 32 +++++++++++++++++++ Octokit/Clients/IStatisticsClient.cs | 8 +++++ Octokit/Clients/StatisticsClient.cs | 22 +++++++++++++ .../Models/Response/WeeklyCommitActivity.cs | 14 ++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 7 files changed, 79 insertions(+) create mode 100644 Octokit/Models/Response/WeeklyCommitActivity.cs diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index 3ac79336..26a380c0 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -49,5 +49,37 @@ namespace Octokit.Tests.Clients await AssertEx.Throws(() => statisticsClient.GetContributors("owner", null)); } } + + public class TheGetCommitActivityForTheLastYearMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/commit_activity", UriKind.Relative); + + var connection = Substitute.For(); + var client = Substitute.For(); + client.Connection.Returns(connection); + var statisticsClient = new StatisticsClient(client); + + statisticsClient.GetCommitActivityForTheLastYear("username", "repositoryName"); + + connection.Received().GetAsync>(expectedEndPoint); + } + + [Fact] + public async Task ThrowsIfGivenNullOwner() + { + var statisticsClient = new StatisticsClient(Substitute.For()); + await AssertEx.Throws(() => statisticsClient.GetCommitActivityForTheLastYear(null, "repositoryName")); + } + + [Fact] + public async Task ThrowsIfGivenNullRepositoryName() + { + var statisticsClient = new StatisticsClient(Substitute.For()); + await AssertEx.Throws(() => statisticsClient.GetCommitActivityForTheLastYear("owner", null)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/IStatisticsClient.cs b/Octokit/Clients/IStatisticsClient.cs index 9e7ad461..760f24e6 100644 --- a/Octokit/Clients/IStatisticsClient.cs +++ b/Octokit/Clients/IStatisticsClient.cs @@ -12,5 +12,13 @@ namespace Octokit /// The name of the repository /// A list of Task> GetContributors(string owner, string repositoryName); + + /// + /// Returns a list of last year of commit activity by . + /// + /// The owner of the repository + /// The name of the repository + /// A list of + Task> GetCommitActivityForTheLastYear(string owner, string repositoryName); } } \ No newline at end of file diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index e1f18fb4..9d6e0a3b 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -35,5 +35,27 @@ namespace Octokit } return response.BodyAsObject; } + + /// + /// Returns a list of last year of commit activity by . + /// + /// The owner of the repository + /// The name of the repository + /// A list of + public async Task> GetCommitActivityForTheLastYear(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + var endpoint = "/repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); + + var response = await Connection.GetAsync>(endpoint, null, null); + + if (response.StatusCode == HttpStatusCode.Accepted) + { + return await GetCommitActivityForTheLastYear(owner, repositoryName); + } + return response.BodyAsObject; + } } } \ No newline at end of file diff --git a/Octokit/Models/Response/WeeklyCommitActivity.cs b/Octokit/Models/Response/WeeklyCommitActivity.cs new file mode 100644 index 00000000..8f94a37d --- /dev/null +++ b/Octokit/Models/Response/WeeklyCommitActivity.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Octokit +{ + public class WeeklyCommitActivity + { + //The days array is a group of commits per day, starting on Sunday. + public IEnumerable Days { get; set; } + + public int Total { get; set; } + + public int Week { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index cf173873..5ef5d09b 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -138,6 +138,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 0522d5da..d235e05b 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -238,6 +238,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index f0915d70..c149e7dc 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -196,6 +196,7 @@ +