Beispiel #1
0
        /// <summary>
        /// Add existing iteraions to a team
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="TeamName"></param>
        static void AddTeamAreas(string TeamProjectName, string TeamName)
        {
            TeamContext teamContext = new TeamContext(TeamProjectName, TeamName);

            Console.WriteLine("Add areas to the team " + TeamName);

            string[] areas = { @"Application\WinClient", @"Application\WebClient" };

            TeamFieldValues currentTeamAreas = WorkClient.GetTeamFieldValuesAsync(teamContext).Result; // get current areas

            TeamFieldValuesPatch teamAreasPatch = new TeamFieldValuesPatch();

            List <TeamFieldValue> newTeamAreas = new List <TeamFieldValue>(currentTeamAreas.Values); // just copy old areas. Here we may remove unneeded areas

            foreach (string area in areas)
            {
                newTeamAreas.Add(new TeamFieldValue {
                    Value = TeamProjectName + "\\" + area, IncludeChildren = false
                });                                                                                                      // add new areas
            }
            teamAreasPatch.DefaultValue = currentTeamAreas.DefaultValue;
            teamAreasPatch.Values       = newTeamAreas;

            TeamFieldValues updatedTeamAreas = WorkClient.UpdateTeamFieldValuesAsync(teamAreasPatch, teamContext).Result;

            Console.WriteLine("Areas has been added");
        }
Beispiel #2
0
        protected override Models.Team DoSetItem()
        {
            var(tpc, tp, t) = GetCollectionProjectAndTeam();
            var description      = GetParameter <string>(nameof(SetTeam.Description));
            var defaultTeam      = GetParameter <bool>(nameof(SetTeam.Default));
            var defaultAreaPath  = GetParameter <string>(nameof(SetTeam.DefaultAreaPath));
            var areaPaths        = GetParameter <IEnumerable <string> >(nameof(SetTeam.AreaPaths));
            var backlogIteration = GetParameter <string>(nameof(SetTeam.BacklogIteration));
            var iterationPaths   = GetParameter <IEnumerable <string> >(nameof(SetTeam.IterationPaths));
            var defaultIteration = GetParameter <string>(nameof(SetTeam.DefaultIterationMacro));

            var teamClient    = GetClient <TeamHttpClient>();
            var projectClient = GetClient <ProjectHttpClient>();
            var workClient    = GetClient <WorkHttpClient>();

            // Set description

            if (HasParameter("Description") && ShouldProcess(t, $"Set team's description to '{description}'"))
            {
                teamClient.UpdateTeamAsync(new WebApiTeam()
                {
                    Description = description ?? string.Empty
                }, tp.Id.ToString(), t.Id.ToString())
                .GetResult($"Error setting team '{t.Name}''s description to '{description}'");
            }

            // Set default team

            if (defaultTeam && ShouldProcess(tp, $"Set team '{t.Name} as default'"))
            {
                throw new NotImplementedException("Set team as default is currently not supported");
            }

            // Set Team Field / Area Path settings

            var ctx            = new TeamContext(tp.Name, t.Name);
            var teamFieldPatch = new TeamFieldValuesPatch();

            if (!string.IsNullOrEmpty(defaultAreaPath) &&
                ShouldProcess(t, $"Set team's default area path (team field) to '{defaultAreaPath}'"))
            {
                if (tpc.IsHosted)
                {
                    this.Log("Conected to Azure DevOps Services. Treating Team Field Value as Area Path");
                    defaultAreaPath = NodeUtil.NormalizeNodePath(defaultAreaPath, tp.Name, "Areas", includeTeamProject: true);
                }

                if (areaPaths == null)
                {
                    this.Log("AreaPaths is empty. Adding DefaultAreaPath (TeamFieldValue) to AreaPaths as default value.");

                    areaPaths = new string[] { defaultAreaPath };
                }

                var area = new { Node = defaultAreaPath };

                if (!TestItem <Models.ClassificationNode>(area))
                {
                    NewItem <Models.ClassificationNode>(area);
                }

                this.Log($"Setting default area path (team field) to {defaultAreaPath}");

                teamFieldPatch.DefaultValue = defaultAreaPath;
            }

            if (areaPaths != null &&
                ShouldProcess(t, $"Set {string.Join(", ", areaPaths)} as team's area paths"))
            {
                var values = new List <TeamFieldValue>();

                foreach (var a in areaPaths)
                {
                    values.Add(new TeamFieldValue()
                    {
                        Value           = NodeUtil.NormalizeNodePath(a.TrimEnd('\\', '*'), tp.Name, scope: "Areas", includeTeamProject: true),
                        IncludeChildren = a.EndsWith("*")
                    });
                }

                teamFieldPatch.Values = values;

                workClient.UpdateTeamFieldValuesAsync(teamFieldPatch, ctx)
                .GetResult("Error applying team field value and/or area path settings");
            }

            // Set backlog and iteration path settings

            bool isDirty        = false;
            var  iterationPatch = new TeamSettingsPatch();

            if (backlogIteration != null &&
                ShouldProcess(t, $"Set the team's backlog iteration to '{backlogIteration}'"))
            {
                this.Log($"Setting backlog iteration to {backlogIteration}");

                var iteration = GetItem <Models.ClassificationNode>(new
                {
                    Node           = backlogIteration,
                    StructureGroup = TreeStructureGroup.Iterations
                });

                iterationPatch.BacklogIteration     =
                    iterationPatch.DefaultIteration =
                        iteration.Identifier;

                isDirty = true;
            }

            if (!string.IsNullOrEmpty(defaultIteration) &&
                ShouldProcess(t, $"Set the team's default iteration to '{defaultIteration}'"))
            {
                this.Log($"Setting default iteration to '{defaultIteration}'");

                if (!defaultIteration.StartsWith("@"))
                {
                    var iteration = GetItem <Models.ClassificationNode>(new
                    {
                        Node           = defaultIteration,
                        StructureGroup = TreeStructureGroup.Iterations
                    });

                    iterationPatch.DefaultIteration = iteration.Identifier;
                }
                else
                {
                    iterationPatch.DefaultIteration      = null;
                    iterationPatch.DefaultIterationMacro = defaultIteration;
                }

                isDirty = true;
            }

            if (isDirty)
            {
                workClient.UpdateTeamSettingsAsync(iterationPatch, ctx)
                .GetResult("Error applying iteration and/or board settings");
            }

            // TODO: Finish migration

            //         if (BacklogVisibilities && ShouldProcess(Team, $"Set the team"s backlog visibilities to {_DumpObj {BacklogVisibilities}}"))
            //         {
            //             this.Log($"Setting backlog iteration to {BacklogVisibilities}");
            //             patch.BacklogVisibilities = _NewDictionary @([string], [bool]) BacklogVisibilities

            //             isDirty = true
            //         }

            //         if (DefaultIterationMacro && ShouldProcess(Team, $"Set the team"s default iteration macro to {DefaultIterationMacro}"))
            //         {
            //             this.Log($"Setting default iteration macro to {DefaultIterationMacro}");
            //             patch.DefaultIterationMacro = DefaultIterationMacro

            //             isDirty = true
            //         }

            //         if (WorkingDays && ShouldProcess(Team, $"Set the team"s working days to {_DumpObj {WorkingDays}}"))
            //         {
            //             this.Log($"Setting working days to {{WorkingDays}|ConvertTo=-Json -Compress}");
            //             patch.WorkingDays = WorkingDays

            //             isDirty = true
            //         }

            //         if(BugsBehavior && ShouldProcess(Team, $"Set the team"s bugs behavior to {_DumpObj {BugsBehavior}}"))
            //         {
            //             this.Log($"Setting bugs behavior to {_DumpObj {BugsBehavior}}");
            //             patch.BugsBehavior = BugsBehavior

            //             isDirty = true
            //         }

            //         if(isDirty)
            //         {
            //             task = client.UpdateTeamSettingsAsync(patch, ctx)
            //             result = task.Result; if(task.IsFaulted) { _throw new Exception("Error applying iteration settings" task.Exception.InnerExceptions })
            //         }

            //         if(Passthru.IsPresent)
            //         {
            //             WriteObject(t); return;
            //         }
            //     }
            // }

            return(GetItem <Models.Team>());
        }