using System; using System.Collections.Generic; using System.Reactive; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Clients; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableRepositoriesClient : IObservableRepositoriesClient { readonly IRepositoriesClient _client; readonly IConnection _connection; public ObservableRepositoriesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository; _connection = client.Connection; CommitStatus = new ObservableCommitStatusClient(client); Hooks = new ObservableRepositoryHooksClient(client); Forks = new ObservableRepositoryForksClient(client); RepoCollaborators = new ObservableRepoCollaboratorsClient(client); Deployment = new ObservableDeploymentsClient(client); Statistics = new ObservableStatisticsClient(client); PullRequest = new ObservablePullRequestsClient(client); RepositoryComments = new ObservableRepositoryCommentsClient(client); Commits = new ObservableRepositoryCommitsClient(client); DeployKeys = new ObservableRepositoryDeployKeysClient(client); Content = new ObservableRepositoryContentsClient(client); Merging = new ObservableMergingClient(client); } /// /// Creates a new repository for the current user. /// /// A instance describing the new repository to create /// An instance for the created repository public IObservable Create(NewRepository newRepository) { Ensure.ArgumentNotNull(newRepository, "newRepository"); if (string.IsNullOrEmpty(newRepository.Name)) throw new ArgumentException("The new repository's name must not be null."); return _client.Create(newRepository).ToObservable(); } /// /// Creates a new repository in the specified organization. /// /// The login of the organization in which to create the repostiory /// A instance describing the new repository to create /// An instance for the created repository public IObservable Create(string organizationLogin, NewRepository newRepository) { Ensure.ArgumentNotNull(organizationLogin, "organizationLogin"); Ensure.ArgumentNotNull(newRepository, "newRepository"); if (string.IsNullOrEmpty(newRepository.Name)) throw new ArgumentException("The new repository's name must not be null."); return _client.Create(organizationLogin, newRepository).ToObservable(); } /// /// Deletes a repository for the specified owner and name. /// /// The owner of the repository /// The name of the repository /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. /// An for the operation public IObservable Delete(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Delete(owner, name).ToObservable(); } /// /// Retrieves the for the specified owner and name. /// /// The owner of the repository /// The name of the repository /// A public IObservable Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Get(owner, name).ToObservable(); } /// /// Retrieves every public . /// /// /// The default page size on GitHub.com is 30. /// /// A of . public IObservable GetAllPublic() { return _connection.GetAndFlattenAllPages(ApiUrls.AllPublicRepositories()); } /// /// Retrieves every public since the last repository seen. /// /// /// The default page size on GitHub.com is 30. /// /// Search parameters of the last repository seen /// A of . public IObservable GetAllPublic(PublicRepositoryRequest request) { Ensure.ArgumentNotNull(request, "request"); var url = ApiUrls.AllPublicRepositories(request.Since); return _connection.GetAndFlattenAllPages(url); } /// /// Retrieves every that belongs to the current user. /// /// /// The default page size on GitHub.com is 30. /// /// Thrown if the client is not authenticated. /// A of . public IObservable GetAllForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Repositories()); } /// /// Retrieves every that belongs to the current user. /// /// /// The default page size on GitHub.com is 30. /// /// Search parameters to filter results on /// Thrown if the client is not authenticated. /// A of . public IObservable GetAllForCurrent(RepositoryRequest request) { Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(), request.ToParametersDictionary()); } /// /// Retrieves every that belongs to the specified user. /// /// /// The default page size on GitHub.com is 30. /// /// A of . public IObservable GetAllForUser(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(login)); } /// /// Retrieves every that belongs to the specified organization. /// /// /// The default page size on GitHub.com is 30. /// /// A of . public IObservable GetAllForOrg(string organization) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationRepositories(organization)); } /// /// A client for GitHub's Commit Status API. /// /// /// See the Commit Status API documentation for more /// details. Also check out the blog post /// that announced this feature. /// public IObservableCommitStatusClient CommitStatus { get; private set; } /// /// Client for GitHub's Repository Deployments API /// /// /// See the Collaborators API documentation for more details /// public IObservableDeploymentsClient Deployment { get; private set; } /// /// Client for GitHub's Repository Statistics API /// /// /// See the Statistics API documentation for more details /// public IObservableStatisticsClient Statistics { get; private set; } /// /// Client for GitHub's Repository Comments API. /// /// /// See the Repository Comments API documentation for more information. /// public IObservableRepositoryCommentsClient RepositoryComments { get; private set; } /// /// A client for GitHub's Repository Hooks API. /// /// See Hooks API documentation for more information. public IObservableRepositoryHooksClient Hooks { get; private set; } /// /// A client for GitHub's Repository Forks API. /// /// See Forks API documentation for more information. public IObservableRepositoryForksClient Forks { get; private set; } /// /// Client for GitHub's Repository Contents API. /// /// /// See the Repository Contents API documentation for more information. /// public IObservableRepositoryContentsClient Content { get; private set; } /// /// Client for GitHub's Repository Merging API /// /// /// See the Merging API documentation for more details /// public IObservableMergingClient Merging { get; private set; } /// /// Gets all the branches for the specified repository. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. /// All es of the repository public IObservable GetAllBranches(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.RepoBranches(owner, name); return _connection.GetAndFlattenAllPages(endpoint); } /// /// Gets all contributors for the specified repository. Does not include anonymous contributors. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// All contributors of the repository. public IObservable GetAllContributors(string owner, string name) { return GetAllContributors(owner, name, false); } /// /// Gets all contributors for the specified repository. With the option to include anonymous contributors. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// True if anonymous contributors should be included in result; Otherwise false /// All contributors of the repository. public IObservable GetAllContributors(string owner, string name, bool includeAnonymous) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.RepositoryContributors(owner, name); var parameters = new Dictionary(); if (includeAnonymous) parameters.Add("anon", "1"); return _connection.GetAndFlattenAllPages(endpoint, parameters); } /// /// Gets all languages for the specified repository. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// All languages used in the repository and the number of bytes of each language. public IObservable GetAllLanguages(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.RepositoryLanguages(owner, name); return _connection .GetAndFlattenAllPages>(endpoint) .Select(t => new RepositoryLanguage(t.Item1, t.Item2)); } /// /// Gets all teams for the specified repository. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// All s associated with the repository public IObservable GetAllTeams(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.RepositoryTeams(owner, name); return _connection.GetAndFlattenAllPages(endpoint); } /// /// Gets all tags for the specified repository. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// All of the repositorys tags. public IObservable GetAllTags(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.RepositoryTags(owner, name); return _connection.GetAndFlattenAllPages(endpoint); } /// /// Gets the specified branch. /// /// /// See the API documentation for more details /// /// The owner of the repository /// The name of the repository /// The name of the branch /// The specified public IObservable GetBranch(string owner, string repositoryName, string branchName) { return _client.GetBranch(owner, repositoryName, branchName).ToObservable(); } /// /// Updates the specified repository with the values given in /// /// The owner of the repository /// The name of the repository /// New values to update the repository with /// The updated public IObservable Edit(string owner, string name, RepositoryUpdate update) { return _client.Edit(owner, name, update).ToObservable(); } /// /// Compare two references in a repository /// /// The owner of the repository /// The name of the repository /// The reference to use as the base commit /// The reference to use as the head commit /// public IObservable Compare(string owner, string name, string @base, string head) { return _client.Commits.Compare(owner, name, @base, head).ToObservable(); } /// /// A client for GitHub's Repo Collaborators. /// /// /// See the Collaborators API documentation for more details /// public IObservableRepoCollaboratorsClient RepoCollaborators { get; private set; } /// /// Client for GitHub's Repository Commits API /// /// /// See the Commits API documentation for more details /// public IObservableRepositoryCommitsClient Commits { get; private set; } /// /// Client for managing pull requests. /// /// /// See the Pull Requests API documentation for more details /// public IObservablePullRequestsClient PullRequest { get; private set; } /// /// Client for managing deploy keys /// /// /// See the Repository Deploy Keys API documentation for more information. /// public IObservableRepositoryDeployKeysClient DeployKeys { get; private set; } } }