Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Octokit/Clients/IRepositoryBranchesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public interface IRepositoryBranchesClient
/// <param name="branch">The name of the branch</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Branch> Get(long repositoryId, string branch);

/// <summary>
/// Get the branch rules for the specified branch
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/repos/rules#get-rules-for-a-branch">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="branch">The name of the branch</param>
Task<List<BranchProtectionRule>> GetBranchRules(string owner, string name, string branch);

/// <summary>
/// Get the branch protection settings for the specified branch
Expand Down
19 changes: 19 additions & 0 deletions Octokit/Clients/RepositoryBranchesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ public Task<Branch> Get(long repositoryId, string branch)
return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(repositoryId, branch), null);
}

/// <summary>
/// Get the branch rules for the specified branch
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/repos/rules#get-rules-for-a-branch">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="branch">The name of the branch</param>
[ManualRoute("GET", "/repos/{owner}/{repo}/rules/branches/{branch}")]
public Task<List<BranchProtectionRule>> GetBranchRules(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));

return ApiConnection.Get<List<BranchProtectionRule>>(ApiUrls.RepoBranchRules(owner, name, branch), null);
}

/// <summary>
/// Get the branch protection settings for the specified branch
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,18 @@ public static Uri RepoBranch(string owner, string name, string branchName)
{
return "repos/{0}/{1}/branches/{2}".FormatUri(owner, name, branchName);
}

/// <summary>
/// Returns the <see cref="Uri"/> for a repository branches rules.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="branchName">The name of the branch</param>
/// <returns></returns>
public static Uri RepoBranchRules(string owner, string name, string branchName)
{
return "repos/{0}/{1}/rules/branches/{2}".FormatUri(owner, name, branchName);
}

/// <summary>
/// Returns the <see cref="Uri"/> for a repository branches protection.
Expand Down
59 changes: 59 additions & 0 deletions Octokit/Models/Response/BranchProtectionRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
/// <summary>
/// Protection rule set for a <see cref="Branch"/>.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionRule
{
public BranchProtectionRule()
{
}

public BranchProtectionRule(string type, string rulesetSourceType, long rulesetId, BranchProtectionRuleParameters parameters)
{
Type = type;
RulesetSourceType = rulesetSourceType;
RulesetId = rulesetId;
Parameters = parameters;
}

public string Type { get; private set; }
public string RulesetSourceType { get; private set; }
public long RulesetId { get; private set; }
public BranchProtectionRuleParameters Parameters { get; private set; }

internal string DebuggerDisplay =>
string.Format(CultureInfo.InvariantCulture,
"Type: {0} RulesetSourceType {1} RulesetId: {2} Parameters: {3}",
Type,
RulesetSourceType,
RulesetId,
Parameters?.DebuggerDisplay ?? "disabled");
}

/// <summary>
/// Specifies settings for status checks which must pass before branches can be merged into the protected branch
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionRuleParameters
{
public BranchProtectionRuleParameters()
{
}

public BranchProtectionRuleParameters(int requiredApprovingReviewCount)
{
RequiredApprovingReviewCount = requiredApprovingReviewCount;
}

public int RequiredApprovingReviewCount { get; private set; }

internal string DebuggerDisplay =>
string.Format(CultureInfo.InvariantCulture,
"RequiredApprovingReviewCount: {0}", RequiredApprovingReviewCount);
}
}
2 changes: 1 addition & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>An async-based GitHub API client library for .NET and .NET Core</Description>
<AssemblyTitle>Octokit</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>1.0.18</Version>
<Version>1.0.19</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Octokit</AssemblyName>
<PackageId>Apiiro.Octokit</PackageId>
Expand Down