diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index 2ba2cb82..2e3c02f6 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -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(); } + /// + /// Deletes a repository for the specified owner and name. + /// + /// The owner of the repository + /// The name of the repository + /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. + /// An for the operation + public IObservable Delete(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Delete(owner, name).ToObservable(); + } + public IObservable Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); diff --git a/Octokit.Reactive/IObservableRepositoriesClient.cs b/Octokit.Reactive/IObservableRepositoriesClient.cs index 66050f4f..710a6281 100644 --- a/Octokit.Reactive/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/IObservableRepositoriesClient.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Reactive; namespace Octokit.Reactive { @@ -19,6 +20,15 @@ namespace Octokit.Reactive /// A instance describing the new repository to create /// An instance for the created repository IObservable Create(string organizationLogin, NewRepository newRepository); + + /// + /// Deletes a repository for the specified owner and name. + /// + /// The owner of the repository + /// The name of the repository + /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. + /// An for the operation + IObservable Delete(string owner, string name); /// /// Retrieves the for the specified owner and name. diff --git a/Octokit.Tests.Integration/RepositoriesClientTests.cs b/Octokit.Tests.Integration/RepositoriesClientTests.cs index 3c983063..209a8467 100644 --- a/Octokit.Tests.Integration/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/RepositoriesClientTests.cs @@ -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] diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 9ab39bc5..74a1ab5b 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -94,6 +94,29 @@ namespace Octokit.Tests.Clients } } + public class TheDeleteMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var repositoriesClient = new RepositoriesClient(Substitute.For>()); + + await AssertEx.Throws(async () => await repositoriesClient.Delete(null, "aRepoName")); + await AssertEx.Throws(async () => await repositoriesClient.Delete("anOwner", null)); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var client = Substitute.For>(); + var repositoriesClient = new RepositoriesClient(client); + + await repositoriesClient.Delete("theOwner", "theRepoName"); + + client.Received().Delete(Arg.Is(u => u.ToString() == "/repos/theOwner/theRepoName")); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index e0261271..bfc46d5c 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -45,6 +45,21 @@ namespace Octokit return await Client.Create(endpoint, newRepository); } + /// + /// Deletes a repository for the specified owner and name. + /// + /// The owner of the repository + /// The name of the repository + /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. + 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 Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); diff --git a/Octokit/IRepositoriesClient.cs b/Octokit/IRepositoriesClient.cs index 8ae1c9e0..5d87cefc 100644 --- a/Octokit/IRepositoriesClient.cs +++ b/Octokit/IRepositoriesClient.cs @@ -22,6 +22,14 @@ namespace Octokit /// A instance for the created repository Task Create(string organizationLogin, NewRepository newRepository); + /// + /// Deletes a repository for the specified owner and name. + /// + /// The owner of the repository + /// The name of the repository + /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. + Task Delete(string owner, string name); + /// /// Retrieves the for the specified owner and name. ///