Merge pull request #691 from rms81/add-get-all-pub-repos

Fix for issue #686 List all public repositories
This commit is contained in:
Brendan Forster
2015-03-04 20:45:38 +10:30
7 changed files with 92 additions and 0 deletions
@@ -38,6 +38,17 @@ namespace Octokit.Reactive
/// <returns>A <see cref="Repository"/></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<Repository> Get(string owner, string name);
/// <summary>
/// Retrieves every public <see cref="Repository"/>.
/// </summary>
/// <remarks>
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
IObservable<Repository> GetAllPublic();
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the current user.
@@ -90,6 +90,18 @@ namespace Octokit.Reactive
return _client.Get(owner, name).ToObservable();
}
/// <summary>
/// Retrieves every public <see cref="Repository"/>.
/// </summary>
/// <remarks>
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
public IObservable<Repository> GetAllPublic()
{
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.AllPublicRepositories());
}
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the current user.
/// </summary>
@@ -548,6 +548,20 @@ public class RepositoriesClientTests
}
}
public class TheGetAllPublicMethod
{
[IntegrationTest(Skip = "Takes too long to run.")]
public async Task ReturnsAllPublicRepositories()
{
var github = Helper.GetAuthenticatedClient();
var repositories = await github.Repository.GetAllPublic();
Assert.True(repositories.Count > 80);
}
}
public class TheGetAllForOrgMethod
{
[IntegrationTest]
@@ -260,6 +260,21 @@ namespace Octokit.Tests.Clients
}
}
public class TheGetAllPublicMethod
{
[Fact]
public void RequestsTheCorrectUrlAndReturnsRepositories()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
client.GetAllPublic();
connection.Received()
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "/repositories"));
}
}
public class TheGetAllForCurrentMethod
{
[Fact]
+14
View File
@@ -94,6 +94,20 @@ namespace Octokit
/// <returns>A <see cref="Repository"/></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Repository> Get(string owner, string name);
/// <summary>
/// Gets all public repositories.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">API documentation</a> for more information.
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
Task<IReadOnlyList<Repository>> GetAllPublic();
/// <summary>
/// Gets all repositories owned by the current user.
+15
View File
@@ -174,6 +174,21 @@ namespace Octokit
return ApiConnection.Get<Repository>(endpoint);
}
/// <summary>
/// Gets all public repositories.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">API documentation</a> for more information.
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
public Task<IReadOnlyList<Repository>> GetAllPublic()
{
return ApiConnection.GetAll<Repository>(ApiUrls.AllPublicRepositories());
}
/// <summary>
/// Gets all repositories owned by the current user.
/// </summary>
+11
View File
@@ -19,6 +19,17 @@ namespace Octokit
static readonly Uri _oauthAuthorize = new Uri("login/oauth/authorize", UriKind.Relative);
static readonly Uri _oauthAccesToken = new Uri("login/oauth/access_token", UriKind.Relative);
/// <summary>
/// Returns the <see cref="Uri"/> that returns all public repositories in
/// response to a GET request.
/// </summary>
/// <returns></returns>
public static Uri AllPublicRepositories()
{
return "/repositories".FormatUri();
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the repositories for the currently logged in user in
/// response to a GET request. A POST to this URL creates a new repository.