From 16c591b9330c3fd088fc276662bdc7e9537cb7b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Nivet?= Date: Fri, 21 Jun 2019 20:15:16 +0200 Subject: [PATCH] Fix implementation of the DeleteBranch (location and return type) Cover it with a unit Test And reference it in the Coverage.md documentation --- Coverage.md | 5 ++++- SharpBucket/V2/EndPoints/BranchResource.cs | 9 +++++++++ SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs | 4 ++-- SharpBucket/V2/EndPoints/RepositoryResource.cs | 9 --------- SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs | 4 ++++ SharpBucketTests/V2/EndPoints/BranchResourceTests.cs | 12 ++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Coverage.md b/Coverage.md index 0dd11ada..e81e6350 100644 --- a/Coverage.md +++ b/Coverage.md @@ -448,9 +448,12 @@ The organization of all that routes may slightly differ in the SharpBucket class - /repositories/{username}/{repo_slug}/refs/branches `POST` - Implemented by: none - Tested: no -- /repositories/{username}/{repo_slug}/refs/branches/{name} `GET` `DELETE` +- /repositories/{username}/{repo_slug}/refs/branches/{name} `GET` - Implemented by: none - Tested: no +- /repositories/{username}/{repo_slug}/refs/branches/{name} `DELETE` + - Implemented by: `BranchResource.DeleteBranch(string)` + - Tested: **yes** ### [Tag resource](https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/tags/%7Bname%7D) - /repositories/{username}/{repo_slug}/refs/tags `GET` diff --git a/SharpBucket/V2/EndPoints/BranchResource.cs b/SharpBucket/V2/EndPoints/BranchResource.cs index 910bf79f..970e8d41 100644 --- a/SharpBucket/V2/EndPoints/BranchResource.cs +++ b/SharpBucket/V2/EndPoints/BranchResource.cs @@ -40,5 +40,14 @@ public List ListBranches(ListParameters parameters) throw new ArgumentNullException(nameof(parameters)); return _repositoriesEndPoint.ListBranches(_accountName, _slug, parameters); } + + /// + /// Removes a branch. + /// + /// The name of the branch to delete. + public void DeleteBranch(string branchName) + { + _repositoriesEndPoint.DeleteBranch(_accountName, _slug, branchName); + } } } \ No newline at end of file diff --git a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs index 96939750..dbfce844 100644 --- a/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs +++ b/SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs @@ -376,10 +376,10 @@ internal List ListBranches(string accountName, string slug, ListParamete return GetPaginatedValues(overrideUrl, parameters.Max, parameters.ToDictionary()); } - internal Branch DeleteBranch(string accountName, string repSlug, string branchName) + internal void DeleteBranch(string accountName, string repSlug, string branchName) { var overrideUrl = GetRepositoryUrl(accountName, repSlug, "refs/branches/" + branchName); - return _sharpBucketV2.Delete(overrideUrl); + _sharpBucketV2.Delete(overrideUrl); } #endregion diff --git a/SharpBucket/V2/EndPoints/RepositoryResource.cs b/SharpBucket/V2/EndPoints/RepositoryResource.cs index d9b5e5de..bc0b47dd 100644 --- a/SharpBucket/V2/EndPoints/RepositoryResource.cs +++ b/SharpBucket/V2/EndPoints/RepositoryResource.cs @@ -82,15 +82,6 @@ public List ListForks() public BranchResource BranchesResource => this._branchesResource ?? (_branchesResource = new BranchResource(_accountName, _slug, _repositoriesEndPoint)); - /// - /// Removes a branch. - /// - /// - public Branch DeleteBranch(string branchName) - { - return _repositoriesEndPoint.DeleteBranch(_accountName, _slug, branchName); - } - #endregion #region Pull Requests Resource diff --git a/SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs b/SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs index 0b983e41..86982ffe 100644 --- a/SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs +++ b/SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs @@ -80,6 +80,10 @@ public TestRepositoryInfo FillRepository() AddOrUpdateFile(repository, "src/goodNewWork2.txt", "a second good work in the same pull request to have 2 commits in one pull request"); repository.Commit("second good work", testSignature, testSignature); + // create branchToDelete (no need commits inside, to avoid to lose commit when testing DeleteBranch) + Commands.Checkout(repository, repository.Branches["master"]); + CreateAndSwitchToNewBranch(repository, "branchToDelete"); + // Push All branches repository.Network.Push(repository.Branches, new PushOptions { CredentialsProvider = GitCredentialsProvider.GetCredentials }); } diff --git a/SharpBucketTests/V2/EndPoints/BranchResourceTests.cs b/SharpBucketTests/V2/EndPoints/BranchResourceTests.cs index 79fb9663..be378d79 100644 --- a/SharpBucketTests/V2/EndPoints/BranchResourceTests.cs +++ b/SharpBucketTests/V2/EndPoints/BranchResourceTests.cs @@ -19,5 +19,17 @@ public void ListBranches_NotEmptyRepository_ReturnAtLeastMainBranch() var branches = SampleRepositories.MercurialRepository.BranchesResource.ListBranches(); branches.ShouldNotBeEmpty("There is at least the main branch on a non empty repository"); } + + [Test] + public void DeleteBranch_ExistingBranch_BrancCouldNotBeListedAnymore() + { + var branchResource = SampleRepositories.TestRepository.RepositoryResource.BranchesResource; + var initialBranches = branchResource.ListBranches(); + + branchResource.DeleteBranch("branchToDelete"); + + var remainingBranches = branchResource.ListBranches(); + remainingBranches.Count.ShouldBe(initialBranches.Count - 1); + } } }