mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
[FEAT] add Triage/Maintain permission (#2467)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Octokit.Tests.Conventions
|
||||
{
|
||||
public class ResponseModelSetterlessAutoPropertyException : Exception
|
||||
{
|
||||
public ResponseModelSetterlessAutoPropertyException(Type modelType, IEnumerable<PropertyInfo> setterlessProperties)
|
||||
: base(CreateMessage(modelType, setterlessProperties))
|
||||
{ }
|
||||
|
||||
static string CreateMessage(Type modelType, IEnumerable<PropertyInfo> setterlessProperties)
|
||||
{
|
||||
return string.Format("Model type '{0}' contains the following setterless properties: {1}{2}",
|
||||
modelType.FullName,
|
||||
Environment.NewLine,
|
||||
string.Join(Environment.NewLine, setterlessProperties.Select(x => x.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ namespace Octokit.Tests.Conventions
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ResponseModelTypes))]
|
||||
public void ResponseModelsHaveGetterOnlyProperties(Type modelType)
|
||||
public void ResponseModelsHaveNoPublicSettableProperties(Type modelType)
|
||||
{
|
||||
var mutableProperties = new List<PropertyInfo>();
|
||||
|
||||
@@ -112,6 +112,33 @@ namespace Octokit.Tests.Conventions
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ResponseModelTypes))]
|
||||
public void ResponseModelsHaveNoSetterlessAutoPropertiesForReflection(Type modelType)
|
||||
{
|
||||
var setterlessAutoProperties = new List<PropertyInfo>();
|
||||
|
||||
foreach (var property in modelType.GetProperties())
|
||||
{
|
||||
var propertyHasNoSetter = property.GetSetMethod(true) is null;
|
||||
if (IsAutoProperty(property) && propertyHasNoSetter)
|
||||
{
|
||||
setterlessAutoProperties.Add(property);
|
||||
}
|
||||
}
|
||||
|
||||
if (setterlessAutoProperties.Any())
|
||||
{
|
||||
throw new ResponseModelSetterlessAutoPropertyException(modelType, setterlessAutoProperties);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsAutoProperty(PropertyInfo prop)
|
||||
{
|
||||
return prop.DeclaringType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
.Any(f => f.Name.Contains("<" + prop.Name + ">"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ResponseModelTypes))]
|
||||
public void ResponseModelsHaveReadOnlyCollections(Type modelType)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
@@ -8,31 +8,46 @@ namespace Octokit
|
||||
{
|
||||
public RepositoryPermissions() { }
|
||||
|
||||
public RepositoryPermissions(bool admin, bool push, bool pull)
|
||||
public RepositoryPermissions(bool admin, bool maintain, bool push, bool triage, bool pull)
|
||||
{
|
||||
Admin = admin;
|
||||
Maintain = maintain;
|
||||
Push = push;
|
||||
Triage = triage;
|
||||
Pull = pull;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current user has administrative permissions
|
||||
/// </summary>
|
||||
public bool Admin { get; protected set; }
|
||||
public bool Admin { get; private set;}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current user has maintain permissions
|
||||
/// </summary>
|
||||
public bool Maintain { get; private set;}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current user has push permissions
|
||||
/// </summary>
|
||||
public bool Push { get; protected set; }
|
||||
public bool Push { get; private set;}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current user has triage permissions
|
||||
/// </summary>
|
||||
public bool Triage { get; private set;}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current user has pull permissions
|
||||
/// </summary>
|
||||
public bool Pull { get; protected set; }
|
||||
public bool Pull { get; private set;}
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get { return string.Format(CultureInfo.InvariantCulture, "Admin: {0}, Push: {1}, Pull: {2}", Admin, Push, Pull); }
|
||||
get
|
||||
{
|
||||
return FormattableString.Invariant($"Admin: {Admin}, Maintain: {Maintain}, Push: {Push}, Triage: {Triage}, Pull: {Pull}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user