Skip to content

Commit

Permalink
Fix implementation of the DeleteBranch (location and return type)
Browse files Browse the repository at this point in the history
Cover it with a unit Test
And reference it in the Coverage.md documentation
  • Loading branch information
mnivet committed Jun 21, 2019
1 parent 4d87fd5 commit 16c591b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 9 additions & 0 deletions SharpBucket/V2/EndPoints/BranchResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,14 @@ public List<Branch> ListBranches(ListParameters parameters)
throw new ArgumentNullException(nameof(parameters));
return _repositoriesEndPoint.ListBranches(_accountName, _slug, parameters);
}

/// <summary>
/// Removes a branch.
/// </summary>
/// <param name="branchName">The name of the branch to delete.</param>
public void DeleteBranch(string branchName)
{
_repositoriesEndPoint.DeleteBranch(_accountName, _slug, branchName);
}
}
}
4 changes: 2 additions & 2 deletions SharpBucket/V2/EndPoints/RepositoriesEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ internal List<Branch> ListBranches(string accountName, string slug, ListParamete
return GetPaginatedValues<Branch>(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<Branch>(overrideUrl);
_sharpBucketV2.Delete(overrideUrl);
}

#endregion
Expand Down
9 changes: 0 additions & 9 deletions SharpBucket/V2/EndPoints/RepositoryResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ public List<Fork> ListForks()
public BranchResource BranchesResource => this._branchesResource ??
(_branchesResource = new BranchResource(_accountName, _slug, _repositoriesEndPoint));

/// <summary>
/// Removes a branch.
/// </summary>
/// <returns></returns>
public Branch DeleteBranch(string branchName)
{
return _repositoriesEndPoint.DeleteBranch(_accountName, _slug, branchName);
}

#endregion

#region Pull Requests Resource
Expand Down
4 changes: 4 additions & 0 deletions SharpBucketTests/GitHelpers/TestRepositoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
12 changes: 12 additions & 0 deletions SharpBucketTests/V2/EndPoints/BranchResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 16c591b

Please sign in to comment.