[feat]: Add RenameBranch method to RepositoryBranchesClient (#2799)

* added RenameBranch method to RepositoryBranchesClient

* revert forced version

* tabs -> spaces :(

---------

Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
This commit is contained in:
Dirty Gooback
2023-10-30 17:59:37 -04:00
committed by GitHub
parent 35d2ee443d
commit 335632b08c
7 changed files with 144 additions and 22 deletions

View File

@@ -652,5 +652,17 @@ namespace Octokit
/// <param name="branch">The name of the branch</param>
/// <param name="users">List of users with push access to remove</param>
Task<IReadOnlyList<User>> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users);
/// <summary>
/// Renames a branch in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#rename-a-branch">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="repository">The name of the repository</param>
/// <param name="branch">The name of the branch to rename</param>
/// <param name="newName">The new name of the branch</param>
Task<Branch> RenameBranch(string owner, string repository, string branch, string newName);
}
}

View File

@@ -1,15 +1,14 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Branches API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches">Repository Branches API documentation</a> for more details.
/// </remarks>
/// <summary>
/// A client for GitHub's Repository Branches API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches">Repository Branches API documentation</a> for more details.
/// </remarks>
public class RepositoryBranchesClient : ApiClient, IRepositoryBranchesClient
{
/// <summary>
@@ -1177,5 +1176,26 @@ namespace Octokit
return ApiConnection.Delete<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users);
}
/// <summary>
/// Renames a branch in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#rename-a-branch">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="repository">The name of the repository</param>
/// <param name="branch">The name of the branch to rename</param>
/// <param name="newName">The new name of the branch</param>
[ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/rename")]
public Task<Branch> 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<Branch>(ApiUrls.RepositoryBranchRename(owner, repository, branch), new { new_name = newName });
}
}
}

View File

@@ -5506,7 +5506,7 @@ namespace Octokit
{
return "user/codespaces/{0}/stop".FormatUri(codespaceName);
}
/// <summary>
/// Returns the <see cref="Uri"/> that lists the artifacts for a repository.
/// </summary>
@@ -5517,7 +5517,7 @@ namespace Octokit
{
return "repos/{0}/{1}/actions/artifacts".FormatUri(owner, repository);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the specified artifact.
/// </summary>
@@ -5542,7 +5542,7 @@ namespace Octokit
{
return "repos/{0}/{1}/actions/artifacts/{2}/{3}".FormatUri(owner, repository, artifactId, archiveFormat);
}
/// <summary>
/// Returns the <see cref="Uri"/> to list the artifacts for a workflow.
/// </summary>
@@ -5554,5 +5554,17 @@ namespace Octokit
{
return "repos/{0}/{1}/actions/runs/{2}/artifacts".FormatUri(owner, repository, runId);
}
/// <summary>
/// Returns the <see cref="Uri"/> to rename a repository branch.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repository">The name of the repository</param>
/// <param name="branch">The name of the branch to rename</param>
/// <returns></returns>
public static Uri RepositoryBranchRename(string owner, string repository, string branch)
{
return "repos/{0}/{1}/branches/{2}/rename".FormatUri(owner, repository, branch);
}
}
}