Skip to content

Commit

Permalink
Merge pull request #376 from octokit/shiftkey/convention-tests-part-deux
Browse files Browse the repository at this point in the history
Convention Tests - Part Deux
  • Loading branch information
haacked committed Feb 20, 2014
2 parents 5a1ce62 + cf0dfe1 commit c048349
Show file tree
Hide file tree
Showing 25 changed files with 232 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;

namespace Octokit.Reactive.Clients
namespace Octokit.Reactive
{
public interface IObservableDeploymentStatusClient
{
Expand Down
7 changes: 6 additions & 1 deletion Octokit.Reactive/Clients/IObservableDeploymentsClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Octokit.Reactive.Clients
namespace Octokit.Reactive
{
public interface IObservableDeploymentsClient
{
Expand Down Expand Up @@ -28,5 +28,10 @@ public interface IObservableDeploymentsClient
/// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
/// <returns>The created <see cref="Deployment"></returns>
IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment);

/// <summary>
///
/// </summary>
IObservableDeploymentStatusClient Status { get; }
}
}
20 changes: 20 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using Octokit.Reactive.Clients;

namespace Octokit.Reactive
{
Expand Down Expand Up @@ -99,6 +100,22 @@ public interface IObservableRepositoriesClient
/// </remarks>
IObservableCommitStatusClient CommitStatus { get; }

/// <summary>
/// Client for GitHub's Repository Deployments API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/deployment/">Collaborators API documentation</a> for more details
/// </remarks>
IObservableDeploymentsClient Deployment { get; }

/// <summary>
/// Client for GitHub's Repository Statistics API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/statistics/">Statistics API documentation</a> for more details
///</remarks>
IObservableStatisticsClient Statistics { get; }

/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
Expand Down Expand Up @@ -188,11 +205,14 @@ public interface IObservableRepositoriesClient
/// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
IObservable<Repository> Edit(string owner, string name, RepositoryUpdate update);

/// <summary>
/// A client for GitHub's Repo Collaborators.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API documentation</a> for more details
/// </remarks>
IObservableRepoCollaboratorsClient RepoCollaborators { get; }

IObservablePullRequestsClient PullRequest { get; }
}
}
33 changes: 33 additions & 0 deletions Octokit.Reactive/Clients/IObservableStatisticsClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Octokit.Response;

namespace Octokit.Reactive
{
Expand All @@ -12,5 +13,37 @@ public interface IObservableStatisticsClient
/// <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);

/// <summary>
/// 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>The last year of <see cref="CommitActivity"/></returns>
IObservable<CommitActivity> GetCommitActivity(string owner, string repositoryName);

/// <summary>
/// Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <returns>Returns a weekly aggregate of the number additions and deletion</returns>
IObservable<CodeFrequency> GetCodeFrequency(string owner, string repositoryName);

/// <summary>
/// Returns the total commit counts for the owner and total commit counts in total.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <returns>Returns <see cref="Participation"/>from oldest week to now</returns>
IObservable<Participation> GetParticipation(string owner, string repositoryName);

/// <summary>
/// Returns a list of the number of commits per hour in each day
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <returns>Returns commit counts per hour in each day</returns>
IObservable<PunchCard> GetPunchCard(string owner, string repositoryName);
}
}
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/IObservableUsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ public interface IObservableUsersClient
/// See the <a href="http://developer.github.com/v3/users/followers/">Followers API documentation</a> for more information.
///</remarks>
IObservableFollowersClient Followers { get; }

/// <summary>
/// A client for GitHub's User Emails API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/emails/">Emails API documentation</a> for more information.
///</remarks>
IObservableUserEmailsClient Email { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ObservableDeploymentStatusClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Deployment.Status;
_client = client.Repository.Deployment.Status;
_connection = client.Connection;
}

Expand Down
9 changes: 8 additions & 1 deletion Octokit.Reactive/Clients/ObservableDeploymentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public ObservableDeploymentsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Deployment;
_client = client.Repository.Deployment;
_connection = client.Connection;

Status = new ObservableDeploymentStatusClient(client);
}

/// <summary>
Expand Down Expand Up @@ -51,5 +53,10 @@ public IObservable<Deployment> Create(string owner, string name, NewDeployment n
{
return _client.Create(owner, name, newDeployment).ToObservable();
}

/// <summary>
///
/// </summary>
public IObservableDeploymentStatusClient Status { get; private set; }
}
}
29 changes: 29 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Clients;
using Octokit.Reactive.Internal;

namespace Octokit.Reactive
Expand All @@ -20,6 +21,9 @@ public ObservableRepositoriesClient(IGitHubClient client)
_connection = client.Connection;
CommitStatus = new ObservableCommitStatusClient(client);
RepoCollaborators = new ObservableRepoCollaboratorsClient(client);
Deployment = new ObservableDeploymentsClient(client);
Statistics = new ObservableStatisticsClient(client);
PullRequest = new ObservablePullRequestsClient(client);
}

/// <summary>
Expand Down Expand Up @@ -160,6 +164,22 @@ public IObservable<string> GetReadmeHtml(string owner, string name)
/// </remarks>
public IObservableCommitStatusClient CommitStatus { get; private set; }

/// <summary>
/// Client for GitHub's Repository Deployments API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/deployment/">Collaborators API documentation</a> for more details
/// </remarks>
public IObservableDeploymentsClient Deployment { get; private set; }

/// <summary>
/// Client for GitHub's Repository Statistics API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/statistics/">Statistics API documentation</a> for more details
///</remarks>
public IObservableStatisticsClient Statistics { get; private set; }

/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
Expand Down Expand Up @@ -299,11 +319,20 @@ public IObservable<Repository> Edit(string owner, string name, RepositoryUpdate
return _client.Edit(owner, name, update).ToObservable();
}

/// <summary>
/// A client for GitHub's Repo Collaborators.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API documentation</a> for more details
/// </remarks>
public IObservableRepoCollaboratorsClient RepoCollaborators { get; private set; }

/// <summary>
/// Client for managing pull requests.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/pulls/">Pull Requests API documentation</a> for more details
/// </remarks>
public IObservablePullRequestsClient PullRequest { get; private set; }
}
}
35 changes: 34 additions & 1 deletion Octokit.Reactive/Clients/ObservableStatisticsClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;
using Octokit.Response;

namespace Octokit.Reactive
{
Expand All @@ -19,7 +20,39 @@ public IObservable<IEnumerable<Contributor>> GetContributors(string owner, strin
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Statistics.GetContributors(owner, repositoryName).ToObservable();
return _client.Repository.Statistics.GetContributors(owner, repositoryName).ToObservable();
}

public IObservable<CommitActivity> GetCommitActivity(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Repository.Statistics.GetCommitActivity(owner, repositoryName).ToObservable();
}

public IObservable<CodeFrequency> GetCodeFrequency(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Repository.Statistics.GetCodeFrequency(owner, repositoryName).ToObservable();
}

public IObservable<Participation> GetParticipation(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Repository.Statistics.GetParticipation(owner, repositoryName).ToObservable();
}

public IObservable<PunchCard> GetPunchCard(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Repository.Statistics.GetPunchCard(owner, repositoryName).ToObservable();
}
}
}
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/ObservableUsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public ObservableUsersClient(IGitHubClient client)
_client = client.User;

Followers = new ObservableFollowersClient(client);
Email = new ObservableUserEmailsClient(client);
}

/// <summary>
Expand Down Expand Up @@ -57,5 +58,13 @@ public IObservable<User> Update(UserUpdate user)
/// See the <a href="http://developer.github.com/v3/users/followers/">Followers API documentation</a> for more information.
///</remarks>
public IObservableFollowersClient Followers { get; private set; }

/// <summary>
/// A client for GitHub's User Emails API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/emails/">Emails API documentation</a> for more information.
///</remarks>
public IObservableUserEmailsClient Email { get; private set; }
}
}
11 changes: 10 additions & 1 deletion Octokit.Tests.Conventions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Octokit.Reactive;

Expand All @@ -20,7 +21,15 @@ public static ParameterInfo[] GetParametersOrdered(this MethodInfo method)

public static MethodInfo[] GetMethodsOrdered(this Type type)
{
return type.GetMethods().OrderBy(m => m.Name).ToArray();
// BF: for the moment, i don't care about checking
// for parameters which are accepting CancellationTokens
// In Rx, disposing of the subscriber should have
// the same effect as cancelling the token, so we should
// think about how we want to ensure these conventions are
// validated
return type.GetMethods().OrderBy(m => m.Name)
.Where(m => m.GetParameters().All(p => p.ParameterType != typeof(CancellationToken)))
.ToArray();
}

public static TypeInfo GetTypeInfo(this Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DeploymentStatusClientTests()
Credentials = Helper.Credentials
};

_deploymentsClient = _gitHubClient.Deployment;
_deploymentsClient = _gitHubClient.Repository.Deployment;

var newRepository = new NewRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DeploymentsClientTests()
Credentials = Helper.Credentials
};

_deploymentsClient = _gitHubClient.Deployment;
_deploymentsClient = _gitHubClient.Repository.Deployment;

var newRepository = new NewRepository
{
Expand Down
10 changes: 5 additions & 5 deletions Octokit.Tests.Integration/Clients/StatisticsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task CanCreateAndRetrieveCommit()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var contributors = await _client.Statistics.GetContributors(repository.Owner, repository.Name);
var contributors = await _client.Repository.Statistics.GetContributors(repository.Owner, repository.Name);

Assert.NotNull(contributors);
Assert.True(contributors.Count() == 1);
Expand All @@ -42,7 +42,7 @@ public async Task CanGetCommitActivityForTheLastYear()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var commitActivities = await _client.Statistics.GetCommitActivity(repository.Owner, repository.Name);
var commitActivities = await _client.Repository.Statistics.GetCommitActivity(repository.Owner, repository.Name);
Assert.NotNull(commitActivities);
Assert.True(commitActivities.Activity.Count() == 52);

Expand All @@ -56,7 +56,7 @@ public async Task CanGetAdditionsAndDeletionsPerWeek()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var commitActivities = await _client.Statistics.GetCodeFrequency(repository.Owner, repository.Name);
var commitActivities = await _client.Repository.Statistics.GetCodeFrequency(repository.Owner, repository.Name);
Assert.NotNull(commitActivities);
Assert.True(commitActivities.AdditionsAndDeletionsByWeek.Any());
}
Expand All @@ -66,7 +66,7 @@ public async Task CanGetParticipationStatistics()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var weeklyCommitCounts = await _client.Statistics.GetParticipation(repository.Owner, repository.Name);
var weeklyCommitCounts = await _client.Repository.Statistics.GetParticipation(repository.Owner, repository.Name);
Assert.NotNull(weeklyCommitCounts);
Assert.NotNull(weeklyCommitCounts.All);
Assert.NotNull(weeklyCommitCounts.Owner);
Expand All @@ -77,7 +77,7 @@ public async Task CanGetPunchCardForRepository()
{
var repository = await CreateRepository();
await CommitToRepository(repository);
var punchCard = await _client.Statistics.GetPunchCard(repository.Owner, repository.Name);
var punchCard = await _client.Repository.Statistics.GetPunchCard(repository.Owner, repository.Name);
Assert.NotNull(punchCard);
Assert.NotNull(punchCard.PunchPoints);
}
Expand Down
Loading

0 comments on commit c048349

Please sign in to comment.