mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
Merge pull request #68 from octokit/half-ogre/delete-repo
Add method for DELETE repos/:owner/:name
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
@@ -44,6 +45,21 @@ namespace Octokit.Reactive.Clients
|
||||
return _client.Create(organizationLogin, newRepository).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a repository for the specified owner and name.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <remarks>Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.</remarks>
|
||||
/// <returns>An <see cref="IObservable{Unit}"/> for the operation</returns>
|
||||
public IObservable<Unit> Delete(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _client.Delete(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<Repository> Get(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
@@ -19,6 +20,15 @@ namespace Octokit.Reactive
|
||||
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
|
||||
/// <returns>An <see cref="IObservable{Repository}"/> instance for the created repository</returns>
|
||||
IObservable<Repository> Create(string organizationLogin, NewRepository newRepository);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a repository for the specified owner and name.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <remarks>Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.</remarks>
|
||||
/// <returns>An <see cref="IObservable{Unit}"/> for the operation</returns>
|
||||
IObservable<Unit> Delete(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
||||
|
||||
@@ -228,6 +228,22 @@ namespace Octokit.Tests.Integration
|
||||
// TODO: Add a test for the team_id param once an overload that takes an oranization is added
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task DeletesRepository()
|
||||
{
|
||||
var github = new GitHubClient("Octokit Test Runner")
|
||||
{
|
||||
Credentials = AutomationSettings.Current.GitHubCredentials
|
||||
};
|
||||
var repoName = AutomationSettings.MakeNameWithTimestamp("repo-to-delete");
|
||||
await github.Repository.Create(new NewRepository { Name = repoName });
|
||||
|
||||
Assert.DoesNotThrow(async () => { await github.Repository.Delete(github.Credentials.Login, repoName); });
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAsyncMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
|
||||
@@ -94,6 +94,29 @@ namespace Octokit.Tests.Clients
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection<Repository>>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Delete(null, "aRepoName"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Delete("anOwner", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection<Repository>>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
|
||||
await repositoriesClient.Delete("theOwner", "theRepoName");
|
||||
|
||||
client.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/repos/theOwner/theRepoName"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -45,6 +45,21 @@ namespace Octokit
|
||||
return await Client.Create(endpoint, newRepository);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a repository for the specified owner and name.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <remarks>Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.</remarks>
|
||||
public async Task Delete(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}".FormatUri(owner, name);
|
||||
await Client.Delete(endpoint);
|
||||
}
|
||||
|
||||
public async Task<Repository> Get(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
|
||||
@@ -22,6 +22,14 @@ namespace Octokit
|
||||
/// <returns>A <see cref="Repository"/> instance for the created repository</returns>
|
||||
Task<Repository> Create(string organizationLogin, NewRepository newRepository);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a repository for the specified owner and name.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <remarks>Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.</remarks>
|
||||
Task Delete(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user