-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 Repository Pages client #1061
Changes from 7 commits
1a5e3d1
15c8ff9
4265b62
3003fb3
0435cd2
e690e22
c113292
564dea5
0201d01
ca187df
134f44f
ef06aa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
public interface IObservableRepositoryPagesClient | ||
{ | ||
/// <summary> | ||
/// Gets the page metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] | ||
IObservable<Page> Get(string owner, string repositoryName); | ||
/// <summary> | ||
/// Gets all build metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
IObservable<PagesBuild> GetAllBuilds(string owner, string repositoryName); | ||
/// <summary> | ||
/// Gets the build metadata for the last build for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
IObservable<PagesBuild> GetLatestBuild(string owner, string repositoryName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Octokit.Reactive.Internal; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient | ||
{ | ||
readonly IRepositoryPagesClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableRepositoryPagesClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Repository.Page; | ||
_connection = client.Connection; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the page metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] | ||
public IObservable<Page> Get(string owner, string repositoryName) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); | ||
|
||
return _client.Get(owner, repositoryName).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets all build metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
public IObservable<PagesBuild> GetAllBuilds(string owner, string repositoryName) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); | ||
|
||
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the build metadata for the last build for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
public IObservable<PagesBuild> GetLatestBuild(string owner, string repositoryName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need a rename (and to call the right method on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I missed that :sad: |
||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); | ||
|
||
return _client.GetLatestBuild(owner, repositoryName).ToObservable(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using NSubstitute; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Clients | ||
{ | ||
public class RepositoryPagesClientTests | ||
{ | ||
public class TheGetMethod | ||
{ | ||
[Fact] | ||
public void RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
client.Get("fake", "repo"); | ||
|
||
connection.Received().Get<Page>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages"), null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how these tests should have passed before the merge, as I managed to break an old PR when I merged There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, I'll merge that first pass at the documentation into |
||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name")); | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null)); | ||
} | ||
} | ||
|
||
public class TheGetBuildsMethod | ||
{ | ||
[Fact] | ||
public void RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
client.GetAllBuilds("fake", "repo"); | ||
|
||
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds")); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name")); | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null)); | ||
} | ||
} | ||
|
||
public class TheGetLatestBuildMethod | ||
{ | ||
[Fact] | ||
public void RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
client.GetLatestBuild("fake", "repo"); | ||
|
||
connection.Received().Get<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds/latest"), null); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new RepositoryPagesClient(connection); | ||
|
||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name")); | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Repository Pages API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information. | ||
/// </remarks> | ||
public interface IRepositoryPagesClient | ||
{ | ||
/// <summary> | ||
/// Gets the page metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] | ||
Task<Page> Get(string owner, string repositoryName); | ||
/// <summary> | ||
/// Gets all build metadata for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
Task<IReadOnlyList<PagesBuild>> GetAllBuilds(string owner, string repositoryName); | ||
/// <summary> | ||
/// Gets the build metadata for the last build for a given repository | ||
/// </summary> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="repositoryName">The name of the repository</param> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information. | ||
/// </remarks> | ||
/// <returns></returns> | ||
Task<PagesBuild> GetLatestBuild(string owner, string repositoryName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the
Builds
suffix from here as well