这是使用 Octokit.NET ( https://github.com/octokit/octokit.net )编写的获取拉取请求的所有提交的示例
var owner = "...";
var repository = "...";
var gitHubClient = new GitHubClient(
new ProductHeaderValue("MyApp"),
new InMemoryCredentialStore(new Credentials("GitHubToken")));
var pullRequest = await gitHubClient.PullRequest.Get(owner, repository, pullRequestNumber);
Console.WriteLine("Summarising Pull Request #{0} - {1}", pullRequest.Number, pullRequest.Title);
var commits = new List<GitHubCommit>();
var moreToGet = true;
var headSha = pullRequest.Head.Sha;
while (moreToGet)
{
var comparison =
await
gitHubClient.Repository.Commits.Compare(
owner,
repository,
pullRequest.Base.Sha,
headSha);
// Because we're working backwards from the head towards the base, but the oldest commits are at the start of the list
commits.InsertRange(0, comparison.Commits);
moreToGet = comparison.Commits.Count == 250;
if (moreToGet)
{
headSha = commits.First().Sha;
}
}
如果找到具有基本 sha 的提交,我最初尝试将 moreToGet 设置为 true,但从未包含在提交列表中(不知道为什么)所以我只是假设如果比较命中是 250 的限制,可以获得更多。