diff --git a/Octokit.Reactive/Clients/IObservableReleasesClient.cs b/Octokit.Reactive/Clients/IObservableReleasesClient.cs index 446fc5756f..a8bfa4cc4a 100644 --- a/Octokit.Reactive/Clients/IObservableReleasesClient.cs +++ b/Octokit.Reactive/Clients/IObservableReleasesClient.cs @@ -32,6 +32,18 @@ public interface IObservableReleasesClient [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] IObservable Get(string owner, string name, int id); + /// + /// Gets the latest for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The repository's owner + /// The repository's name + /// Thrown when a general API error occurs. + /// The latest specified by the repository + IObservable GetLatest(string owner, string name); + /// /// Creates a new for the specified repository. /// diff --git a/Octokit.Reactive/Clients/ObservableReleasesClient.cs b/Octokit.Reactive/Clients/ObservableReleasesClient.cs index 8c687af132..dfc9478e1e 100644 --- a/Octokit.Reactive/Clients/ObservableReleasesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReleasesClient.cs @@ -55,6 +55,23 @@ public IObservable Get(string owner, string name, int id) return _client.Get(owner, name, id).ToObservable(); } + /// + /// Gets the latest for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The repository's owner + /// The repository's name + /// Thrown when a general API error occurs. + /// The latest specified by the repository + public IObservable GetLatest(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.GetLatest(owner, name).ToObservable(); + } /// /// Creates a new for the specified repository. /// diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 95ded50edd..d4d5379add 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -59,6 +59,31 @@ public async Task EnsuresNonNullArguments() } } + public class TheGetLatestReleaseMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReleasesClient(connection); + + client.GetLatest("fake", "repo"); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/latest"), + null); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var releasesClient = new ReleasesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => releasesClient.GetLatest(null, "name")); + await Assert.ThrowsAsync(() => releasesClient.GetLatest("", "name")); + await Assert.ThrowsAsync(() => releasesClient.GetLatest("owner", null)); + await Assert.ThrowsAsync(() => releasesClient.GetLatest("owner", "")); + } + } public class TheCreateReleaseMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs index 3bec9c746f..c07d3586cb 100644 --- a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs @@ -66,7 +66,30 @@ public void EnsuresNonNullArguments() Assert.Throws(() => releasesClient.Get("owner", "", 1)); } } + public class TheGetLatestReleaseMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableReleasesClient(gitHubClient); + + client.GetLatest("fake", "repo"); + + gitHubClient.Release.Received(1).GetLatest("fake", "repo"); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var releasesClient = new ObservableReleasesClient(Substitute.For()); + Assert.Throws(() => releasesClient.GetLatest(null, "name")); + Assert.Throws(() => releasesClient.GetLatest("", "name")); + Assert.Throws(() => releasesClient.GetLatest("owner", null)); + Assert.Throws(() => releasesClient.GetLatest("owner", "")); + } + } public class TheCreateReleaseMethod { [Fact] diff --git a/Octokit/Clients/IReleasesClient.cs b/Octokit/Clients/IReleasesClient.cs index 06d61fb1b6..d04b0cd3e4 100644 --- a/Octokit/Clients/IReleasesClient.cs +++ b/Octokit/Clients/IReleasesClient.cs @@ -40,6 +40,18 @@ public interface IReleasesClient [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(string owner, string name, int id); + /// + /// Gets the latest for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The repository's owner + /// The repository's name + /// Thrown when a general API error occurs. + /// The latest specified by the repository + Task GetLatest(string owner, string name); + /// /// Creates a new for the specified repository. /// diff --git a/Octokit/Clients/ReleasesClient.cs b/Octokit/Clients/ReleasesClient.cs index be2b3a5c57..fae7bc4d8f 100644 --- a/Octokit/Clients/ReleasesClient.cs +++ b/Octokit/Clients/ReleasesClient.cs @@ -60,6 +60,25 @@ public Task Get(string owner, string name, int id) return ApiConnection.Get(endpoint); } + /// + /// Gets the latest for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The repository's owner + /// The repository's name + /// Thrown when a general API error occurs. + /// The latest specified by the repository + public Task GetLatest(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.LatestRelease(owner, name); + return ApiConnection.Get(endpoint); + } + /// /// Creates a new for the specified repository. /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 5368fa1585..229c1970a2 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -139,6 +139,17 @@ public static Uri Releases(string owner, string name, int id) return "repos/{0}/{1}/releases/{2}".FormatUri(owner, name, id); } + /// + /// Returns the that returns the latest release for the specified repository + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri LatestRelease(string owner, string name) + { + return "repos/{0}/{1}/releases/latest".FormatUri(owner, name); + } + /// /// Returns the that returns all the assets for the specified release for the specified repository. ///