From 05240981a308e0495bdf8ed71733c503c8899ec7 Mon Sep 17 00:00:00 2001 From: Dirty Gooback <19241000+dirtygooback@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:05:50 -0400 Subject: [PATCH 1/3] added RenameBranch method to RepositoryBranchesClient --- .../IObservableRepositoryBranchesClient.cs | 27 +++++++---- .../ObservableRepositoryBranchesClient.cs | 24 +++++++++- .../Clients/RepositoryBranchesClientTests.cs | 48 ++++++++++++++++++- Octokit/Clients/IRepositoryBranchesClient.cs | 12 +++++ Octokit/Clients/RepositoryBranchesClient.cs | 34 ++++++++++--- Octokit/Helpers/ApiUrls.cs | 12 +++++ build/Utilities/BuildVersion.cs | 4 +- 7 files changed, 142 insertions(+), 19 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs index eb9e41c26d..f9df12471a 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs @@ -1,15 +1,14 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - namespace Octokit.Reactive { - /// - /// A client for GitHub's Repository Branches API. - /// - /// - /// See the Repository Branches API documentation for more details. - /// + /// + /// A client for GitHub's Repository Branches API. + /// + /// + /// See the Repository Branches API documentation for more details. + /// public interface IObservableRepositoryBranchesClient { /// @@ -644,5 +643,17 @@ public interface IObservableRepositoryBranchesClient /// The name of the branch /// List of users with push access to remove IObservable DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); - } + + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + IObservable RenameBranch(string owner, string repository, string branch, string newName); + } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs index ac87bb1b0d..091b0296f6 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs @@ -3,6 +3,8 @@ using System.Diagnostics.CodeAnalysis; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; + using Octokit.Reactive.Internal; namespace Octokit.Reactive @@ -1021,5 +1023,25 @@ public IObservable DeleteProtectedBranchUserRestrictions(long repositoryId return _client.DeleteProtectedBranchUserRestrictions(repositoryId, branch, users).ToObservable().SelectMany(x => x); } - } + + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + public IObservable RenameBranch(string owner, string repository, string branch, string newName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); + + return _client.RenameBranch(owner, repository, branch, newName).ToObservable(); + } + } } diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs index 6d5160ec55..01c3474cbe 100644 --- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs @@ -1399,5 +1399,51 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions(1, "", usersToRemove)); } } - } + + public class TheRenameBranchMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + + client.RenameBranch("owner", "repo", "branch", "new_name"); + + connection.Received() + .Post(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/rename"), Arg.Any()); + } + + + [Fact] + public async Task PassesTheCorrectNewBranchParameter() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newBranch = "a"; + + await client.RenameBranch("owner", "repo", "branch", newBranch); + + connection.Received().Post( + Arg.Any(), + Arg.Is(o => o.GetType().GetProperty("new_name").GetValue(o).ToString() == newBranch)); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.RenameBranch(null, "repo", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", null, "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", null, "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.RenameBranch("", "repo", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", "")); + } + } + } } diff --git a/Octokit/Clients/IRepositoryBranchesClient.cs b/Octokit/Clients/IRepositoryBranchesClient.cs index eec7c6026c..ed4081e57d 100644 --- a/Octokit/Clients/IRepositoryBranchesClient.cs +++ b/Octokit/Clients/IRepositoryBranchesClient.cs @@ -652,5 +652,17 @@ public interface IRepositoryBranchesClient /// The name of the branch /// List of users with push access to remove Task> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); + + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + Task RenameBranch(string owner, string repository, string branch, string newName); } } diff --git a/Octokit/Clients/RepositoryBranchesClient.cs b/Octokit/Clients/RepositoryBranchesClient.cs index 8126fc0ea6..2aa3fc5264 100644 --- a/Octokit/Clients/RepositoryBranchesClient.cs +++ b/Octokit/Clients/RepositoryBranchesClient.cs @@ -1,15 +1,14 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; - namespace Octokit { - /// - /// A client for GitHub's Repository Branches API. - /// - /// - /// See the Repository Branches API documentation for more details. - /// + /// + /// A client for GitHub's Repository Branches API. + /// + /// + /// See the Repository Branches API documentation for more details. + /// public class RepositoryBranchesClient : ApiClient, IRepositoryBranchesClient { /// @@ -1177,5 +1176,26 @@ public Task> DeleteProtectedBranchUserRestrictions(long repo return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users); } + + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + [ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/rename")] + public Task RenameBranch(string owner, string repository, string branch, string newName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); + + return ApiConnection.Post(ApiUrls.RepositoryBranchRename(owner, repository, branch), new { new_name = newName }); + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 62ea8140a0..10c24e6964 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -5519,6 +5519,18 @@ public static Uri DownloadArtifact(string owner, string repository, long artifac public static Uri ListWorkflowArtifacts(string owner, string repository, long runId) { return "repos/{0}/{1}/actions/runs/{2}/artifacts".FormatUri(owner, repository, runId); + } + + /// + /// Returns the to rename a repository branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// + public static Uri RepositoryBranchRename(string owner, string repository, string branch) + { + return "repos/{0}/{1}/branches/{2}/rename".FormatUri(owner, repository, branch); } } } diff --git a/build/Utilities/BuildVersion.cs b/build/Utilities/BuildVersion.cs index 7c4985981c..6a61193138 100644 --- a/build/Utilities/BuildVersion.cs +++ b/build/Utilities/BuildVersion.cs @@ -45,8 +45,8 @@ public static BuildVersion Calculate(Context context) // Run in interactive mode to get the properties for the rest of the script var assertedversions = GitVersionRunner.Run(context, GitVersionOutput.Json); - - version = assertedversions.MajorMinorPatch; + + version = "9.2.0"; // assertedversions.MajorMinorPatch; semVersion = assertedversions.LegacySemVerPadded; fullSemVer = assertedversions.FullSemVer; From 54f488f3901fb1763ec23d50f1655a40d4551663 Mon Sep 17 00:00:00 2001 From: Dirty Gooback <19241000+dirtygooback@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:07:53 -0400 Subject: [PATCH 2/3] revert forced version --- build/Utilities/BuildVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Utilities/BuildVersion.cs b/build/Utilities/BuildVersion.cs index 6a61193138..619a46d069 100644 --- a/build/Utilities/BuildVersion.cs +++ b/build/Utilities/BuildVersion.cs @@ -46,7 +46,7 @@ public static BuildVersion Calculate(Context context) // Run in interactive mode to get the properties for the rest of the script var assertedversions = GitVersionRunner.Run(context, GitVersionOutput.Json); - version = "9.2.0"; // assertedversions.MajorMinorPatch; + version = assertedversions.MajorMinorPatch; semVersion = assertedversions.LegacySemVerPadded; fullSemVer = assertedversions.FullSemVer; From 35853cb18da800c5bdcd8360fff883bf80c9d75e Mon Sep 17 00:00:00 2001 From: Dirty Gooback <19241000+dirtygooback@users.noreply.github.com> Date: Fri, 13 Oct 2023 06:18:45 -0400 Subject: [PATCH 3/3] tabs -> spaces :( --- .../IObservableRepositoryBranchesClient.cs | 24 ++--- .../ObservableRepositoryBranchesClient.cs | 42 ++++----- .../Clients/RepositoryBranchesClientTests.cs | 87 +++++++++---------- Octokit/Clients/RepositoryBranchesClient.cs | 32 +++---- Octokit/Helpers/ApiUrls.cs | 22 ++--- 5 files changed, 103 insertions(+), 104 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs index f9df12471a..a37cb260e2 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs @@ -644,16 +644,16 @@ public interface IObservableRepositoryBranchesClient /// List of users with push access to remove IObservable DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); - /// - /// Renames a branch in a repository - /// - /// - /// See the API documentation for more details - /// - /// The owner of the repository - /// The name of the repository - /// The name of the branch to rename - /// The new name of the branch - IObservable RenameBranch(string owner, string repository, string branch, string newName); - } + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + IObservable RenameBranch(string owner, string repository, string branch, string newName); + } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs index 091b0296f6..8eea00feab 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs @@ -299,7 +299,7 @@ public IObservable UpdateRequiredStatusChe /// /// The owner of the repository /// The name of the repository - /// The name of the branch + /// The name of the branch public IObservable DeleteRequiredStatusChecks(string owner, string name, string branch) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -316,7 +316,7 @@ public IObservable DeleteRequiredStatusChecks(string owner, string name, s /// See the API documentation for more details /// /// The Id of the repository - /// The name of the branch + /// The name of the branch public IObservable DeleteRequiredStatusChecks(long repositoryId, string branch) { Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); @@ -1024,24 +1024,24 @@ public IObservable DeleteProtectedBranchUserRestrictions(long repositoryId return _client.DeleteProtectedBranchUserRestrictions(repositoryId, branch, users).ToObservable().SelectMany(x => x); } - /// - /// Renames a branch in a repository - /// - /// - /// See the API documentation for more details - /// - /// The owner of the repository - /// The name of the repository - /// The name of the branch to rename - /// The new name of the branch - public IObservable RenameBranch(string owner, string repository, string branch, string newName) - { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); - Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); - - return _client.RenameBranch(owner, repository, branch, newName).ToObservable(); - } + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + public IObservable RenameBranch(string owner, string repository, string branch, string newName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); + + return _client.RenameBranch(owner, repository, branch, newName).ToObservable(); + } } } diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs index 01c3474cbe..ed0aeb8918 100644 --- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs @@ -1400,50 +1400,49 @@ public async Task EnsuresNonNullArguments() } } - public class TheRenameBranchMethod - { - [Fact] - public void RequestsTheCorrectUrl() - { - var connection = Substitute.For(); - var client = new RepositoryBranchesClient(connection); - - client.RenameBranch("owner", "repo", "branch", "new_name"); - - connection.Received() - .Post(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/rename"), Arg.Any()); - } - - - [Fact] - public async Task PassesTheCorrectNewBranchParameter() - { - var connection = Substitute.For(); - var client = new RepositoryBranchesClient(connection); - var newBranch = "a"; - - await client.RenameBranch("owner", "repo", "branch", newBranch); - - connection.Received().Post( - Arg.Any(), - Arg.Is(o => o.GetType().GetProperty("new_name").GetValue(o).ToString() == newBranch)); - } - - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new RepositoryBranchesClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.RenameBranch(null, "repo", "branch", "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", null, "branch", "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", null, "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", null)); - - await Assert.ThrowsAsync(() => client.RenameBranch("", "repo", "branch", "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", "", "branch", "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "", "new_name")); - await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", "")); - } + public class TheRenameBranchMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + + client.RenameBranch("owner", "repo", "branch", "new_name"); + + connection.Received() + .Post(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/rename"), Arg.Any()); + } + + [Fact] + public async Task PassesTheCorrectNewBranchParameter() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newBranch = "a"; + + await client.RenameBranch("owner", "repo", "branch", newBranch); + + connection.Received().Post( + Arg.Any(), + Arg.Is(o => o.GetType().GetProperty("new_name").GetValue(o).ToString() == newBranch)); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.RenameBranch(null, "repo", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", null, "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", null, "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.RenameBranch("", "repo", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "", "branch", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "", "new_name")); + await Assert.ThrowsAsync(() => client.RenameBranch("owner", "repo", "branch", "")); + } } } } diff --git a/Octokit/Clients/RepositoryBranchesClient.cs b/Octokit/Clients/RepositoryBranchesClient.cs index 2aa3fc5264..15225c453a 100644 --- a/Octokit/Clients/RepositoryBranchesClient.cs +++ b/Octokit/Clients/RepositoryBranchesClient.cs @@ -1177,25 +1177,25 @@ public Task> DeleteProtectedBranchUserRestrictions(long repo return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users); } - /// - /// Renames a branch in a repository - /// - /// - /// See the API documentation for more details - /// - /// The owner of the repository - /// The name of the repository - /// The name of the branch to rename - /// The new name of the branch - [ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/rename")] + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// The new name of the branch + [ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/rename")] public Task RenameBranch(string owner, string repository, string branch, string newName) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); - Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(repository, nameof(repository)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(newName, nameof(newName)); return ApiConnection.Post(ApiUrls.RepositoryBranchRename(owner, repository, branch), new { new_name = newName }); - } + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 9113ed9d1e..41cb5ca958 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -5506,7 +5506,7 @@ public static Uri CodespaceStop(string codespaceName) { return "user/codespaces/{0}/stop".FormatUri(codespaceName); } - + /// /// Returns the that lists the artifacts for a repository. /// @@ -5517,7 +5517,7 @@ public static Uri ListArtifacts(string owner, string repository) { return "repos/{0}/{1}/actions/artifacts".FormatUri(owner, repository); } - + /// /// Returns the for the specified artifact. /// @@ -5542,7 +5542,7 @@ public static Uri DownloadArtifact(string owner, string repository, long artifac { return "repos/{0}/{1}/actions/artifacts/{2}/{3}".FormatUri(owner, repository, artifactId, archiveFormat); } - + /// /// Returns the to list the artifacts for a workflow. /// @@ -5555,14 +5555,14 @@ public static Uri ListWorkflowArtifacts(string owner, string repository, long ru return "repos/{0}/{1}/actions/runs/{2}/artifacts".FormatUri(owner, repository, runId); } - /// - /// Returns the to rename a repository branch. - /// - /// The owner of the repository - /// The name of the repository - /// The name of the branch to rename - /// - public static Uri RepositoryBranchRename(string owner, string repository, string branch) + /// + /// Returns the to rename a repository branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch to rename + /// + public static Uri RepositoryBranchRename(string owner, string repository, string branch) { return "repos/{0}/{1}/branches/{2}/rename".FormatUri(owner, repository, branch); }