是否有 REST API 或任何其他方式来获取 VSTS 中所有存储库的所有分支?
Is there a REST API or any other way to get all branches for all repositories in VSTS?
我想要我的 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 或告诉我一种获取存储库下所有分支的方法吗?
使用 Repositories - List,您可以获得 VSTS 帐户中所有存储库的列表。
鉴于该列表,您可以使用 Refs - List 遍历所有回购协议,这样您就应该能够获得所有引用,从而获得有关分支机构的信息。
获取所有回购协议的所有分支的全局 API 调用也很困难 - 分支名称 (refs) 在不同的回购协议中可能相同。所有回购协议的一个规范候选者是 master 分支。
您可以使用两个循环获取 VSTS 帐户中所有 git 存储库的所有分支。详细步骤如下:
1。 Get all the projects 在您的 VSTS 帐户中
GET https://{account}.visualstudio.com/_apis/projects?api-version=4.1-preview.1
在响应中将 return VSTS 帐户中的所有项目。
2。从每个 VSTS 项目
的第 1 步和 get all the git repos 循环 VSTS 项目
GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories?api-version=4.1
在 REST API 的响应中,您可以获取每个项目的所有 git 回购协议。
3。从 step2 循环 git repos 并获取每个 git repo
的所有分支
您可以使用 list refs REST API 获取每个 git 存储库的所有分支:
GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=4.1
执行所有循环后,您将获得所有 git 个存储库的所有分支。
我想要我的 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 或告诉我一种获取存储库下所有分支的方法吗?
使用 Repositories - List,您可以获得 VSTS 帐户中所有存储库的列表。
鉴于该列表,您可以使用 Refs - List 遍历所有回购协议,这样您就应该能够获得所有引用,从而获得有关分支机构的信息。
获取所有回购协议的所有分支的全局 API 调用也很困难 - 分支名称 (refs) 在不同的回购协议中可能相同。所有回购协议的一个规范候选者是 master 分支。
您可以使用两个循环获取 VSTS 帐户中所有 git 存储库的所有分支。详细步骤如下:
1。 Get all the projects 在您的 VSTS 帐户中
GET https://{account}.visualstudio.com/_apis/projects?api-version=4.1-preview.1
在响应中将 return VSTS 帐户中的所有项目。
2。从每个 VSTS 项目
的第 1 步和 get all the git repos 循环 VSTS 项目GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories?api-version=4.1
在 REST API 的响应中,您可以获取每个项目的所有 git 回购协议。
3。从 step2 循环 git repos 并获取每个 git repo
的所有分支您可以使用 list refs REST API 获取每个 git 存储库的所有分支:
GET https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=4.1
执行所有循环后,您将获得所有 git 个存储库的所有分支。