Accessing GitHub using REST and C#

Accessing GitHub using REST and C#

Some time ago I created a GitStat app and described it in this post. To do that I used the libgit2sharp library, which I also planned to use for git plugin for TeamScreen. Unfortunately, at the time I’m writing this post, there isn’t the libgit2sharp version for .NET Core. I needed alternate approach so I decided to go for accessing GitHub repository via its REST API. I wanted to have general solution, but it’s just not possible at this time 🙁

Plugin creation is described in previous posts and I’m gonna use an excellent RestEase library for accessing GitHub’s REST API. Description why RestEase is fun and how to use it you can find here. I want to display recent commits and also some basic statistics, an interface for RestEase shows what’s exactly I’m gonna need from GitHub:

Having clients interface, next I create GitHubService, that uses it:

Next, we need a controller:

The controller uses GitHubService to get all needed information, returns it then to the view:

All that code produces this screen:

I skip mapping and settings part because they’re very similar to what I described in previous posts. As you can see, having established plugin architecture pays off and adding new plugins is fast and straightforward. Full source code is available on GitHub. Thanks for reading and see you next time!

One thought on “Accessing GitHub using REST and C#

  1. Pingback:

Leave a Reply

Your email address will not be published. Required fields are marked *