c# - 使用 TFS WIQL 获取用户故事的变更集 ID?

标签 c# tfs wiql

检索分配给我的用户故事

WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));                      
String _Query = @"SELECT [System.Id] FROM WorkItems where [Assigned to] = @Me AND [Work Item Type] = 'User Story'";
WorkItemCollection _Collection = _WorkItemStore.Query(_Query);

用户故事可以将任务或错误工作项类型分配给它作为子项。然后错误/任务有链接到它们的变更集。

我是否可以检索这些变更集的列表,这些变更集附加到作为这些用户故事的子项的任务/错误?

最佳答案

我添加了这个答案作为替代方案,但我仍然很想知道是否有可能通过 WIQL 查询获得同样的结果。

我编写的递归函数,用于检索与任何子工作项关联的用户故事的所有变更集。

public List<Changeset> Query(int id, List<Changeset> associatedChangesets)
{            
    WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));            
    WorkItem _WorkItem = _WorkItemStore.GetWorkItem(id);

    List<Changeset> _AssociatedChangesets;

    if (associatedChangesets == null)
    {
            _AssociatedChangesets = new List<Changeset>();
    }
    else
    {
        _AssociatedChangesets = associatedChangesets;
    }

    foreach (Link _Link in _WorkItem.Links)
    {
        RelatedLink _RelatedLink = null;
        ExternalLink _ExternalLink = null;

        if(_Link is RelatedLink)
        {
            _RelatedLink = (RelatedLink)_Link;
        }
        else if(_Link is ExternalLink)
        {
            _ExternalLink = (ExternalLink)_Link;
        }

        if (_ExternalLink != null)
        {
            ArtifactId _Artifact = LinkingUtilities.DecodeUri(_ExternalLink.LinkedArtifactUri);
            if (String.Equals(_Artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
            {                        
                _AssociatedChangesets.Add(__VersionControl.ArtifactProvider.GetChangeset(new Uri(_ExternalLink.LinkedArtifactUri)));
            }
        }

        if (_RelatedLink != null)
        {
            if (String.Equals(_RelatedLink.LinkTypeEnd.Name, "Child", StringComparison.Ordinal))
            {
                associatedChangesets = Query(_RelatedLink.RelatedWorkItemId, _AssociatedChangesets);
            }
        }
    }
    return associatedChangesets;
}

关于c# - 使用 TFS WIQL 获取用户故事的变更集 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22359399/

相关文章:

java - SonarQube CLI 扫描仪无法保留堆

python - 使用 WIQL 从 Azure Devops 检索链接的工作项

c# - View 模型中的异步方法 : should this return Task or void?

c# - Process.Start 在某些客户端上随机阻塞/挂起

visual-studio - 如何在大型 TFS 管理的 Visual Studio 项目中批量重构类/cs 文件名

c# - 如何获取 TFS WIQL 项目的所有用户以及团队迭代?

json - TFS API - WIQL - 查询只返回 id 和 url

c# - Linq 是否缓存多个 From 的结果?

c# - 将字节数组从 C++ 传递到 C# 程序集有哪些不同的方法?

c# - 如何判断哪个 TestCaseData 失败(在 TestCaseSource 代码中)