以编程方式获取TFS责备(注释)数据

时间:2015-07-21 19:32:08

标签: c# tfs tfs2010 annotate blame

我正在尝试为Team Foundation Server 2010实施一个插件,该插件将创建有关团队项目中用户的报告。从概念上讲,为了正确实现此插件,我所需要的只是访问使用" Annotate"时所获得的相同数据。 Visual Studio中的功能:我需要能够告诉谁是最后一个创作给定代码行的人。

我已经在互联网上搜索了文档或代码示例,但我找到的所有内容都是using the TFS command-line tools或看似不完整code samples等建议。

我不介意在客户端代码中做很多繁重的事情,但似乎并不是一个明显的方法来获取有关内容的有用作者数据。 Changeset中的代码,以及merge details返回的代码。

2 个答案:

答案 0 :(得分:3)

与此同时,我找到了一个可以执行Team Foundation Power Tools进程并解析其输出的工作解决方案:

private readonly Regex m_Regex = new Regex(@"^(?<changeset>\d+)(?<codeLine>.*)", RegexOptions.Compiled | RegexOptions.Multiline);

public List<Changeset> GetAnnotations(string filepath, string codeText)
    {
        var versionControlServer = CreateVersionControlServer();

        return m_Regex.Matches(ExecutePowerTools(filepath))
            .Cast<Match>()
            .Where(m => m.Groups["codeLine"].Value.Contains(codeText))
            .Select(v => versionControlServer.GetChangeset(int.Parse(v.Groups["changeset"].Value), false, false))
            .ToList();
    }

    private static VersionControlServer CreateVersionControlServer()
    {
        var projectCollection = new TfsTeamProjectCollection(new Uri(@"TFS URL"));
        var versionControlServer = projectCollection.GetService<VersionControlServer>();
        return versionControlServer;
    }

    private static string ExecutePowerTools(string filepath)
    {
        using (var process = Process.Start(TfptLocation, string.Format("annotate /noprompt {0}", filepath)))
        {
            process.WaitForExit();
            return process.StandardOutput.ReadToEnd();
        }
    }

答案 1 :(得分:0)

我有非常类似的要求来获取文件中特定属性的详细信息,例如谁添加,何时,相关的工作项目等;以下GitHub项目正在实施以获取所需的详细信息并需要进行最少的更改 -

SonarQube SCM TFVC plugin

需要在安装了Team Foundation Server对象模型的Windows计算机上执行分析(下载TFS 2013)。

相关问题