Skip to content

Commit

Permalink
Merge pull request #975 from chenjiaming93/GetLatestRelease
Browse files Browse the repository at this point in the history
Implemented GetLatestRelease API.
  • Loading branch information
shiftkey committed Feb 3, 2016
2 parents b70dca4 + e7583c8 commit 7ca0140
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Octokit.Reactive/Clients/IObservableReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public interface IObservableReleasesClient
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
IObservable<Release> Get(string owner, string name, int id);

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The latest <see cref="Release"/> specified by the repository</returns>
IObservable<Release> GetLatest(string owner, string name);

/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions Octokit.Reactive/Clients/ObservableReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public IObservable<Release> Get(string owner, string name, int id)
return _client.Get(owner, name, id).ToObservable();
}

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The latest <see cref="Release"/> specified by the repository</returns>
public IObservable<Release> GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _client.GetLatest(owner, name).ToObservable();
}
/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions Octokit.Tests/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ public async Task EnsuresNonNullArguments()
}
}

public class TheGetLatestReleaseMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new ReleasesClient(connection);

client.GetLatest("fake", "repo");

connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/latest"),
null);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var releasesClient = new ReleasesClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetLatest(null, "name"));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.GetLatest("", "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetLatest("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.GetLatest("owner", ""));
}
}
public class TheCreateReleaseMethod
{
[Fact]
Expand Down
23 changes: 23 additions & 0 deletions Octokit.Tests/Reactive/ObservableReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,30 @@ public void EnsuresNonNullArguments()
Assert.Throws<ArgumentException>(() => releasesClient.Get("owner", "", 1));
}
}
public class TheGetLatestReleaseMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
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<IGitHubClient>());

Assert.Throws<ArgumentNullException>(() => releasesClient.GetLatest(null, "name"));
Assert.Throws<ArgumentException>(() => releasesClient.GetLatest("", "name"));
Assert.Throws<ArgumentNullException>(() => releasesClient.GetLatest("owner", null));
Assert.Throws<ArgumentException>(() => releasesClient.GetLatest("owner", ""));
}
}
public class TheCreateReleaseMethod
{
[Fact]
Expand Down
12 changes: 12 additions & 0 deletions Octokit/Clients/IReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public interface IReleasesClient
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
Task<Release> Get(string owner, string name, int id);

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The latest <see cref="Release"/> specified by the repository</returns>
Task<Release> GetLatest(string owner, string name);

/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions Octokit/Clients/ReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ public Task<Release> Get(string owner, string name, int id)
return ApiConnection.Get<Release>(endpoint);
}

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The latest <see cref="Release"/> specified by the repository</returns>
public Task<Release> GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

var endpoint = ApiUrls.LatestRelease(owner, name);
return ApiConnection.Get<Release>(endpoint);
}

/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ public static Uri Releases(string owner, string name, int id)
return "repos/{0}/{1}/releases/{2}".FormatUri(owner, name, id);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns the latest release for the specified repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public static Uri LatestRelease(string owner, string name)
{
return "repos/{0}/{1}/releases/latest".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all the assets for the specified release for the specified repository.
/// </summary>
Expand Down

0 comments on commit 7ca0140

Please sign in to comment.