using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableIssuesLabelsClient : IObservableIssuesLabelsClient
{
readonly IIssuesLabelsClient _client;
readonly IConnection _connection;
public ObservableIssuesLabelsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_connection = client.Connection;
_client = client.Issue.Labels;
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The list of labels
public IObservable GetForIssue(string owner, string repo, int number)
{
return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(owner, repo, number));
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The list of labels
public IObservable GetForRepository(string owner, string repo)
{
return _connection.GetAndFlattenAllPages(ApiUrls.Labels(owner, repo));
}
///
/// Gets a single Label by name.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
/// The label
public IObservable Get(string owner, string repo, string name)
{
return _client.Get(owner, repo, name).ToObservable();
}
///
/// Deletes a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
///
public IObservable Delete(string owner, string repo, string name)
{
return _client.Delete(owner, repo, name).ToObservable();
}
///
/// Creates a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The data for the label to be created
/// The created label
public IObservable Create(string owner, string repo, NewLabel newLabel)
{
return _client.Create(owner, repo, newLabel).ToObservable();
}
///
/// Updates a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
/// The data for the label to be updated
/// The updated label '
public IObservable Update(string owner, string repo, string name, LabelUpdate labelUpdate)
{
return _client.Update(owner, repo, name, labelUpdate).ToObservable();
}
///
/// Adds a label to an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The names of the labels to add
///
public IObservable AddToIssue(string owner, string repo, int number, string[] labels)
{
return _client.AddToIssue(owner, repo, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: POST is not compatible with GetAndFlattenPages
}
///
/// Removes a label from an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The name of the label to remove
///
public IObservable RemoveFromIssue(string owner, string repo, int number, string label)
{
return _client.RemoveFromIssue(owner, repo, number, label).ToObservable();
}
///
/// Replaces all labels on the specified issues with the provided labels
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The names of the labels to set
///
public IObservable ReplaceAllForIssue(string owner, string repo, int number, string[] labels)
{
return _client.ReplaceAllForIssue(owner, repo, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: PUT is not compatible with GetAndFlattenPages
}
///
/// Removes all labels from an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
///
public IObservable RemoveAllFromIssue(string owner, string repo, int number)
{
return _client.RemoveAllFromIssue(owner, repo, number).ToObservable();
}
///
/// Gets labels for every issue in a milestone
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the milestone
///
public IObservable GetForMilestone(string owner, string repo, int number)
{
return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(owner, repo, number));
}
}
}