using System.Collections.Generic;
using System.Linq;
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
public Task> GetContributors(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetContributors(owner, name, CancellationToken.None);
}
///
/// Returns a list of for the given repository
///
/// The ID of the repository
public Task> GetContributors(int repositoryId)
{
return GetContributors(repositoryId, 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
public Task> GetContributors(string owner, string name, CancellationToken cancellationToken)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.GetQueuedOperation(ApiUrls.StatsContributors(owner, name), cancellationToken);
}
///
/// Returns a list of for the given repository
///
/// The ID of the repository
/// A token used to cancel this potentially long running request
public Task> GetContributors(int repositoryId, CancellationToken cancellationToken)
{
return ApiConnection.GetQueuedOperation(ApiUrls.StatsContributors(repositoryId), cancellationToken);
}
///
/// Returns the last year of commit activity grouped by week.
///
/// The owner of the repository
/// The name of the repository
public Task GetCommitActivity(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetCommitActivity(owner, name, CancellationToken.None);
}
///
/// Returns the last year of commit activity grouped by week.
///
/// The ID of the repository
public Task GetCommitActivity(int repositoryId)
{
return GetCommitActivity(repositoryId, 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
public async Task GetCommitActivity(string owner, string name, CancellationToken cancellationToken)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var activity = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsCommitActivity(owner, name), cancellationToken).ConfigureAwait(false);
return new CommitActivity(activity);
}
///
/// Returns the last year of commit activity grouped by week.
///
/// The ID of the repository
/// A token used to cancel this potentially long running request
public async Task GetCommitActivity(int repositoryId, CancellationToken cancellationToken)
{
var activity = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsCommitActivity(repositoryId), cancellationToken).ConfigureAwait(false);
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
public Task GetCodeFrequency(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetCodeFrequency(owner, name, CancellationToken.None);
}
///
/// Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
///
/// The ID of the repository
public Task GetCodeFrequency(int repositoryId)
{
return GetCodeFrequency(repositoryId, 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
public async Task GetCodeFrequency(string owner, string name, CancellationToken cancellationToken)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var rawFrequencies = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsCodeFrequency(owner, name), cancellationToken).ConfigureAwait(false);
return new CodeFrequency(rawFrequencies);
}
///
/// Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
///
/// The ID of the repository
/// A token used to cancel this potentially long running request
public async Task GetCodeFrequency(int repositoryId, CancellationToken cancellationToken)
{
var rawFrequencies = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsCodeFrequency(repositoryId), cancellationToken).ConfigureAwait(false);
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
public Task GetParticipation(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetParticipation(owner, name, CancellationToken.None);
}
///
/// Returns the total commit counts for the owner and total commit counts in total.
///
/// The ID of the repository
public Task GetParticipation(int repositoryId)
{
return GetParticipation(repositoryId, 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
public async Task GetParticipation(string owner, string name, CancellationToken cancellationToken)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var result = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsParticipation(owner, name), cancellationToken).ConfigureAwait(false);
return result.FirstOrDefault();
}
///
/// Returns the total commit counts for the owner and total commit counts in total.
///
/// The ID of the repository
/// A token used to cancel this potentially long running request
public async Task GetParticipation(int repositoryId, CancellationToken cancellationToken)
{
var result = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsParticipation(repositoryId), cancellationToken).ConfigureAwait(false);
return result.FirstOrDefault();
}
///
/// Returns a list of the number of commits per hour in each day
///
/// The owner of the repository
/// The name of the repository
public Task GetPunchCard(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetPunchCard(owner, name, CancellationToken.None);
}
///
/// Returns a list of the number of commits per hour in each day
///
/// The ID of the repository
public Task GetPunchCard(int repositoryId)
{
return GetPunchCard(repositoryId, 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
public async Task GetPunchCard(string owner, string name, CancellationToken cancellationToken)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var punchCardData = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsPunchCard(owner, name), cancellationToken).ConfigureAwait(false);
return new PunchCard(punchCardData);
}
///
/// Returns a list of the number of commits per hour in each day
///
/// The ID of the repository
/// A token used to cancel this potentially long running request
public async Task GetPunchCard(int repositoryId, CancellationToken cancellationToken)
{
var punchCardData = await ApiConnection.GetQueuedOperation(
ApiUrls.StatsPunchCard(repositoryId), cancellationToken).ConfigureAwait(false);
return new PunchCard(punchCardData);
}
}
}