using System;
using System.Linq;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Git Trees API.
///
///
/// See the Git Trees API documentation for more information.
///
public class TreesClient : ApiClient, ITreesClient
{
///
/// Instantiates a new GitHub Git Trees API client.
///
/// An API connection
public TreesClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
///
/// Gets a Tree Response for a given SHA.
///
///
/// http://developer.github.com/v3/git/trees/#get-a-tree
///
/// The owner of the repository
/// The name of the repository
/// The SHA that references the tree
public Task Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get(ApiUrls.Tree(owner, name, reference));
}
///
/// Gets a Tree Response for a given SHA.
///
///
/// http://developer.github.com/v3/git/trees/#get-a-tree
///
/// The ID of the repository
/// The SHA that references the tree
public Task Get(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get(ApiUrls.Tree(repositoryId, reference));
}
///
/// Gets a Tree Response for a given SHA.
///
///
/// https://developer.github.com/v3/git/trees/#get-a-tree-recursively
///
/// The owner of the repository
/// The name of the repository
/// The SHA that references the tree
public Task GetRecursive(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get(ApiUrls.TreeRecursive(owner, name, reference));
}
///
/// Gets a Tree Response for a given SHA.
///
///
/// https://developer.github.com/v3/git/trees/#get-a-tree-recursively
///
/// The ID of the repository
/// The SHA that references the tree
public Task GetRecursive(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get(ApiUrls.TreeRecursive(repositoryId, reference));
}
///
/// Creates a new Tree in the specified repo
///
///
/// http://developer.github.com/v3/git/trees/#create-a-tree
///
/// The owner of the repository
/// The name of the repository
/// The value of the new tree
public Task Create(string owner, string name, NewTree newTree)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newTree, "newTree");
if (newTree.Tree.Any(t => string.IsNullOrWhiteSpace(t.Mode)))
{
throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
}
return ApiConnection.Post(ApiUrls.Tree(owner, name), newTree);
}
///
/// Creates a new Tree in the specified repo
///
///
/// http://developer.github.com/v3/git/trees/#create-a-tree
///
/// The ID of the repository
/// The value of the new tree
public Task Create(int repositoryId, NewTree newTree)
{
Ensure.ArgumentNotNull(newTree, "newTree");
if (newTree.Tree.Any(t => string.IsNullOrWhiteSpace(t.Mode)))
{
throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
}
return ApiConnection.Post(ApiUrls.Tree(repositoryId), newTree);
}
}
}