C# 如何以编程方式获取AzureDevOps中所有已完成PullRequests的列表?
我正在使用以下代码获取VSTS存储库中所有已完成拉取请求的列表。但是,获取的拉请求列表只包含有限的拉请求列表,而不是全部。知道我做错了什么吗 代码如下:C# 如何以编程方式获取AzureDevOps中所有已完成PullRequests的列表?,c#,azure-devops,pull-request,programmatically,C#,Azure Devops,Pull Request,Programmatically,我正在使用以下代码获取VSTS存储库中所有已完成拉取请求的列表。但是,获取的拉请求列表只包含有限的拉请求列表,而不是全部。知道我做错了什么吗 代码如下: /// <summary> /// Gets all the completed pull requests that are created by the given identity, for the given repository /// </summary>
/// <summary>
/// Gets all the completed pull requests that are created by the given identity, for the given repository
/// </summary>
/// <param name="gitHttpClient">GitHttpClient that is created for accessing vsts.</param>
/// <param name="repositoryId">The unique identifier of the repository</param>
/// <param name="identity">The vsts Identity of a user on Vsts</param>
/// <returns></returns>
public static List<GitPullRequest> GetAllCompletedPullRequests(
GitHttpClient gitHttpClient, Guid repositoryId, Identity identity)
{
var pullRequestSearchCriteria = new GitPullRequestSearchCriteria
{
Status = PullRequestStatus.Completed,
CreatorId = identity.Id,
};
List<GitPullRequest> allPullRequests = gitHttpClient.GetPullRequestsAsync(
repositoryId,
pullRequestSearchCriteria).Result;
return allPullRequests;
}
//
///获取由给定标识为给定存储库创建的所有已完成拉取请求
///
///为访问VST而创建的GitHttpClient。
///存储库的唯一标识符
///vsts上用户的vsts标识
///
公共静态列表GetAllCompletedPullRequests(
GitHttpClient GitHttpClient,Guid repositoryId,标识)
{
var pullRequestSearchCriteria=new GitPullRequestSearchCriteria
{
状态=PullRequestStatus.Completed,
CreatorId=identity.Id,
};
列出allPullRequests=gitHttpClient.GetPullRequestsAsync(
repositoryId,
结果;
返回所有请求;
}
事实证明,默认情况下,这个获取拉请求的调用只会返回有限数量的拉请求(在我的例子中是101)。您需要做的是指定skip和top参数,它们在GetPullRequestsAsync
方法的签名定义中是可选的。以下代码显示了如何使用这些参数返回所有拉取请求:
注意:从方法的定义来看,不清楚skip的默认值和顶级参数是什么(但通过改变这些值,我每次可以得到1000)
//
///获取由给定标识为给定存储库创建的所有已完成拉取请求
///
///为访问VST而创建的GitHttpClient。
///存储库的唯一标识符
///vsts上用户的vsts标识
///
公共静态列表GetAllCompletedPullRequests(
GitHttpClient GitHttpClient,Guid repositoryId,标识)
{
var pullRequestSearchCriteria=new GitPullRequestSearchCriteria
{
状态=PullRequestStatus.Completed,
CreatorId=identity.Id,
};
List allPullRequests=new List();
int skip=0;
int阈值=1000;
while(true){
List partialPullRequests=gitHttpClient.GetPullRequestsAsync(
repositoryId,
根据搜索标准,
跳过:跳过,
顶部:阈值
).结果;
allPullRequests.AddRange(partialPullRequests);
if(partialPullRequests.Length<阈值){break;}
跳过+=阈值
}
返回所有请求;
}
事实证明,默认情况下,这个获取拉请求的调用只会返回有限数量的拉请求(在我的例子中是101)。您需要做的是指定skip和top参数,它们在GetPullRequestsAsync
方法的签名定义中是可选的。以下代码显示了如何使用这些参数返回所有拉取请求:
注意:从方法的定义来看,不清楚skip的默认值和顶级参数是什么(但通过改变这些值,我每次可以得到1000)
//
///获取由给定标识为给定存储库创建的所有已完成拉取请求
///
///为访问VST而创建的GitHttpClient。
///存储库的唯一标识符
///vsts上用户的vsts标识
///
公共静态列表GetAllCompletedPullRequests(
GitHttpClient GitHttpClient,Guid repositoryId,标识)
{
var pullRequestSearchCriteria=new GitPullRequestSearchCriteria
{
状态=PullRequestStatus.Completed,
CreatorId=identity.Id,
};
List allPullRequests=new List();
int skip=0;
int阈值=1000;
while(true){
List partialPullRequests=gitHttpClient.GetPullRequestsAsync(
repositoryId,
根据搜索标准,
跳过:跳过,
顶部:阈值
).结果;
allPullRequests.AddRange(partialPullRequests);
if(partialPullRequests.Length<阈值){break;}
跳过+=阈值
}
返回所有请求;
}
/// <summary>
/// Gets all the completed pull requests that are created by the given identity, for the given repository
/// </summary>
/// <param name="gitHttpClient">GitHttpClient that is created for accessing vsts.</param>
/// <param name="repositoryId">The unique identifier of the repository</param>
/// <param name="identity">The vsts Identity of a user on Vsts</param>
/// <returns></returns>
public static List<GitPullRequest> GetAllCompletedPullRequests(
GitHttpClient gitHttpClient, Guid repositoryId, Identity identity)
{
var pullRequestSearchCriteria = new GitPullRequestSearchCriteria
{
Status = PullRequestStatus.Completed,
CreatorId = identity.Id,
};
List<GitPullRequest> allPullRequests = new List<GitPullRequest>();
int skip = 0;
int threshold = 1000;
while(true){
List<GitPullRequest> partialPullRequests = gitHttpClient.GetPullRequestsAsync(
repositoryId,
pullRequestSearchCriteria,
skip:skip,
top:threshold
).Result;
allPullRequests.AddRange(partialPullRequests);
if(partialPullRequests.Length < threshold){break;}
skip += threshold
}
return allPullRequests;
}