Over 170 contributors have assisted GitHub in creating a GitHub API client library for .NET called Octokit.NET. The library targets .NET Framework 4.6+ and .NET Standard 2+ and above and makes it much easier to interact with the GitHub API. It’s quite easy to get started. If using a .NET Core application, from a command line you can use the dotnet installer tool by executing:

1
dotnet add package Octokit

There is another package, called Octokit.Reactive that provides an IObservable based GitHub API client for .NET Core.

1
dotnet add package Octokit.Reactive

You can also clone the repository locally by clicking the button below:

Clone Repository

In a future post, I’ll use the following code snippet to obtain a count of pull requests for my site.

1
2
3
4
5
6
7
8
9
10
11
12
const string owner = "jasongaylord";
const string repo = "JasonGaylord.com";
const string token = "<INSERT_TOKEN_HERE>";
const string project_name = "MyFirstOctokitProject";

public int CountPullRequests()
{
    var creds = new InMemoryCredentialStore(new Credentials(token));
    var client = new GitHubClient(new ProductHeaderValue(project_name), creds);
    var pullrequests = client.PullRequest.GetAllForRepository(owner, repo).Result;
    return pullrequests.Count();
}

If you haven’t checked out the client library yet, be sure to check it out.

Octokit.NET Project