Esempio n. 1
0
    public override void Run()
    {
        WorkItemStore store     = Driver.TeamFoundationServer.GetService(typeof(WorkItemStore)) as WorkItemStore;
        ILinking      linking   = Driver.TeamFoundationServer.GetService(typeof(ILinking)) as ILinking;
        int           changeSet = 1;

        // Get URI for changeset
        ArtifactId changeSetId = new ArtifactId();

        changeSetId.Tool           = "VersionControl";
        changeSetId.ArtifactType   = "ChangeSet";
        changeSetId.ToolSpecificId = changeSet.ToString();
        string changeSetUri = LinkingUtilities.EncodeUri(changeSetId);

        // Get referencing artifacts for given changeset
        Artifact[] artifacts = linking.GetReferencingArtifacts(new string[] { changeSetUri }, null);

        foreach (Artifact artifact in artifacts)
        {
            Console.WriteLine(artifact.ToString());
            ArtifactId artifactId = LinkingUtilities.DecodeUri(artifact.Uri);
            if (String.Equals(artifactId.Tool, "WorkItemTracking", StringComparison.OrdinalIgnoreCase))
            {
                WorkItem wi = store.GetWorkItem(Convert.ToInt32(artifactId.ToolSpecificId));
                Console.WriteLine(wi);
            }
        }
    }
Esempio n. 2
0
        public static void List(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: WorkItemHelper.List <URL for TFS> <server path>");
                //Environment.Exit(1);
                return;
            }

            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(args[0]));
            VersionControlServer     vcs = tpc.GetService <VersionControlServer>();

            // Get the changeset artifact URIs for each changeset in the history query
            List <string> changesetArtifactUris = new List <string>();

            foreach (Object obj in vcs.QueryHistory(args[1],                       // path we care about ($/project/whatever)
                                                    VersionSpec.Latest,            // version of that path
                                                    0,                             // deletion ID (0 = not deleted)
                                                    RecursionType.Full,            // entire tree - full recursion
                                                    null,                          // include changesets from all users
                                                    new ChangesetVersionSpec(1),   // start at the beginning of time
                                                    VersionSpec.Latest,            // end at latest
                                                    100,                           // only return these max count rows
                                                    false,                         // we don't want the files changed
                                                    true))                         // do history on the path
            {
                Changeset c = obj as Changeset;
                changesetArtifactUris.Add(c.ArtifactUri.AbsoluteUri);
            }

            // We'll use the linking service to get information about the associated work items
            ILinking   linkingService = tpc.GetService <ILinking>();
            LinkFilter linkFilter     = new LinkFilter();

            linkFilter.FilterType   = FilterType.ToolType;
            linkFilter.FilterValues = new string[1] {
                ToolNames.WorkItemTracking
            };                                                                       // we only want work items

            // Convert the artifact URIs for the work items into strongly-typed objects holding the properties rather than name/value pairs
            Artifact[] artifacts = linkingService.GetReferencingArtifacts(changesetArtifactUris.ToArray(), new LinkFilter[1] {
                linkFilter
            });
            AssociatedWorkItemInfo[] workItemInfos = AssociatedWorkItemInfo.FromArtifacts(artifacts);

            // Here we'll just print the IDs and titles of the work items
            foreach (AssociatedWorkItemInfo workItemInfo in workItemInfos.OrderByDescending(a => a.Id).ToList())
            {
                Console.WriteLine("Id: " + workItemInfo.Id + " Title: " + workItemInfo.Title);
            }
        }
Esempio n. 3
0
File: TFS.cs Progetto: Eun/TFSMonkey
        public IEnumerable <IWorkItem> GetWorkItems(ICollection <HistoryItem> historyItems)
        {
            Debug.WriteLine($"Getting WorkItems for {historyItems.Count} HistoryItems");
            LinkFilter linkFilter = new LinkFilter();

            linkFilter.FilterType   = FilterType.ToolType;
            linkFilter.FilterValues = new String[1] {
                ToolNames.WorkItemTracking
            };

            Artifact[] artifacts = _linkingService.GetReferencingArtifacts(historyItems.Select(item => item.ChangeSet.ArtifactUri.AbsoluteUri).ToArray(), new LinkFilter[1] {
                linkFilter
            });
            var col = IWorkItem.FromArtifacts(artifacts, WorkItemFactory);

            Debug.WriteLine($"{col.Count} WorkItems Fetched");
            return(col.OrderByDescending(item => item.Id));
        }
Esempio n. 4
0
        public IList <WorkItem> GetAssociateItems(int changeset)
        {
            var result = new List <WorkItem>();

            // Создал объект для получения URL
            var setId = new ArtifactId
            {
                Tool           = ToolNames.VersionControl,
                ArtifactType   = WorkItemTypes.ChangeSet,
                ToolSpecificId = changeset.ToString()
            };

            // По этому URL буду искать линкованные элементы
            var uri = LinkingUtilities.EncodeUri(setId);

            // Нашел связи
            var linked = _linking.GetReferencingArtifacts(new[] { uri });

            Trace.WriteLine($"{nameof(TfsApi)}.{nameof(GetAssociateItems)}: Founded {linked.Length} links");

            foreach (var artifact in linked)
            {
                // Распарсил url
                var artifactId = LinkingUtilities.DecodeUri(artifact.Uri);
                // Какая-то хитрая проверка
                if (string.Equals(artifactId.Tool, ToolNames.WorkItemTracking, StringComparison.OrdinalIgnoreCase))
                {
                    // Нашёл элемент
                    var item = _itemStore.GetWorkItem(Convert.ToInt32(artifactId.ToolSpecificId));
                    // Добавил
                    result.Add(item);
                }
            }

            Trace.WriteLineIf(result.Any(),
                              $"{nameof(TfsApi)}.{nameof(GetAssociateItems)}: Changeset {changeset} linked with items: {string.Join(", ", result.Select(x => x.Id))}");

            return(result);
        }
Esempio n. 5
0
        public List <ClientWorkItem> GetWorkItemsFromChangesets(List <Changeset> changes, List <string> stateFilter)
        {
            var asd         = changes.Select(x => x.ArtifactUri.ToString()).ToList();
            var linkFilters = new[]
            {
                new LinkFilter
                {
                    FilterType   = FilterType.ToolType,
                    FilterValues = new[] { "WorkItemTracking" }
                }
            };
            var artifacts     = _linkingServer.GetReferencingArtifacts(asd.ToArray(), linkFilters);
            var workItemInfos = artifacts.ToClientWorkItems();
            var workItemIds   = workItemInfos.Select(x => x.Id).ToList();
            //.Where(x => x.Type.ToString() != "Code Review Request" && x.Type.ToString() != "Task").ToList()
            //.Where(x => stateFilter.Contains(x.State))
            //.Select(x => x.Id.ToString()).Distinct().ToList();
            var joinedWorkItems = string.Join(",", workItemIds);
            var workItems       = _itemStore.Query(string.Format(_workItemsByIds, joinedWorkItems)).Cast <WorkItem>().ToList();

            return(workItems.Select(workItem => workItem.ToClientWorkItem()).ToList());
        }