Tweak naming of classes to be consistent

Change team and user lists to specific classes derived from Collection<T> so we can offer better configuration of BranchProtectionPushRestriction via multiple ctors (teams only, users only, teams and users, etc)
Add another ctor to BranchProtectionPushRestrictions for the case where no teams/users are specified (ie admin only)
Change organization update tests to use this new ctor and assert we get empty lists rather than no push restrictions
This commit is contained in:
Ryan Gribble
2016-08-25 07:38:24 +10:00
parent 46dc145e72
commit 902a5d765f
4 changed files with 102 additions and 24 deletions
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;
@@ -30,7 +31,7 @@ namespace Octokit
/// </summary>
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, ProtectedBranchRestrictionsUpdate restrictions)
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions)
{
RequiredStatusChecks = requiredStatusChecks;
Restrictions = restrictions;
@@ -46,13 +47,16 @@ namespace Octokit
/// Push access restrictions for the protected branch
/// </summary>
[SerializeNull]
public ProtectedBranchRestrictionsUpdate Restrictions { get; protected set; }
public BranchProtectionPushRestrictionsUpdate Restrictions { get; protected set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "StatusChecks: {0} Restrictions: {1}", RequiredStatusChecks.DebuggerDisplay, Restrictions.DebuggerDisplay);
return String.Format(CultureInfo.InvariantCulture,
"StatusChecks: {0} Restrictions: {1}",
RequiredStatusChecks == null ? "disabled" : RequiredStatusChecks.DebuggerDisplay,
Restrictions == null ? "disabled" : Restrictions.DebuggerDisplay);
}
}
}
@@ -101,17 +105,50 @@ namespace Octokit
}
/// <summary>
/// Specifies people or teams allowed to push to the protected branch. Required status checks will still prevent these people from merging if the checks fail
/// Specifies teams and/or people allowed to push to the protected branch. Required status checks will still prevent these people from merging if the checks fail
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class ProtectedBranchRestrictionsUpdate
public class BranchProtectionPushRestrictionsUpdate
{
/// <summary>
/// Specify people or teams (in addition to Administrators) allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail
/// Specify only administrators are allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail
/// </summary>
/// <param name="teams">Teams allowed to push to this branch (pass empty array if no teams)</param>
/// <param name="users">Users allowed to push to this branch (pass empty array if no users)</param>
public ProtectedBranchRestrictionsUpdate(IReadOnlyList<string> teams, IReadOnlyList<string> users)
public BranchProtectionPushRestrictionsUpdate()
{
Teams = new BranchProtectionTeamCollection();
Users = new BranchProtectionUserCollection();
}
/// <summary>
/// Specify teams (in addition to Administrators) allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail
/// </summary>
/// <param name="teams">Teams allowed to push to this branch</param>
public BranchProtectionPushRestrictionsUpdate(BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNull(teams, "teams");
Teams = teams;
Users = new BranchProtectionUserCollection();
}
/// <summary>
/// Specify people (in addition to Administrators) allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail
/// </summary>
/// <param name="users">Users allowed to push to this branch</param>
public BranchProtectionPushRestrictionsUpdate(BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNull(users, "users");
Teams = new BranchProtectionTeamCollection();
Users = users;
}
/// <summary>
/// Specify teams and/or people (in addition to Administrators) allowed to push to this branch. Required status checks will still prevent these people from merging if the checks fail
/// </summary>
/// <param name="teams">Teams allowed to push to this branch</param>
/// <param name="users">Users allowed to push to this branch</param>
public BranchProtectionPushRestrictionsUpdate(BranchProtectionTeamCollection teams, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNull(teams, "teams");
Ensure.ArgumentNotNull(users, "users");
@@ -123,18 +160,57 @@ namespace Octokit
/// <summary>
/// Teams allowed to push to this branch
/// </summary>
public IReadOnlyList<string> Teams { get; private set; }
public BranchProtectionTeamCollection Teams { get; private set; }
/// <summary>
/// Users allowed to push to this branch
/// </summary>
public IReadOnlyList<string> Users { get; private set; }
public BranchProtectionUserCollection Users { get; private set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Teams: {0} Users: {1}", Teams == null ? "" : String.Join(",", Teams), Users == null ? "" : String.Join(",", Users));
return String.Format(CultureInfo.InvariantCulture,
"Teams: {0} Users: {1}",
Teams == null ? "" : Teams.DebuggerDisplay,
Users == null ? "" : Users.DebuggerDisplay);
}
}
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionTeamCollection : Collection<string>
{
public BranchProtectionTeamCollection()
{ }
public BranchProtectionTeamCollection(IList<string> list) : base(list)
{ }
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, String.Join(", ", this));
}
}
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionUserCollection : Collection<string>
{
public BranchProtectionUserCollection()
{ }
public BranchProtectionUserCollection(IList<string> list) : base(list)
{ }
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, String.Join(", ", this));
}
}
}