Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Count commits to a specific owner's repository for a specific time period.
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
public static class GitHubCommitCounter
public static async Task Count(string owner, DateTime minDateTime)
using (var httpClient = new HttpClient())
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# HttpClient");
var repositories =
.Parse(await httpClient.GetStringAsync($"{owner}/repos"))
.Select(x => (string)x["name"]);
foreach (var repository in repositories)
var json = await httpClient.GetStringAsync($"{owner}/{repository}/commits");
var count = JArray.Parse(json)
.Where(x => (string)x.SelectToken("author.login") == owner
&& minDateTime < DateTime.Parse((string)x.SelectToken("")))
if (0 < count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment