refs/heads/{sourceBranch}
和
refs/heads/{targetBranch}
有人可以帮忙吗?
public async Task<GitCommitRef[]> GetCommits(string sourceBranch, string targetBranch)
{
VssConnection conn = new(new Uri(this._azureDevOpsUrl), new VssBasicCredential(string.Empty, pat));
GitHttpClient client = conn.GetClient<GitHttpClient>();
List<GitCommitRef> commits = [];
try
{
List<GitCommitRef> res = await client.GetCommitsAsync(projectname, reponame, new GitQueryCommitsCriteria
{
ItemVersion = new GitVersionDescriptor
{
// I also tried refs/heads/{sourceBranch} and refs/heads/{targetBranch}, didnt work either
VersionType = GitVersionType.Branch,
Version = sourceBranch
},
CompareVersion = new GitVersionDescriptor
{
VersionType = GitVersionType.Branch,
Version = targetBranch
}
});
if (res != null)
{
commits.AddRange(res);
}
}
catch (Exception ex)
{
ConsoleEx.Throw($"Error fetching commits: {ex.Message}");
}
return commits.ToArray();
}
在您的代码中调用的函数'
GetCommitsAsync
'的相应的azure rest api是“commits -getconsitssearchCriteria.itemVersion.version
On a branch
”上,'searchCriteria.itemVersion.version
),而不是分支的全名(例如,例如,
refs/heads/main
)。
我也尝试了这个API:
如果我将'
searchCriteria.itemVersion.version
'的值设置为
refs/heads/main
,我可以获得相同的
TF401175如果我将'
searchCriteria.itemVersion.version
'的值设置为main