mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Added get release by tag endpoint (#1793)
* 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
This commit is contained in:
@@ -66,9 +66,20 @@ namespace Octokit.Reactive
|
||||
/// <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>
|
||||
@@ -78,9 +89,19 @@ namespace Octokit.Reactive
|
||||
/// <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>
|
||||
|
||||
@@ -107,6 +107,25 @@ namespace Octokit.Reactive
|
||||
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>
|
||||
@@ -121,6 +140,22 @@ namespace Octokit.Reactive
|
||||
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>
|
||||
|
||||
@@ -168,6 +168,50 @@ public class ReleasesClientTests
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -84,5 +84,49 @@ namespace Octokit.Tests.Integration.Reactive
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,17 @@ namespace Octokit.Tests.Clients
|
||||
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()
|
||||
{
|
||||
@@ -134,6 +145,17 @@ namespace Octokit.Tests.Clients
|
||||
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()
|
||||
{
|
||||
@@ -144,6 +166,16 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
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, ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,28 @@ namespace Octokit.Tests.Reactive
|
||||
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()
|
||||
{
|
||||
@@ -136,6 +158,13 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
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", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,20 @@ namespace Octokit
|
||||
/// <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>
|
||||
@@ -78,9 +89,19 @@ namespace Octokit
|
||||
/// <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>
|
||||
|
||||
@@ -105,6 +105,26 @@ namespace Octokit
|
||||
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>
|
||||
@@ -120,6 +140,23 @@ namespace Octokit
|
||||
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>
|
||||
|
||||
@@ -215,6 +215,18 @@ namespace Octokit
|
||||
return "repos/{0}/{1}/releases/{2}".FormatUri(owner, name, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns a single release for the specified repository
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="tag">The tag of the release</param>
|
||||
/// <returns></returns>
|
||||
public static Uri Releases(string owner, string name, string tag)
|
||||
{
|
||||
return "repos/{0}/{1}/releases/tags/{2}".FormatUri(owner, name, tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns the latest release for the specified repository
|
||||
/// </summary>
|
||||
@@ -3082,6 +3094,17 @@ namespace Octokit
|
||||
return "repositories/{0}/releases/{1}".FormatUri(repositoryId, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns a single release for the specified repository
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="tag">The tag of the release</param>
|
||||
/// <returns>The <see cref="Uri"/> that returns a single release for the specified repository</returns>
|
||||
public static Uri Releases(long repositoryId, string tag)
|
||||
{
|
||||
return "repositories/{0}/releases/tags/{1}".FormatUri(repositoryId, tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for a repository branch.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user