mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
161 lines
7.0 KiB
C#
161 lines
7.0 KiB
C#
using System;
|
|
using System.Reactive;
|
|
using System.Reactive.Threading.Tasks;
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new repository for the current user.
|
|
/// </summary>
|
|
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
|
|
/// <returns>An <see cref="IObservable{Repository}"/> instance for the created repository</returns>
|
|
public IObservable<Repository> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new repository in the specified organization.
|
|
/// </summary>
|
|
/// <param name="organizationLogin">The login of the organization in which to create the repostiory</param>
|
|
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
|
|
/// <returns>An <see cref="IObservable{Repository}"/> instance for the created repository</returns>
|
|
public IObservable<Repository> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a repository for the specified owner and name.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <remarks>Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.</remarks>
|
|
/// <returns>An <see cref="IObservable{Unit}"/> for the operation</returns>
|
|
public IObservable<Unit> Delete(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return _client.Delete(owner, name).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <returns>A <see cref="Repository"/></returns>
|
|
public IObservable<Repository> Get(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return _client.Get(owner, name).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves every <see cref="Repository"/> that belongs to the current user.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The default page size on GitHub.com is 30.
|
|
/// </remarks>
|
|
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
|
|
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
|
|
public IObservable<Repository> GetAllForCurrent()
|
|
{
|
|
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Repositories());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves every <see cref="Repository"/> that belongs to the specified user.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The default page size on GitHub.com is 30.
|
|
/// </remarks>
|
|
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
|
|
public IObservable<Repository> GetAllForUser(string login)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
|
|
|
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Repositories(login));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves every <see cref="Repository"/> that belongs to the specified organization.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The default page size on GitHub.com is 30.
|
|
/// </remarks>
|
|
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
|
|
public IObservable<Repository> GetAllForOrg(string organization)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
|
|
|
|
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.OrganizationRepositories(organization));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the HTML rendered README.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <returns></returns>
|
|
public IObservable<Readme> GetReadme(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return _client.GetReadme(owner, name).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns just the HTML portion of the README without the surrounding HTML document.
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <returns></returns>
|
|
public IObservable<string> GetReadmeHtml(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return _client.GetReadmeHtml(owner, name).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// A client for GitHub's Commit Status API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/statuses/">Commit Status API documentation</a> for more
|
|
/// details. Also check out the <a href="https://github.com/blog/1227-commit-status-api">blog post</a>
|
|
/// that announced this feature.
|
|
/// </remarks>
|
|
public IObservableCommitStatusClient CommitStatus { get; private set; }
|
|
}
|
|
}
|