💄 for commit activities

This commit is contained in:
Amy Palamountain
2014-02-16 14:33:08 +13:00
parent 5a168f0924
commit 71029212b9
11 changed files with 64 additions and 21 deletions
@@ -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);
}
@@ -58,7 +58,7 @@ namespace Octokit.Tests.Clients
var client = Substitute.For<IApiConnection>();
var statisticsClient = new StatisticsClient(client);
statisticsClient.GetCommitActivityForTheLastYear("username", "repositoryName");
statisticsClient.GetCommitActivity("username", "repositoryName");
client.Received().GetQueuedOperation<IEnumerable<WeeklyCommitActivity>>(expectedEndPoint, Args.CancellationToken);
}
@@ -67,14 +67,14 @@ namespace Octokit.Tests.Clients
public async Task ThrowsIfGivenNullOwner()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCommitActivityForTheLastYear(null, "repositoryName"));
await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCommitActivity(null, "repositoryName"));
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCommitActivityForTheLastYear("owner", null));
await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCommitActivity("owner", null));
}
}
+6 -6
View File
@@ -25,21 +25,21 @@ namespace Octokit
Task<IEnumerable<Contributor>> GetContributors(string owner, string repositoryName, CancellationToken cancellationToken);
/// <summary>
/// Returns a list of last year of commit activity by <see cref="WeeklyCommitActivity"/>.
/// Returns the last year of commit activity grouped by week.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <returns>A list of <see cref="WeeklyCommitActivity"/></returns>
Task<IEnumerable<WeeklyCommitActivity>> GetCommitActivityForTheLastYear(string owner, string repositoryName);
/// <returns>The last year of <see cref="CommitActivity"/></returns>
Task<CommitActivity> GetCommitActivity(string owner, string repositoryName);
/// <summary>
/// Returns a list of last year of commit activity by <see cref="WeeklyCommitActivity"/>.
/// Returns the last year of commit activity grouped by week.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="cancellationToken">A token used to cancel this potentially long running request</param>
/// <returns>A list of <see cref="WeeklyCommitActivity"/></returns>
Task<IEnumerable<WeeklyCommitActivity>> GetCommitActivityForTheLastYear(string owner, string repositoryName, CancellationToken cancellationToken);
/// <returns>The last year of <see cref="CommitActivity"/></returns>
Task<CommitActivity> GetCommitActivity(string owner, string repositoryName, CancellationToken cancellationToken);
/// <summary>
/// Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
+9 -8
View File
@@ -43,30 +43,31 @@ namespace Octokit
}
/// <summary>
/// Returns a list of last year of commit activity by <see cref="WeeklyCommitActivity"/>.
/// Returns the last year of commit activity grouped by week.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <returns>A list of <see cref="WeeklyCommitActivity"/></returns>
public Task<IEnumerable<WeeklyCommitActivity>> GetCommitActivityForTheLastYear(string owner, string repositoryName)
/// <returns>The last year of <see cref="CommitActivity"/></returns>
public Task<CommitActivity> GetCommitActivity(string owner, string repositoryName)
{
return GetCommitActivityForTheLastYear(owner, repositoryName, CancellationToken.None);
return GetCommitActivity(owner, repositoryName, CancellationToken.None);
}
/// <summary>
/// Returns a list of last year of commit activity by <see cref="WeeklyCommitActivity"/>.
/// Returns the last year of commit activity grouped by week.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="cancellationToken">A token used to cancel this potentially long running request</param>
/// <returns>A list of <see cref="WeeklyCommitActivity"/></returns>
public async Task<IEnumerable<WeeklyCommitActivity>> GetCommitActivityForTheLastYear(string owner, string repositoryName, CancellationToken cancellationToken)
/// <returns>The last year of <see cref="CommitActivity"/></returns>
public async Task<CommitActivity> 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<IEnumerable<WeeklyCommitActivity>>(endpoint,cancellationToken);
var activity = await ApiConnection.GetQueuedOperation<IEnumerable<WeeklyCommitActivity>>(endpoint,cancellationToken);
return new CommitActivity(activity);
}
/// <summary>
+17
View File
@@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace Octokit
{
public class CommitActivity
{
public CommitActivity(IEnumerable<WeeklyCommitActivity> activity)
{
Activity = activity;
}
/// <summary>
/// Returns the last year of commit activity grouped by week.
/// </summary>
public IEnumerable<WeeklyCommitActivity> Activity { get; private set; }
}
}
@@ -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.
/// <summary>
/// The days array is a group of commits per day, starting on Sunday.
/// </summary>
public IEnumerable<int> Days { get; set; }
/// <summary>
/// Totally number of commits made this week.
/// </summary>
public int Total { get; set; }
/// <summary>
/// The week of commits
/// </summary>
public int Week { get; set; }
/// <summary>
/// Get the number of commits made on any <see cref="DayOfWeek"/>
/// </summary>
/// <param name="dayOfWeek">The day of the week</param>
/// <returns>The number of commits made</returns>
public int GetCommitCountOn(DayOfWeek dayOfWeek)
{
return Days.ElementAt((int)dayOfWeek);
}
}
}
+1
View File
@@ -277,6 +277,7 @@
<Compile Include="Models\Response\Participation.cs" />
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -287,6 +287,7 @@
<Compile Include="Models\Response\Participation.cs" />
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+1
View File
@@ -282,6 +282,7 @@
<Compile Include="Models\Response\Participation.cs" />
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -275,6 +275,7 @@
<Compile Include="Models\Response\Participation.cs" />
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+1
View File
@@ -125,6 +125,7 @@
<Compile Include="Clients\TreesClient.cs" />
<Compile Include="Models\Response\Branch.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
<Compile Include="Models\Response\Emoji.cs" />
<Compile Include="Models\Response\Contributor.cs" />
<Compile Include="Models\Response\GistComment.cs" />