using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace Octokit
{
///
/// Protection details for a .
/// Note: this is a PREVIEW api: https://developer.github.com/changes/2015-11-11-protected-branches-api/
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtection
{
public BranchProtection() { }
public BranchProtection(bool enabled, RequiredStatusChecks requiredStatusChecks)
{
Enabled = enabled;
RequiredStatusChecks = requiredStatusChecks;
}
///
/// Should this branch be protected or not
///
public bool Enabled { get; protected set; }
///
/// The information for this .
///
public RequiredStatusChecks RequiredStatusChecks { get; private set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Enabled: {0}", Enabled);
}
}
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RequiredStatusChecks
{
public RequiredStatusChecks() { }
public RequiredStatusChecks(EnforcementLevel enforcementLevel, IEnumerable contexts)
{
EnforcementLevel = enforcementLevel;
Contexts = new ReadOnlyCollection(contexts.ToList());
}
///
/// Who required status checks apply to
///
public EnforcementLevel EnforcementLevel { get; protected set; }
///
/// The list of status checks to require in order to merge into this
///
public IReadOnlyList Contexts { get; private set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "EnforcementLevel: {0} Contexts: {1}", EnforcementLevel.ToString(), Contexts.Count);
}
}
}
///
/// The enforcement levels that are available
///
public enum EnforcementLevel
{
///
/// Turn off required status checks for this .
///
Off,
///
/// Required status checks will be enforced for non-admins.
///
NonAdmins,
///
/// Required status checks will be enforced for everyone (including admins).
///
Everyone
}
}