Added support for custom labels (#414)

* Added support for custom labels

* ignore case

* Added interactive config for labels

* Fixing L0s

* pr comments
This commit is contained in:
Lokesh Gopu
2020-04-13 21:33:13 -04:00
committed by GitHub
parent a20ad4e121
commit f9baec4b32
11 changed files with 199 additions and 43 deletions

View File

@@ -0,0 +1,59 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace GitHub.DistributedTask.WebApi
{
[DataContract]
public class AgentLabel
{
[JsonConstructor]
public AgentLabel()
{
}
public AgentLabel(string name)
{
this.Name = name;
this.Type = LabelType.System;
}
public AgentLabel(string name, LabelType type)
{
this.Name = name;
this.Type = type;
}
private AgentLabel(AgentLabel labelToBeCloned)
{
this.Id = labelToBeCloned.Id;
this.Name = labelToBeCloned.Name;
this.Type = labelToBeCloned.Type;
}
[DataMember]
public int Id
{
get;
set;
}
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
public LabelType Type
{
get;
set;
}
public AgentLabel Clone()
{
return new AgentLabel(this);
}
}
}

View File

@@ -0,0 +1,14 @@
using System.Runtime.Serialization;
namespace GitHub.DistributedTask.WebApi
{
[DataContract]
public enum LabelType
{
[EnumMember]
System = 0,
[EnumMember]
User = 1
}
}

View File

@@ -51,7 +51,7 @@ namespace GitHub.DistributedTask.WebApi
if (agentToBeCloned.m_labels != null && agentToBeCloned.m_labels.Count > 0)
{
m_labels = new HashSet<string>(agentToBeCloned.m_labels, StringComparer.OrdinalIgnoreCase);
m_labels = new HashSet<AgentLabel>(agentToBeCloned.m_labels);
}
}
@@ -118,13 +118,13 @@ namespace GitHub.DistributedTask.WebApi
/// <summary>
/// The labels of the runner
/// </summary>
public ISet<string> Labels
public ISet<AgentLabel> Labels
{
get
{
if (m_labels == null)
{
m_labels = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
m_labels = new HashSet<AgentLabel>();
}
return m_labels;
}
@@ -164,6 +164,6 @@ namespace GitHub.DistributedTask.WebApi
private PropertiesCollection m_properties;
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Labels")]
private HashSet<string> m_labels;
private HashSet<AgentLabel> m_labels;
}
}