From eae86070c092c4f384b4e765f5c4c874fd5476b9 Mon Sep 17 00:00:00 2001 From: astrohart Date: Wed, 30 Jan 2019 13:54:49 -0500 Subject: [PATCH 1/4] Updated ApiUrls.Reference to remove 'refs' from referenceName parameter's value --- Octokit/Helpers/ApiUrls.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 48cf5db7e1..77d08dc806 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3185,7 +3185,8 @@ public static Uri Reference(long repositoryId) /// The for the specified reference. public static Uri Reference(long repositoryId, string referenceName) { - return "repositories/{0}/git/refs/{1}".FormatUri(repositoryId, referenceName); + return "repositories/{0}/git/refs/{1}".FormatUri(repositoryId, + referenceName.Replace("refs/", string.Empty)); } /// From 9c0bb2ac8372fe24dc5efdec6a08434188e0990f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 25 Feb 2020 16:16:32 -0400 Subject: [PATCH 2/4] move fix up into clients and update docs and unit tests --- .../Clients/ObservableReferencesClient.cs | 26 ++++- .../Clients/ReferencesClientTests.cs | 68 ++++++++++- Octokit/Clients/IReferencesClient.cs | 89 ++++++++++++--- Octokit/Clients/ReferencesClient.cs | 108 +++++++++++++++--- Octokit/Helpers/ApiUrls.cs | 3 +- 5 files changed, 257 insertions(+), 37 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableReferencesClient.cs b/Octokit.Reactive/Clients/ObservableReferencesClient.cs index b5353bd296..21fcba501e 100644 --- a/Octokit.Reactive/Clients/ObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReferencesClient.cs @@ -146,7 +146,12 @@ public IObservable GetAllForSubNamespace(string owner, string name, s /// The name of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public IObservable GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -154,6 +159,11 @@ public IObservable GetAllForSubNamespace(string owner, string name, s Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); + if (subNamespace.StartsWith("refs/")) + { + subNamespace = subNamespace.Replace("refs/", string.Empty); + } + return _connection.GetAndFlattenAllPages(ApiUrls.Reference(owner, name, subNamespace), options); } @@ -180,12 +190,22 @@ public IObservable GetAllForSubNamespace(long repositoryId, string su /// The Id of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public IObservable GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); + if (subNamespace.StartsWith("refs/")) + { + subNamespace = subNamespace.Replace("refs/", string.Empty); + } + return _connection.GetAndFlattenAllPages(ApiUrls.Reference(repositoryId, subNamespace), options); } @@ -298,4 +318,4 @@ public IObservable Delete(long repositoryId, string reference) return _reference.Delete(repositoryId, reference).ToObservable(); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index 782004f659..1756f3de8c 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -47,6 +47,17 @@ public async Task RequestsCorrectUrl() connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop")); } + [Fact] + public async Task RequestsCorrectUrlWithRef() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Get("owner", "repo", "refs/heads/develop"); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop")); + } + [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { @@ -57,6 +68,17 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads/develop")); } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdAndRefs() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Get(1, "refs/heads/develop"); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads/develop")); + } } public class TheGetAllMethod @@ -150,6 +172,17 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRef() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.GetAllForSubNamespace("owner", "repo", "refs/heads"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { @@ -160,6 +193,17 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads"), Args.ApiOptions); } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdAndRefs() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.GetAllForSubNamespace(1, "refs/heads"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads"), Args.ApiOptions); + } } public class TheCreateMethod @@ -282,6 +326,17 @@ public async Task RequestsCorrectUrl() connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop")); } + [Fact] + public async Task RequestsCorrectUrlWithRefs() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Delete("owner", "repo", "refs/heads/develop"); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop")); + } + [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { @@ -292,6 +347,17 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads/develop")); } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdAndRefs() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Delete(1, "refs/heads/develop"); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/git/refs/heads/develop")); + } } } -} \ No newline at end of file +} diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index 04122e2f14..23369c073c 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -20,8 +20,13 @@ public interface IReferencesClient /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(string owner, string name, string reference); @@ -33,8 +38,13 @@ public interface IReferencesClient /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(long repositoryId, string reference); @@ -92,7 +102,12 @@ public interface IReferencesClient /// The owner of the repository /// The name of the repository /// The sub-namespace to get references for - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task> GetAllForSubNamespace(string owner, string name, string subNamespace); /// @@ -105,7 +120,12 @@ public interface IReferencesClient /// The name of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options); /// @@ -116,7 +136,12 @@ public interface IReferencesClient /// /// The Id of the repository /// The sub-namespace to get references for - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task> GetAllForSubNamespace(long repositoryId, string subNamespace); /// @@ -128,7 +153,12 @@ public interface IReferencesClient /// The Id of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options); /// @@ -140,7 +170,12 @@ public interface IReferencesClient /// The owner of the repository /// The name of the repository /// The reference to create - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task Create(string owner, string name, NewReference reference); /// @@ -162,9 +197,14 @@ public interface IReferencesClient /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The reference name /// The updated reference data - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); /// @@ -174,9 +214,14 @@ public interface IReferencesClient /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The reference name /// The updated reference data - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate); /// @@ -187,8 +232,13 @@ public interface IReferencesClient /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task Delete(string owner, string name, string reference); /// @@ -198,8 +248,13 @@ public interface IReferencesClient /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// Task Delete(long repositoryId, string reference); } } diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index 1b5fdb3fe8..01c6ad542f 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -28,14 +28,24 @@ public ReferencesClient(IApiConnection apiConnection) : /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } @@ -46,12 +56,22 @@ public Task Get(string owner, string name, string reference) /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Get(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Get(ApiUrls.Reference(repositoryId, reference)); } @@ -142,7 +162,12 @@ public Task> GetAllForSubNamespace(string owner, string /// The name of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -152,6 +177,11 @@ public Task> GetAllForSubNamespace(string owner, string // TODO: Handle 404 when subNamespace cannot be found + if (subNamespace.StartsWith("refs/")) + { + subNamespace = subNamespace.Replace("refs/", string.Empty); + } + return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace), options); } @@ -178,7 +208,12 @@ public Task> GetAllForSubNamespace(long repositoryId, s /// The Id of the repository /// The sub-namespace to get references for /// Options for changing the API response - /// + /// + /// The subNamespace parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); @@ -186,6 +221,11 @@ public Task> GetAllForSubNamespace(long repositoryId, s // TODO: Handle 404 when subNamespace cannot be found + if (subNamespace.StartsWith("refs/")) + { + subNamespace = subNamespace.Replace("refs/", string.Empty); + } + return ApiConnection.GetAll(ApiUrls.Reference(repositoryId, subNamespace), options); } @@ -232,9 +272,14 @@ public Task Create(long repositoryId, NewReference reference) /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The reference name /// The updated reference data - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -242,6 +287,11 @@ public Task Update(string owner, string name, string reference, Refer Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(referenceUpdate, nameof(referenceUpdate)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), referenceUpdate); } @@ -252,14 +302,24 @@ public Task Update(string owner, string name, string reference, Refer /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The reference name /// The updated reference data - /// + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(referenceUpdate, nameof(referenceUpdate)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Patch(ApiUrls.Reference(repositoryId, reference), referenceUpdate); } @@ -271,14 +331,24 @@ public Task Update(long repositoryId, string reference, ReferenceUpda /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Delete(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Delete(ApiUrls.Reference(owner, name, reference)); } @@ -289,12 +359,22 @@ public Task Delete(string owner, string name, string reference) /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" - /// + /// The reference name + /// + /// The reference parameter supports either the fully-qualified ref + /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. + /// "heads/master" or "tags/release-1") + /// public Task Delete(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + if (reference.StartsWith("refs/")) + { + reference = reference.Replace("refs/", string.Empty); + } + return ApiConnection.Delete(ApiUrls.Reference(repositoryId, reference)); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 77d08dc806..48cf5db7e1 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3185,8 +3185,7 @@ public static Uri Reference(long repositoryId) /// The for the specified reference. public static Uri Reference(long repositoryId, string referenceName) { - return "repositories/{0}/git/refs/{1}".FormatUri(repositoryId, - referenceName.Replace("refs/", string.Empty)); + return "repositories/{0}/git/refs/{1}".FormatUri(repositoryId, referenceName); } /// From db13e8493f50e78eb29199a60684b1350b04b862 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 25 Feb 2020 16:56:58 -0400 Subject: [PATCH 3/4] add some integration tests that use refs --- .../Clients/ReferencesClientTests.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs index ff6f930aca..9f2c62bdd2 100644 --- a/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs @@ -179,6 +179,13 @@ public async Task CanGetListOfReferencesInNamespace() Assert.NotEmpty(list); } + [IntegrationTest] + public async Task CanGetListOfReferencesInNamespaceWithRefsIncluded() + { + var list = await _fixture.GetAllForSubNamespace("octokit", "octokit.net", "refs/heads"); + Assert.NotEmpty(list); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfReferencesInNamespaceWithStart() { @@ -503,6 +510,42 @@ public async Task CanDeleteAReference() Assert.Empty(all.Where(r => r.Ref == "heads/develop")); } + [IntegrationTest] + public async Task CanDeleteAReferenceUsingRefs() + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Mode = FileMode.File, + Type = TreeType.Blob, + Path = "README.md", + Sha = blobResult.Sha + }); + + var treeResult = await _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree); + + var newCommit = new NewCommit("This is a new commit", treeResult.Sha); + + var commitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); + + var newReference = new NewReference("heads/develop", commitResult.Sha); + + await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newReference); + await _fixture.Delete(_context.RepositoryOwner, _context.RepositoryName, "refs/heads/develop"); + + var all = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName); + + Assert.Empty(all.Where(r => r.Ref == "heads/develop")); + } + + [IntegrationTest] public async Task CanDeleteAReferenceWithRepositoryId() { From 308e8a2876650284bb02c9352aed922e2413c25b Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 25 Feb 2020 17:07:40 -0400 Subject: [PATCH 4/4] keep internals simple for now --- Octokit/Clients/ReferencesClient.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index 01c6ad542f..7d0dc87f5e 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -175,8 +175,6 @@ public Task> GetAllForSubNamespace(string owner, string Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); - // TODO: Handle 404 when subNamespace cannot be found - if (subNamespace.StartsWith("refs/")) { subNamespace = subNamespace.Replace("refs/", string.Empty); @@ -219,8 +217,6 @@ public Task> GetAllForSubNamespace(long repositoryId, s Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); - // TODO: Handle 404 when subNamespace cannot be found - if (subNamespace.StartsWith("refs/")) { subNamespace = subNamespace.Replace("refs/", string.Empty);