I have one class GitHub with one method which should return list of all commits for specific username and repo on GitHub:
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;
}
}
}
And I have main function which call getAllCommits method:
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);
}
}
}
}
When I run this i get following error:
Problem is because this variable commit.Files is Null probably because of async call but I am not sure how to solve it. Please some help?