代码之家  ›  专栏  ›  技术社区  ›  tRuEsAtM

是否有rest api或其他方法来获取vsts中所有存储库的所有分支?

  •  1
  • tRuEsAtM  · 技术社区  · 6 年前

    我想有我的vsts帐户下所有存储库的所有分支的列表。 我能找到 https://{account}.visualstudio.com/DefaultCollection/_apis/git/repositories?api-version=1.0 . 但是,这并没有列出我的存储库下的所有分支,它只列出默认分支。

    我有C_的密码,

    var personalaccesstoken = "TOKEN";
    
    using (HttpClient client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(
        new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
    
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
        Convert.ToBase64String(
            System.Text.ASCIIEncoding.ASCII.GetBytes(
                string.Format("{0}:{1}", "", personalaccesstoken))));
    
    using (HttpResponseMessage response = client.GetAsync(
                "https://{account}.visualstudio.com/DefaultCollection/_apis/git/repositories?api-version=1.0").Result)
    {
        response.EnsureSuccessStatusCode();
        string responseBody = await response.Content.ReadAsStringAsync();
        Console.WriteLine(responseBody);
    }
    Console.ReadLine();
    

    有谁能指出rest api或者告诉我一种方法来获取存储库下的所有分支吗?

    2 回复  |  直到 6 年前
        1
  •  4
  •   Marina Liu    6 年前

    您可以使用两个循环来获取vsts帐户中所有git存储库的所有分支。具体步骤如下:

    Get all the projects 在您的vsts帐户中

    GET https://{account}.visualstudio.com/_apis/projects?api-version=4.1-preview.1
    

    在响应中将返回vsts帐户中的所有项目。

    2.步骤1和中VSTS项目的循环 get all the git repos 每个VSTS项目的

    GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories?api-version=4.1
    

    在rest api的响应中,您可以为每个项目执行所有git响应。

    三。从步骤2循环git repo并获取每个git repo的所有分支

    你可以用 list refs rest api获取每个git repo的所有分支:

    GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=4.1
    

    执行完所有循环后,您将获得所有git repo的所有分支。

        2
  •  0
  •   milbrandt    6 年前

    Repositories - List 您可以获取VSTS帐户中所有回购的列表。

    给定该列表,您可以使用 Refs - List 这样你就可以得到所有的参考文献,以及关于分支的信息。

    获取所有repo的所有分支的全局API调用也很困难-分支名称(ref)在不同的repo中可能相同所有回购协议的一个经典候选人是master branch。