mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-12 06:00:38 +00:00
Add Protected Branches to Branch object
- Create BranchProtection models - Add Protection element to Branch model - Adjust RepositoryClient GetBranch and GetBranches calls to set the special preview accepts header to enable Protected Branches API (currently in preview) - Adjust tests to include preview accepts header - Add test for Protection element
This commit is contained in:
@@ -24,5 +24,20 @@ public class BranchesClientTests
|
||||
Assert.Equal(branches[0].Name, "master");
|
||||
}
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsBranchesWithProtectionStatus()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
using (var context = await github.CreateRepositoryContext("public-repo"))
|
||||
{
|
||||
var branches = await github.Repository.GetAllBranches(context.Repository.Owner.Login, context.Repository.Name);
|
||||
|
||||
Assert.NotEmpty(branches);
|
||||
Assert.Equal(branches[0].Name, "master");
|
||||
Assert.NotNull(branches[0].Protection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,7 +435,7 @@ namespace Octokit.Tests.Clients
|
||||
client.GetAllBranches("owner", "name");
|
||||
|
||||
connection.Received()
|
||||
.GetAll<Branch>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/branches"));
|
||||
.GetAll<Branch>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/branches"), null, "application/vnd.github.loki-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -565,7 +565,7 @@ namespace Octokit.Tests.Clients
|
||||
client.GetBranch("owner", "repo", "branch");
|
||||
|
||||
connection.Received()
|
||||
.Get<Branch>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch"), null);
|
||||
.Get<Branch>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch"), null, "application/vnd.github.loki-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -389,8 +389,8 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepoBranches(owner, name);
|
||||
return ApiConnection.GetAll<Branch>(endpoint);
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
return ApiConnection.GetAll<Branch>(ApiUrls.RepoBranches(owner, name), null, previewAcceptsHeader);
|
||||
}
|
||||
|
||||
|
||||
@@ -502,7 +502,8 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branchName, "branchName");
|
||||
|
||||
return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName));
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName), null, previewAcceptsHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,12 @@ namespace Octokit
|
||||
/// </summary>
|
||||
public string Name { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="BranchProtection"/> details for this <see cref="Branch"/>.
|
||||
/// Note: this is a PREVIEW api: https://developer.github.com/changes/2015-11-11-protected-branches-api/
|
||||
/// </summary>
|
||||
public BranchProtection Protection { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="GitReference"/> history for this <see cref="Branch"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Protection details for a <see cref="Branch"/>.
|
||||
/// Note: this is a PREVIEW api: https://developer.github.com/changes/2015-11-11-protected-branches-api/
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class BranchProtection
|
||||
{
|
||||
/// <summary>
|
||||
/// Should this branch be protected or not
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="RequiredStatusChecks"/> information for this <see cref="Branch"/>.
|
||||
/// </summary>
|
||||
public RequiredStatusChecks RequiredStatusChecks { get; private set; }
|
||||
|
||||
public BranchProtection()
|
||||
{
|
||||
RequiredStatusChecks = new RequiredStatusChecks();
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class RequiredStatusChecks
|
||||
{
|
||||
/// <summary>
|
||||
/// Who required status checks apply to
|
||||
/// </summary>
|
||||
public EnforcementLevel EnforcementLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of status checks to require in order to merge into this <see cref="Branch"/>
|
||||
/// </summary>
|
||||
public ICollection<string> Contexts { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified context to the required status checks.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the context.</param>
|
||||
public void AddContext(string name)
|
||||
{
|
||||
// lazily create the contexts array
|
||||
if (Contexts == null)
|
||||
{
|
||||
Contexts = new List<string>();
|
||||
}
|
||||
|
||||
Contexts.Add(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all the contexts.
|
||||
/// </summary>
|
||||
public void ClearContexts()
|
||||
{
|
||||
// lazily create the contexts array
|
||||
if (Contexts == null)
|
||||
{
|
||||
Contexts = new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Contexts.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The enforcement levels that are available
|
||||
/// </summary>
|
||||
public enum EnforcementLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// Turn off required status checks for this <see cref="Branch"/>.
|
||||
/// </summary>
|
||||
Off,
|
||||
|
||||
/// <summary>
|
||||
/// Required status checks will be enforeced for non-admins.
|
||||
/// </summary>
|
||||
NonAdmins,
|
||||
|
||||
/// <summary>
|
||||
/// Required status checks will be enforced for everyone (including admins).
|
||||
/// </summary>
|
||||
Everyone
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,7 @@
|
||||
<Compile Include="Models\Response\ActivityPayloads\StarredEventPayload.cs" />
|
||||
<Compile Include="Models\Response\Author.cs" />
|
||||
<Compile Include="Models\Response\Branch.cs" />
|
||||
<Compile Include="Models\Response\BranchProtection.cs" />
|
||||
<Compile Include="Models\Response\Commit.cs" />
|
||||
<Compile Include="Models\Response\Activity.cs" />
|
||||
<Compile Include="Models\Response\Blob.cs" />
|
||||
|
||||
@@ -236,6 +236,7 @@
|
||||
<Compile Include="Models\Response\Authorization.cs" />
|
||||
<Compile Include="Models\Response\Blob.cs" />
|
||||
<Compile Include="Models\Response\Branch.cs" />
|
||||
<Compile Include="Models\Response\BranchProtection.cs" />
|
||||
<Compile Include="Models\Response\Commit.cs" />
|
||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||
<Compile Include="Models\Response\RepositoryContributor.cs" />
|
||||
|
||||
@@ -243,6 +243,7 @@
|
||||
<Compile Include="Models\Response\Authorization.cs" />
|
||||
<Compile Include="Models\Response\Blob.cs" />
|
||||
<Compile Include="Models\Response\Branch.cs" />
|
||||
<Compile Include="Models\Response\BranchProtection.cs" />
|
||||
<Compile Include="Models\Response\Commit.cs" />
|
||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||
<Compile Include="Models\Response\Contributor.cs" />
|
||||
|
||||
@@ -117,6 +117,7 @@
|
||||
<Compile Include="Models\Response\ActivityPayloads\PullRequestEventPayload.cs" />
|
||||
<Compile Include="Models\Response\ActivityPayloads\PushEventPayload.cs" />
|
||||
<Compile Include="Models\Response\ActivityPayloads\StarredEventPayload.cs" />
|
||||
<Compile Include="Models\Response\BranchProtection.cs" />
|
||||
<Compile Include="Models\Response\CombinedCommitStatus.cs" />
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
|
||||
|
||||
Reference in New Issue
Block a user