Пример #1
0
        public static async Task SaveWorkItemsAsync(EFU workItem)
        {
            var tags = string.Join(';', workItem.Tags);
            var ops  = new[]
            {
                new Op {
                    op = AddOperation, path = SystemTags, value = tags
                }
            }.ToList();

            var result = await ProcessRequest <dynamic>(string.Format(CultureInfo.InvariantCulture, WorkItemUpdateUrl, workItem.Id), ops?.ToJson(), true).ConfigureAwait(false);

            ColorConsole.WriteLine($"Updated Tags for {workItem.Id}: {tags}".White().OnDarkGreen());
        }
Пример #2
0
        private static async Task <bool> UpdateParentTags(EFU parent, string tagToPromote, bool remove)
        {
            var update = false;

            if (parent != null)
            {
                var contains = parent.Tags?.Contains(tagToPromote) == true;
                if (remove)
                {
                    if (contains)
                    {
                        if (parent.Tags == null)
                        {
                            parent.Tags = new List <string>();
                        }

                        parent.Tags.Remove(tagToPromote);
                        update = true;
                    }
                }
                else
                {
                    if (!contains)
                    {
                        if (parent.Tags == null)
                        {
                            parent.Tags = new List <string>();
                        }

                        parent.Tags.Add(tagToPromote);
                        update = true;
                    }
                }

                if (update)
                {
                    var action = remove ? "removed from" : "promoted to";
                    ColorConsole.WriteLine($" Tag '{tagToPromote}' {action} parent '{parent.Id}'".Yellow());
                    if (!ReportOnly)
                    {
                        await SaveWorkItemsAsync(parent).ConfigureAwait(false);
                    }
                }
            }

            return(update);
        }
Пример #3
0
        private static async Task IterateWorkItems(List <WorkitemRelation> relations, EFU parent, WiqlRelationList wis)
        {
            if (relations.Count > 0)
            {
                workitems = await GetWorkItems(relations.ToList());

                foreach (var wi in workitems)
                {
                    ColorConsole.WriteLine($" {wi.fields.SystemWorkItemType} ".PadLeft(22) + wi.id.ToString().PadLeft(6) + Dot + wi.fields.SystemTitle + $" [Tags: {wi.fields.SystemTags}]");
                    var efu = new EFU
                    {
                        Id           = wi.id,
                        Title        = wi.fields.SystemTitle,
                        Workitemtype = wi.fields.SystemWorkItemType,
                        Tags         = wi.fields.SystemTags?.Split(TagsDelimiters, StringSplitOptions.RemoveEmptyEntries)?.Select(x => x.Trim())?.ToList(),
                        Parent       = parent?.Id
                    };

                    var updates = (await ProcessRequest <Updates>(string.Format(CultureInfo.InvariantCulture, WorkItemUpdatesUrl, efu.Id)).ConfigureAwait(false))?.value;
                    if (updates?.Length > 0)
                    {
                        foreach (var tag in TagsToPromote)
                        {
                            var tagged   = updates?.Where(x => !(x?.fields?.SystemTags?.oldValues?.Contains(tag) == true) && (x?.fields?.SystemTags?.newValues?.Contains(tag) == true))?.OrderBy(x => x.rev)?.FirstOrDefault();
                            var untagged = efu.Tags?.Contains(tag) == true ? null : updates?.Where(x => (x?.fields?.SystemTags?.oldValues?.Contains(tag) == true) && !(x?.fields?.SystemTags?.newValues?.Contains(tag) == true))?.OrderByDescending(x => x.rev)?.FirstOrDefault(); // x => x.revisedDate.Year > DateTime.MinValue.Year && x.revisedDate.Year < DateTime.MaxValue.Year
                            if (tagged != null || untagged != null)
                            {
                                var wtag = new WorkItemTag {
                                    Id = efu.Id, Title = efu.Title, ChangedBy = $"{tagged?.revisedBy?.displayName} / {untagged?.revisedBy?.displayName}", Type = efu.Workitemtype, Tag = tag, CurrentTags = efu.Tags == null ? string.Empty : string.Join(", ", efu.Tags), Added = tagged?.fields?.SystemChangedDate?.newValue, Removed = untagged?.fields?.SystemChangedDate?.newValue
                                };
                                workItemTags.Add(wtag);
                            }
                        }
                    }

                    efus.Add(efu);
                    parent?.Children.Add(efu.Id);
                    await IterateWorkItems(wis.workItemRelations.Where(x => x.source != null && x.source.id.Equals(wi.id)).ToList(), efu, wis);
                }
            }
        }