Added moar methods to teams client

In both the ObservableTeamsClient and TeamsClient, added:

- AddRepository
- RemoveRepository
- IsRepositoryManagedByTeam
This commit is contained in:
Jason Kanaris
2014-07-15 23:41:23 -04:00
parent cd8f54272e
commit ed85234ce2
2 changed files with 133 additions and 0 deletions
@@ -143,5 +143,51 @@ namespace Octokit.Reactive
{
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id));
}
/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="org">Org to associate the repo with.</param>
/// <param name="repo">Name of the repo.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> AddRepository(int id, string org, string repo)
{
return _client.AddRepository(id, org, repo).ToObservable();
}
/// <summary>
/// Removes a <see cref="Repository"/> from a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="owner">Owner of the org the team is associated with.</param>
/// <param name="repo">Name of the repo.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was removed from the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> RemoveRepository(int id, string owner, string repo)
{
return _client.RemoveRepository(id, owner, repo).ToObservable();
}
/// <summary>
/// Gets whether or not the given repository is managed by the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <param name="owner">Owner of the org the team is associated with.</param>
/// <param name="repo">Name of the repo.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#get-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository is managed by the given team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> IsRepositoryManagedByTeam(int id, string owner, string repo)
{
return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable();
}
}
}
+87
View File
@@ -195,5 +195,92 @@ namespace Octokit
return ApiConnection.GetAll<Repository>(endpoint);
}
/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="org">Org to associate the repo with.</param>
/// <param name="repo">Name of the repo.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public async Task<bool> AddRepository(int id, string org, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
var endpoint = ApiUrls.TeamRepository(id, org, repo);
try
{
var httpStatusCode = await ApiConnection.Connection.Put(endpoint);
return httpStatusCode == System.Net.HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
/// <summary>
/// Removes a <see cref="Repository"/> from a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="owner">Owner of the org the team is associated with.</param>
/// <param name="repo">Name of the repo.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was removed from the team; <see langword="false"/> otherwise.</returns>
public async Task<bool> RemoveRepository(int id, string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
var endpoint = ApiUrls.TeamRepository(id, owner, repo);
try
{
var httpStatusCode = await ApiConnection.Connection.Delete(endpoint);
return httpStatusCode == System.Net.HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
/// <summary>
/// Gets whether or not the given repository is managed by the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <param name="owner">Owner of the org the team is associated with.</param>
/// <param name="repo">Name of the repo.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#get-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository is managed by the given team; <see langword="false"/> otherwise.</returns>
public async Task<bool> IsRepositoryManagedByTeam(int id, string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
var endpoint = ApiUrls.TeamRepository(id, owner, repo);
try
{
var response = await ApiConnection.Connection.GetResponse<string>(endpoint);
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
}
}