【发布时间】:2018-07-19 18:30:50
【问题描述】:
我想获得我的 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 或告诉我一种获取存储库下所有分支的方法?
【问题讨论】:
-
你想获取给定 repo 的所有分支吗? REST API 列表 refs 可以返回给定 git repo 的所有分支和标签。
-
不是给定的仓库,我需要所有仓库的分支信息。
-
我在回答中添加了获取git repos所有分支的方法,你可以试试。
标签: git azure-devops azure-devops-rest-api