Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Statistics api #296

Merged
merged 55 commits into from
Feb 18, 2014
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
92d3d18
Added stats/contributors client & response objects
ammeep Jan 9, 2014
91b0592
Stubbed implementation of IStatisticsClient
ammeep Jan 9, 2014
af4c82a
Updated signature to include repo name and owner
ammeep Jan 9, 2014
98afca5
renamed parameter
ammeep Jan 10, 2014
feb52c0
Implement client
ammeep Jan 10, 2014
29461db
Test stats client get contributors
ammeep Jan 10, 2014
23ee959
:lipstick: renamed to GetContributors
ammeep Jan 10, 2014
f926187
Added Statistics Client
ammeep Jan 10, 2014
c14acda
:lipstick:
ammeep Jan 10, 2014
fd71335
ObservableStats Client
ammeep Jan 10, 2014
6a66bf9
Observable Client tests
ammeep Jan 10, 2014
60fc710
Added intergration tests for contributors api
ammeep Jan 27, 2014
021ef3d
Retry until call is successful
ammeep Jan 27, 2014
82fcea6
a work around for simple json support for empty root nodes
ammeep Feb 1, 2014
815da31
Get commit activity for the last year
ammeep Feb 1, 2014
c03626c
Simple intergration test for commit activity
ammeep Feb 1, 2014
dd96b8a
One test fixture to rule them all
ammeep Feb 1, 2014
d08c636
Extra asserts for contributors intergration tests
ammeep Feb 1, 2014
e0f4052
:lipstick:
ammeep Feb 1, 2014
34f049f
Extra asserts for this years commit stats
ammeep Feb 1, 2014
d74768b
Added additions and deletions aggregate api
ammeep Feb 1, 2014
6fe41bf
Unit test for addition and deletion aggregate api
ammeep Feb 1, 2014
c7aaa19
Integration test for additions and deletions
ammeep Feb 1, 2014
ab7ce9d
Added weekly commit counts api
ammeep Feb 1, 2014
1394677
Unit test for weekly commit count
ammeep Feb 2, 2014
79e7916
Intergration test for commit counts by week
ammeep Feb 2, 2014
dd7149c
Assert that days get deserialized correctly.
ammeep Feb 2, 2014
71263c3
Added commits per hour each day
ammeep Feb 2, 2014
c209e2a
Integration test for hourly commits
ammeep Feb 2, 2014
3580c13
Basic unit tests for hourly commits
ammeep Feb 2, 2014
5834544
Refactor waiting into it's own method
ammeep Feb 2, 2014
3438326
Moved Queued Wait into IApiConnection
ammeep Feb 2, 2014
706ab46
Assert he makes a get request
ammeep Feb 2, 2014
809ebd1
Unit tests for QueuedOpertaion
ammeep Feb 2, 2014
98e1556
Added cancelation token to request
ammeep Feb 2, 2014
77d3785
Set CancellationToken.None where not needed yet
ammeep Feb 2, 2014
2e1fcd7
Added is any cancellation token argument
ammeep Feb 3, 2014
a1e62ec
GetAsync<T> overload with cancellation token
ammeep Feb 3, 2014
e71c3e3
GetQueuedOperation<T> takes cancellation token
ammeep Feb 3, 2014
a975e77
Fix up mono projects
ammeep Feb 15, 2014
63da057
Provide cancellation token option
ammeep Feb 15, 2014
ec5db2c
:facepunch: card statistics 2.0
ammeep Feb 15, 2014
ddab946
Line up with the api - what is this all about
ammeep Feb 15, 2014
5a168f0
:lipstick: Lets talk about code frequencies
ammeep Feb 15, 2014
7102921
:lipstick: for commit activities
ammeep Feb 16, 2014
8469a50
Unix Timestamp helper
ammeep Feb 16, 2014
0a01e4c
Because A D and C is meaningful....
ammeep Feb 16, 2014
dd15b62
fixed indenting
ammeep Feb 16, 2014
c912825
:lipstick:
ammeep Feb 16, 2014
1a78ed7
Debugger displays
ammeep Feb 16, 2014
668f79d
use the new cancellation token
shiftkey Feb 18, 2014
c3cf8d1
updated tests to use correct mock
shiftkey Feb 18, 2014
5f97d10
removed redundant Send<T> from IHttpClient
shiftkey Feb 18, 2014
66c19ad
:lipstick:
ammeep Feb 18, 2014
36427ea
Merge branch 'master' into ammeep/statistics-api
ammeep Feb 18, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Octokit.Reactive/Clients/IObservableStatisticsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

namespace Octokit.Reactive
{
public interface IObservableStatisticsClient
{
/// <summary>
/// Returns a list of <see cref="Contributor"/> for the given repository
/// </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="Contributor"/></returns>
IObservable<IEnumerable<Contributor>> GetContributors(string owner, string repositoryName);
}
}
25 changes: 25 additions & 0 deletions Octokit.Reactive/Clients/ObservableStatisticsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
public class ObservableStatisticsClient : IObservableStatisticsClient
{
readonly IGitHubClient _client;

public ObservableStatisticsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client;
}

public IObservable<IEnumerable<Contributor>> GetContributors(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Statistics.GetContributors(owner, repositoryName).ToObservable();
}
}
}
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\IObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\IObservableStatisticsClient.cs" />
<Compile Include="Clients\ObservableStatisticsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\IObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\IObservableStatisticsClient.cs" />
<Compile Include="Clients\ObservableStatisticsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\IObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\IObservableStatisticsClient.cs" />
<Compile Include="Clients\ObservableStatisticsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="Clients\IObservableUserEmailsClient.cs" />
<Compile Include="Clients\IObservableWatchedClient.cs" />
<Compile Include="Clients\IObservableFollowersClient.cs" />
<Compile Include="Clients\IObservableStatisticsClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\IObservableBlobClient.cs" />
<Compile Include="Clients\IObservableGistCommentsClient.cs" />
Expand Down Expand Up @@ -120,6 +121,7 @@
<Compile Include="Clients\ObservableRepositoriesClient.cs" />
<Compile Include="Clients\ObservableSshKeysClient.cs" />
<Compile Include="Clients\ObservableStarredClient.cs" />
<Compile Include="Clients\ObservableStatisticsClient.cs" />
<Compile Include="Clients\ObservableTagsClient.cs" />
<Compile Include="Clients\ObservableTreesClient.cs" />
<Compile Include="Clients\ObservableFollowersClient.cs" />
Expand Down
131 changes: 131 additions & 0 deletions Octokit.Tests.Integration/Clients/StatisticsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Integration.Clients
{
public class StatisticsClientTests
{
readonly IGitHubClient _client;
readonly ICommitsClient _fixture;

public StatisticsClientTests()
{
_client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_fixture = _client.GitDatabase.Commit;
}

[IntegrationTest]
public async Task CanCreateAndRetrieveCommit()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var contributors = await _client.Statistics.GetContributors(repository.Owner, repository.Name);

Assert.NotNull(contributors);
Assert.True(contributors.Count() == 1);

var soleContributor = contributors.First();
Assert.NotNull(soleContributor.Author);
Assert.True(soleContributor.Author.Login == repository.Owner);

Assert.True(soleContributor.Weeks.Count() == 1);
Assert.True(soleContributor.Total == 1);
}

[IntegrationTest]
public async Task CanGetCommitActivityForTheLastYear()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var commitActivities = await _client.Statistics.GetCommitActivity(repository.Owner, repository.Name);
Assert.NotNull(commitActivities);
Assert.True(commitActivities.Activity.Count() == 52);

var thisWeek = commitActivities.Activity.Last();
Assert.True(thisWeek.Total == 1);
Assert.NotNull(thisWeek.Days);
}

[IntegrationTest]
public async Task CanGetAdditionsAndDeletionsPerWeek()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var commitActivities = await _client.Statistics.GetCodeFrequency(repository.Owner, repository.Name);
Assert.NotNull(commitActivities);
Assert.True(commitActivities.AdditionsAndDeletionsByWeek.Any());
}

[IntegrationTest]
public async Task CanGetParticipationStatistics()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var weeklyCommitCounts = await _client.Statistics.GetParticipation(repository.Owner, repository.Name);
Assert.NotNull(weeklyCommitCounts);
Assert.NotNull(weeklyCommitCounts.All);
Assert.NotNull(weeklyCommitCounts.Owner);
}

[IntegrationTest]
public async Task CanGetPunchCardForRepository()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var punchCard = await _client.Statistics.GetPunchCard(repository.Owner, repository.Name);
Assert.NotNull(punchCard);
Assert.NotNull(punchCard.PunchPoints);
}

async Task<RepositorySummary> CreateRepository()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
var repository = await _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
return new RepositorySummary
{
Owner = repository.Owner.Login,
Name = repoName
};
}

async Task<Commit> CommitToRepository(RepositorySummary repositorySummary)
{
var owner = repositorySummary.Owner;
var repository = repositorySummary.Name;
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _client.GitDatabase.Blob.Create(owner, repository, blob);

var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = "README.md",
Sha = blobResult.Sha
});

var treeResult = await _client.GitDatabase.Tree.Create(owner, repository, newTree);

var newCommit = new NewCommit("test-commit", treeResult.Sha);

var commit = await _fixture.Create(owner, repository, newCommit);
return commit;
}

class RepositorySummary
{
public string Name { get; set; }

public string Owner { get; set; }
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Clients\IssuesEventsClientTests.cs" />
<Compile Include="Clients\MilestonesClientTests.cs" />
<Compile Include="Clients\ReferencesClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.cs" />
<Compile Include="Clients\TreeClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
<Compile Include="Clients\FollowersClientTests.cs" />
Expand Down
Loading