From 503959b27caa60e323ae039c77d5d1aeab255ac3 Mon Sep 17 00:00:00 2001 From: half-ogre Date: Wed, 9 Oct 2013 11:27:54 -0700 Subject: [PATCH 1/4] add method for DELETE /repos/:owner/:name --- Octokit/Clients/RepositoriesClient.cs | 15 +++++++++++++++ Octokit/IRepositoriesClient.cs | 8 ++++++++ 2 files changed, 23 insertions(+) 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. /// From 35727b87a542f03db879f85d4143b819847dfb98 Mon Sep 17 00:00:00 2001 From: half-ogre Date: Wed, 9 Oct 2013 11:30:20 -0700 Subject: [PATCH 2/4] add observable counterparts --- .../Clients/ObservableRepositoriesClient.cs | 16 ++++++++++++++++ .../IObservableRepositoriesClient.cs | 10 ++++++++++ 2 files changed, 26 insertions(+) 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. From 0bbfa4b41b9195fc2b41edb1a22e8d09b2634851 Mon Sep 17 00:00:00 2001 From: half-ogre Date: Wed, 9 Oct 2013 11:32:53 -0700 Subject: [PATCH 3/4] unit tests for deleting a repo --- .../Clients/RepositoriesClientTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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] From a51a9f2c7fbd85871f4372102556a467a4caed1f Mon Sep 17 00:00:00 2001 From: half-ogre Date: Wed, 9 Oct 2013 11:47:30 -0700 Subject: [PATCH 4/4] integration test for deleting a repo --- .../RepositoriesClientTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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]