Exemplo n.º 1
0
    internal static Task <VariableGroup> AddVariableGroupAsync(this TaskAgentHttpClient client, TeamProject project, string name, IDictionary <string, VariableValue> variables, string description = null)
    {
        if (client is null)
        {
            throw new ArgumentNullException(nameof(client));
        }

        if (project is null)
        {
            throw new ArgumentNullException(nameof(project));
        }

        if (string.IsNullOrWhiteSpace(name))
        {
            throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name));
        }

        if (variables is null)
        {
            throw new ArgumentNullException(nameof(variables));
        }

        if (!variables.Any())
        {
            throw new ArgumentException($"'{nameof(name)}' must contain at least one variable.", nameof(variables));
        }

        return(client.AddVariableGroupAsync(new VariableGroupParameters()
        {
            Name = name,
            Description = description,
            Type = "Vsts",
            Variables = variables,
            VariableGroupProjectReferences = new List <VariableGroupProjectReference>()
            {
                new VariableGroupProjectReference()
                {
                    Name = name,
                    Description = description,
                    ProjectReference = project.ToVariableProjectReference()
                }
            }
        }));
    }
Exemplo n.º 2
0
    internal static Task <VariableGroup> UpdateVariableGroupAsync(this TaskAgentHttpClient client, TeamProject project, VariableGroup group)
    {
        if (client is null)
        {
            throw new ArgumentNullException(nameof(client));
        }

        if (project is null)
        {
            throw new ArgumentNullException(nameof(project));
        }

        if (group is null)
        {
            throw new ArgumentNullException(nameof(group));
        }

        var variableGroupProjectReferenced = group.VariableGroupProjectReferences ?? new List <VariableGroupProjectReference>();

        if (!variableGroupProjectReferenced.Any(r => project.Id.Equals(r.ProjectReference?.Id)))
        {
            variableGroupProjectReferenced.Add(new VariableGroupProjectReference()
            {
                Name             = group.Name,
                Description      = group.Description,
                ProjectReference = project.ToVariableProjectReference()
            });
        }

        return(client.UpdateVariableGroupAsync(group.Id, new VariableGroupParameters()
        {
            Name = group.Name,
            Description = group.Description,
            Type = group.Type,
            Variables = group.Variables,
            VariableGroupProjectReferences = variableGroupProjectReferenced
        }));
    }