Skip to content

Commit

Permalink
Added get release by tag endpoint (#1793)
Browse files Browse the repository at this point in the history
* Added get release by tag endpoint

* Added integration tests for get release by tag overload

* tidy up integration tests and add reactive integration tests

* Implement repositoryId based method

* Implement repositoryId based method in Reactive client
  • Loading branch information
tasadar2 authored and ryangribble committed Apr 16, 2018
1 parent 5ffc969 commit 75196b1
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 4 deletions.
25 changes: 23 additions & 2 deletions Octokit.Reactive/Clients/IObservableReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ public interface IObservableReleasesClient
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
IObservable<Release> Get(string owner, string name, int id);

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

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
Expand All @@ -78,9 +89,19 @@ public interface IObservableReleasesClient
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
IObservable<Release> Get(long repositoryId, int id);

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="tag">The tag of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<Release> Get(long repositoryId, string tag);

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

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

return _client.Get(owner, name, tag).ToObservable();
}

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
Expand All @@ -121,6 +140,22 @@ public IObservable<Release> Get(long repositoryId, int id)
return _client.Get(repositoryId, id).ToObservable();
}

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="tag">The tag of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Get(long repositoryId, string tag)
{
Ensure.ArgumentNotNullOrEmptyString(tag, nameof(tag));

return _client.Get(repositoryId, tag).ToObservable();
}

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
44 changes: 44 additions & 0 deletions Octokit.Tests.Integration/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,50 @@ public void Dispose()
}
}

public class TheGetMethod
{
private readonly IReleasesClient _releaseClient;
private readonly IGitHubClient _client;

public TheGetMethod()
{
_client = Helper.GetAuthenticatedClient();
_releaseClient = _client.Repository.Release;
}

[IntegrationTest]
public async Task ReturnsReleaseByTag()
{
var releaseByTag = await _releaseClient.Get("octokit", "octokit.net", "v0.28.0");

Assert.Equal(releaseByTag.Id, 8396883);
Assert.Equal(releaseByTag.Name, "v0.28 - Get to the Chopper!!!");
Assert.Equal(releaseByTag.TagName, "v0.28.0");
}

[IntegrationTest]
public async Task ReturnsReleaseWithRepositoryIdByTag()
{
var releaseByTag = await _releaseClient.Get(7528679, "v0.28.0");

Assert.Equal(releaseByTag.Id, 8396883);
Assert.Equal(releaseByTag.Name, "v0.28 - Get to the Chopper!!!");
Assert.Equal(releaseByTag.TagName, "v0.28.0");
}

[IntegrationTest]
public async Task ThrowsWhenTagNotFound()
{
await Assert.ThrowsAsync<NotFoundException>(() => _releaseClient.Get("octokit", "octokit.net", "0.0"));
}

[IntegrationTest]
public async Task ThrowsWhenTagNotFoundWithRepositoryId()
{
await Assert.ThrowsAsync<NotFoundException>(() => _releaseClient.Get(7528679, "0.0"));
}
}

public class TheGetAllMethod
{
readonly IReleasesClient _releaseClient;
Expand Down
44 changes: 44 additions & 0 deletions Octokit.Tests.Integration/Reactive/ObservableReleaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,49 @@ public async Task ReturnsDistinctResultsBasedOnStartPage()
Assert.NotEqual(firstPage[4].Id, secondPage[4].Id);
}
}

public class TheGetMethod
{
readonly ObservableReleasesClient _releaseClient;

public TheGetMethod()
{
var github = Helper.GetAuthenticatedClient();

_releaseClient = new ObservableReleasesClient(github);
}

[IntegrationTest]
public async Task ReturnsReleaseByTag()
{
var releaseByTag = await _releaseClient.Get("octokit", "octokit.net", "v0.28.0");

Assert.Equal(releaseByTag.Id, 8396883);
Assert.Equal(releaseByTag.Name, "v0.28 - Get to the Chopper!!!");
Assert.Equal(releaseByTag.TagName, "v0.28.0");
}

[IntegrationTest]
public async Task ReturnsReleaseWithRepositoryIdByTag()
{
var releaseByTag = await _releaseClient.Get(7528679, "v0.28.0");

Assert.Equal(releaseByTag.Id, 8396883);
Assert.Equal(releaseByTag.Name, "v0.28 - Get to the Chopper!!!");
Assert.Equal(releaseByTag.TagName, "v0.28.0");
}

[IntegrationTest]
public async Task ThrowsWhenTagNotFound()
{
await Assert.ThrowsAsync<NotFoundException>(async () => await _releaseClient.Get("octokit", "octokit.net", "0.0"));
}

[IntegrationTest]
public async Task ThrowsWhenTagNotFoundWithRepositoryId()
{
await Assert.ThrowsAsync<NotFoundException>(async () => await _releaseClient.Get(7528679, "0.0"));
}
}
}
}
32 changes: 32 additions & 0 deletions Octokit.Tests/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ public async Task RequestsTheCorrectUrl()
connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"));
}

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

await client.Get("fake", "repo", "tag");

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

[Fact]
public async Task RequestsTheCorrectUrlWithRepositoryId()
{
Expand All @@ -134,6 +145,17 @@ public async Task RequestsTheCorrectUrlWithRepositoryId()
connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/releases/1"));
}

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

await client.Get(1, "tag");

connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/releases/tags/tag"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
Expand All @@ -144,6 +166,16 @@ public async Task EnsuresNonNullArguments()

await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get("owner", "", 1));

await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.Get("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get("owner", "name", ""));
await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.Get(null, "name", "tag"));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get("", "name", "tag"));
await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.Get("owner", null, "tag"));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get("owner", "", "tag"));

await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.Get(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => releasesClient.Get(1, ""));
}
}

Expand Down
29 changes: 29 additions & 0 deletions Octokit.Tests/Reactive/ObservableReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ public void RequestsTheCorrectUrlWithRepositoryId()
gitHubClient.Repository.Release.Received(1).Get(1, 1);
}

[Fact]
public void RequestsTheCorrectUrlByTag()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableReleasesClient(gitHubClient);

client.Get("fake", "repo", "tag");

gitHubClient.Repository.Release.Received(1).Get("fake", "repo", "tag");
}

[Fact]
public void RequestsTheCorrectUrlWithRepositoryIdByTag()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableReleasesClient(gitHubClient);

client.Get(1, "tag");

gitHubClient.Repository.Release.Received(1).Get(1, "tag");
}

[Fact]
public void EnsuresNonNullArguments()
{
Expand All @@ -136,6 +158,13 @@ public void EnsuresNonNullArguments()

Assert.Throws<ArgumentException>(() => releasesClient.Get("", "name", 1));
Assert.Throws<ArgumentException>(() => releasesClient.Get("owner", "", 1));

Assert.Throws<ArgumentNullException>(() => releasesClient.Get(null, "name", "tag"));
Assert.Throws<ArgumentException>(() => releasesClient.Get("", "name", "tag"));
Assert.Throws<ArgumentNullException>(() => releasesClient.Get("owner", null, "tag"));
Assert.Throws<ArgumentException>(() => releasesClient.Get("owner", "", "tag"));
Assert.Throws<ArgumentNullException>(() => releasesClient.Get("owner", "name", null));
Assert.Throws<ArgumentException>(() => releasesClient.Get("owner", "name", ""));
}
}

Expand Down
25 changes: 23 additions & 2 deletions Octokit/Clients/IReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ public interface IReleasesClient
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
Task<Release> Get(string owner, string name, int id);

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

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
Expand All @@ -78,9 +89,19 @@ public interface IReleasesClient
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")]
Task<Release> Get(long repositoryId, int id);

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="tag">The tag of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
Task<Release> Get(long repositoryId, string tag);

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

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

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

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
Expand All @@ -120,6 +140,23 @@ public Task<Release> Get(long repositoryId, int id)
return ApiConnection.Get<Release>(endpoint);
}

/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="tag">The tag of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<Release> Get(long repositoryId, string tag)
{
Ensure.ArgumentNotNullOrEmptyString(tag, nameof(tag));

var endpoint = ApiUrls.Releases(repositoryId, tag);
return ApiConnection.Get<Release>(endpoint);
}

/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
Expand Down
Loading

0 comments on commit 75196b1

Please sign in to comment.