using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Repository Statistics API. /// /// /// See the Repository Statistics API documentation for more information. /// public class StatisticsClient : ApiClient, IStatisticsClient { /// /// Instantiates a new GitHub Statistics API client. /// /// An API connection public StatisticsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Returns a list of for the given repository /// /// The owner of the repository /// The name of the repository /// A list of public Task> GetContributors(string owner, string repositoryName) { return GetContributors(owner, repositoryName, CancellationToken.None); } /// /// Returns a list of for the given repository /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request /// A list of public async Task> GetContributors(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName); return await ApiConnection.GetQueuedOperation>(endpoint, cancellationToken); } /// /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository /// The last year of public Task GetCommitActivity(string owner, string repositoryName) { return GetCommitActivity(owner, repositoryName, CancellationToken.None); } /// /// Returns the last year of commit activity grouped by week. /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request /// The last year of public async Task GetCommitActivity(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); var activity = await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); return new CommitActivity(activity); } /// /// Returns a weekly aggregate of the number of additions and deletions pushed to a repository. /// /// The owner of the repository /// The name of the repository /// Returns a weekly aggregate of the number additions and deletion public Task GetCodeFrequency(string owner, string repositoryName) { return GetCodeFrequency(owner, repositoryName, CancellationToken.None); } /// /// Returns a weekly aggregate of the number of additions and deletions pushed to a repository. /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request /// Returns a weekly aggregate of the number additions and deletion public async Task GetCodeFrequency(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName); var rawFrequencies = await ApiConnection.GetQueuedOperation>(endpoint,cancellationToken); return new CodeFrequency(rawFrequencies); } /// /// Returns the total commit counts for the owner and total commit counts in total. /// /// The owner of the repository /// The name of the repository /// Returns from oldest week to now public Task GetParticipation(string owner, string repositoryName) { return GetParticipation(owner, repositoryName, CancellationToken.None); } /// /// Returns the total commit counts for the owner and total commit counts in total. /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request /// Returns from oldest week to now public async Task GetParticipation(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName); return await ApiConnection.GetQueuedOperation(endpoint,cancellationToken); } /// /// Returns a list of the number of commits per hour in each day /// /// The owner of the repository /// The name of the repository /// Returns commit counts per hour in each day public Task GetPunchCard(string owner, string repositoryName) { return GetPunchCard(owner, repositoryName,CancellationToken.None); } /// /// Returns a list of the number of commits per hour in each day /// /// The owner of the repository /// The name of the repository /// A token used to cancel this potentially long running request /// Returns commit counts per hour in each day public async Task GetPunchCard(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "/repos/{0}/{1}/stats/punch_card".FormatUri(owner, repositoryName); var punchCardData = await ApiConnection.GetQueuedOperation>(endpoint, cancellationToken); return new PunchCard(punchCardData); } } }