从合并变更集中获取工作项

时间:2019-06-21 19:01:24

标签: tfs tfs2017

我需要从生产构建中生成工作项目列表,该列表由合并触发。在从我关心的构建中提取Changeset ID后,我使用下面的方法获取更改列表

         CLASS GRADE   CATEGORY CATEGORY_1
STUD_ID                                   
1        'Sci'   max    'Alpha'    'Alpha'
2        'Sci'     7    'Omega'    'Alpha'
3        'Sci'     9    'Alpha'    'Alpha'
4        'Sci'     3    'Alpha'    'Alpha'
5        'Sci'     9    'Alpha'    'Alpha'
7        'eng'   max    'Gamma'    'Gamma'
8        'eng'     5    'Gamma'    'Gamma'
9        'eng'     3  'Epsilon'    'Gamma'
10       'Art'     3   'Lambda'  undefined
11       'Art'     8   'Lambda'  undefined
12       'Art'   max  undefined  undefined
13       'Art'     1  undefined  undefined
14       'Art'     5  undefined  undefined

但是,对象中似乎没有任何有关每个签入源的内容。如前所述,我主要需要工作项,因此以后可以链接回我们的JIRA票证。

我尝试了以下操作,但未返回任何内容

Uri tfsUri = new Uri("http://leecrp-tfs1:8080/tfs");
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
VersionControlServer vcs = tfs.GetService<VersionControlServer>();

List<String> changedThings = new List<String>();
Build bld = _builds.Where(x => x.BuildNumber == buildNumber).First();

if(bld != null)
{
    int.TryParse(bld.SourceVersion, out int csId);
    if (csId > 0)
    {
        Changeset changeset = vcs.GetChangeset(csId);
        foreach(Microsoft.TeamFoundation.VersionControl.Client.Change change in changeset.Changes)
        {
            changedThings.Add(change.Item.ServerItem);
        }
    }                
}

if(changedThings != null && changedThings.Count > 0)
{
    lbChanges.DataSource = changedThings;
}

1 个答案:

答案 0 :(得分:1)

事实证明,我只需要稍作修改即可。下面为我​​提供了合并细节

VersionSpec versionSpec = VersionSpec.ParseSingleSpec(csId.ToString(), null);
ChangesetMergeDetails results = vcs.QueryMergesWithDetails(@"$/Project/SourceBranch", VersionSpec.Latest, 0, @"$/Project/TargetBranch", VersionSpec.Latest, 0, versionSpec, versionSpec, RecursionType.Full);

从那里我使用过多的foreach循环来获取我想要的东西:

foreach(Changeset thing in results.Changesets)
{
    foreach(WorkItem workItem in thing.WorkItems.Distinct())
    {
        changedItems.Add(workItem.Id.ToString());

        foreach (Revision revision in workItem.Revisions)
        {
            foreach (Field field in workItem.Fields)
            {
                if(field.Name == "History")
                {
                    string thingICareAbout = revision.Fields[field.Name].Value.ToString();
                    if (thingICareAbout.Contains("TFS4JIRA"))
                    {
                        wiHistory.Add(ParseJIRT(thingICareAbout));
                    }                                        
                }
            }
        }
    }
}