diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs new file mode 100644 index 0000000000..8c11afdfb0 --- /dev/null +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -0,0 +1,37 @@ +using NSubstitute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class RepositoryPagesClientTests + { + public class TheGetMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryPagesClient(connection); + + client.Get("fake", "repo"); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/pages")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryPagesClient(connection); + + await Assert.ThrowsAsync(() => client.Get(null, "name")); + await Assert.ThrowsAsync(() => client.Get("owner", null)); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 5dc32016bc..57055097f4 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -93,6 +93,7 @@ + diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 654a4231b9..d88480a6df 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -269,7 +269,7 @@ public interface IRepositoriesClient /// See the Commits API documentation for more details /// IRepositoryCommitsClient Commit { get; } - + /// /// Access GitHub's Releases API. /// @@ -384,5 +384,13 @@ public interface IRepositoriesClient /// New values to update the branch with /// The updated Task EditBranch(string owner, string name, string branch, BranchUpdate update); + + /// + /// A client for GitHub's Repository Pages API. + /// + /// + /// See the Repository Pages API documentation for more information. + /// + IRepositoryPagesClient Page { get; } } } diff --git a/Octokit/Clients/IRepositoryPagesClient.cs b/Octokit/Clients/IRepositoryPagesClient.cs index 71709f9f96..eb3a05553c 100644 --- a/Octokit/Clients/IRepositoryPagesClient.cs +++ b/Octokit/Clients/IRepositoryPagesClient.cs @@ -1,32 +1,39 @@ -using Octokit.Models.Response; -using System; +using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Octokit.Clients +namespace Octokit { /// /// A client for GitHub's Repository Pages API. /// /// - /// See the Repository Pages API documentation for more information. + /// See the Repository Pages API documentation for more information. /// - interface IRepositoryPagesClient + public interface IRepositoryPagesClient { /// /// Gets the page metadata for a given repository /// /// The owner of the repository /// The name of the repository + /// + /// See the API documentation for more information. + /// /// - Task> Get(string owner, string repositoryName); + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] + Task Get(string owner, string repositoryName); /// /// Gets all build metadata for a given repository /// /// The owner of the repository /// The name of the repository + /// + /// See the API documentation for more information. + /// /// Task> GetBuilds(string owner, string repositoryName); /// @@ -34,6 +41,9 @@ interface IRepositoryPagesClient /// /// The owner of the repository /// The name of the repository + /// + /// See the API documentation for more information. + /// /// Task GetLatestBuild(string owner, string repositoryName); } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 8360a97001..0c3c937995 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -44,6 +44,7 @@ public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection) DeployKeys = new RepositoryDeployKeysClient(apiConnection); Merging = new MergingClient(apiConnection); Content = new RepositoryContentsClient(apiConnection); + Page = new RepositoryPagesClient(apiConnection); } /// @@ -577,5 +578,13 @@ public Task GetBranch(string owner, string repositoryName, string branch return ApiConnection.Get(ApiUrls.RepoBranch(owner, repositoryName, branchName), null, AcceptHeaders.ProtectedBranchesApiPreview); } + + /// + /// A client for GitHub's Repository Pages API. + /// + /// + /// See the Repository Pages API documentation for more information. + /// + public IRepositoryPagesClient Page { get; private set; } } } diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs new file mode 100644 index 0000000000..a8492d9fcd --- /dev/null +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Repository Pages API. + /// + /// + /// See the Repository Pages API documentation for more information. + /// + public class RepositoryPagesClient : ApiClient, IRepositoryPagesClient + { + /// + /// Initializes a new GitHub Repository Pages API client. + /// + /// An API connection. + public RepositoryPagesClient(IApiConnection apiConnection) : base(apiConnection) + { + + } + + /// + /// Gets the page metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// + /// See the API documentation for more information. + /// + /// + public Task Get(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + return ApiConnection.Get(ApiUrls.RepositoryPage(owner, repositoryName)); + } + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// + /// See the API documentation for more information. + /// + /// + public Task> GetBuilds(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + return ApiConnection.GetAll(ApiUrls.RepositoryBuilds(owner, repositoryName)); + } + + /// + /// Gets the build metadata for the last build for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// + /// See the API documentation for more information. + /// + /// + public Task GetLatestBuild(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + return ApiConnection.Get(ApiUrls.RepositoryBuildsLatest(owner, repositoryName)); + } + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index f8f79d68cd..ee3b0d22c4 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1554,5 +1554,20 @@ public static Uri RepositoryContent(string owner, string name, string path, stri { return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference); } + + public static Uri RepositoryPage(string owner, string name) + { + return "repos/{0}/{1}/pages".FormatUri(owner, name); + } + + public static Uri RepositoryBuilds(string owner, string name) + { + return "repos/{0}/{1}/pages/builds".FormatUri(owner, name); + } + + public static Uri RepositoryBuildsLatest(string owner, string name) + { + return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name); + } } } diff --git a/Octokit/Models/Response/Page.cs b/Octokit/Models/Response/Page.cs index ddfff06cf2..454f25659e 100644 --- a/Octokit/Models/Response/Page.cs +++ b/Octokit/Models/Response/Page.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace Octokit.Models.Response +namespace Octokit { public enum PagesBuildStatus { diff --git a/Octokit/Models/Response/PagesBuild.cs b/Octokit/Models/Response/PagesBuild.cs index cc11a47d08..15e7069a94 100644 --- a/Octokit/Models/Response/PagesBuild.cs +++ b/Octokit/Models/Response/PagesBuild.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Octokit.Models.Response +namespace Octokit { /// /// Metadata of a Github Pages build. diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 7238ed974d..73a2f14493 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -73,6 +73,7 @@ +