Latest commits notes from github

For AOP with Roslyn I want to automatically get the latest commits message before doing a new commit.

This was  solved easily using https://github.com/octokit/octokit.net 

The code is  very simple:

public async Task<DateForCommit[]> BetweenLatest2Commits()
{
           
var client = new GitHubClient(new ProductHeaderValue("GitBetweenCommits"));
var rep = await client.Repository.Get(Author, RepositoryName);
var relLatest = await client.Repository.Release.GetLatest(rep.Id);
var relAll = await client.Repository.Release.GetAll(rep.Id, new ApiOptions() { PageSize = int.MaxValue - 1 });
var relBeforeLatest = relAll.OrderByDescending(it => it.CreatedAt).Skip(1).FirstOrDefault();

var dateLatest = relLatest.CreatedAt;
var dateBeforeLatest = relBeforeLatest.CreatedAt;

var commits = await client.Repository.Commit.GetAll(rep.Id, ApiOptions.None);
var res = commits
    .Where(it => 
    it.Commit.Author.Date >= dateBeforeLatest
    &&
    it.Commit.Author.Date<=dateLatest
    )
    .Select(it => new DateForCommit()
    {
        Author = it.Commit.Author.Name,
        Message = it.Commit.Message,
        CommitDate = it.Commit.Author.Date.DateTime
    })
    .ToArray();
return res;
}

It works also as a .NET Global tool
Install with

dotnet tool install –global dotnet-gcr

run with

dotnet gcr

for example for https://github.com/ignatandrei/AOP_With_Roslyn the arguments are

dotnet gcr ignatandrei AOP_With_Roslyn

NuGet at https://www.nuget.org/packages/dotnet-gcr/

Full Code at https://github.com/ignatandrei/GitCommitsBetweenReleases
enjoy