我有一个类 GitHub,其中一种方法应该返回 GitHub 上特定用户名和 repo 的所有提交列表:
using System;
using Octokit;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace ReadRepo
{
public class GitHub
{
public GitHub()
{
}
public async Task<List<GitHubCommit>> getAllCommits()
{
string username = "lukalopusina";
string repo = "flask-microservices-main";
var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp"));
var repository = await github.Repository.Get(username, repo);
var commits = await github.Repository.Commit.GetAll(repository.Id);
List<GitHubCommit> commitList = new List<GitHubCommit>();
foreach(GitHubCommit commit in commits) {
commitList.Add(commit);
}
return commitList;
}
}
}
我有调用 getAllCommits 方法的主函数:
using System;
using Octokit;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace ReadRepo
{
class MainClass
{
public static void Main(string[] args)
{
GitHub github = new GitHub();
Task<List<GitHubCommit>> commits = github.getAllCommits();
commits.Wait(10000);
foreach(GitHubCommit commit in commits.Result) {
foreach (GitHubCommitFile file in commit.Files)
Console.WriteLine(file.Filename);
}
}
}
}
当我运行它时,我收到以下错误:
问题是因为这个变量 commit.Files 是 Null 可能是因为异步调用,但我不知道如何解决它。请帮忙?