mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Add more methods to teams client
- Added functionality for AddMember, RemoveMember and GetRepositories - Unit tests missing for now.
This commit is contained in:
@@ -64,6 +64,30 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Delete(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to add to the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was added to the team; <see langword="false"/> otherwise.</returns>
|
||||
IObservable<bool> AddMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="User"/> from a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to remove from the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
|
||||
IObservable<bool> RemoveMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the user with the given <paramref name="login"/>
|
||||
/// is a member of the team with the given <paramref name="id"/>.
|
||||
@@ -72,5 +96,16 @@ namespace Octokit.Reactive
|
||||
/// <param name="login">The user to check.</param>
|
||||
/// <returns><see langword="true"/> if the user is a member of the team; <see langword="false"/> otherwise.</returns>
|
||||
IObservable<bool> IsMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Repository"/>(ies) associated with the given team.
|
||||
/// </summary>
|
||||
/// <param name="id">The team identifier</param>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-team-repos">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>A list of the team's <see cref="Repository"/>(ies).</returns>
|
||||
IObservable<Repository> GetRepositories(int id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,36 @@ namespace Octokit.Reactive
|
||||
return _client.Delete(id).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to add to the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was added to the team; <see langword="false"/> otherwise.</returns>
|
||||
public IObservable<bool> AddMember(int id, string login)
|
||||
{
|
||||
return _client.AddMember(id, login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="User"/> from a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to remove from the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
|
||||
public IObservable<bool> RemoveMember(int id, string login)
|
||||
{
|
||||
return _client.RemoveMember(id, login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the user with the given <paramref name="login"/>
|
||||
/// is a member of the team with the given <paramref name="id"/>.
|
||||
@@ -108,5 +138,18 @@ namespace Octokit.Reactive
|
||||
return _client.IsMember(id, login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Repository"/>(ies) associated with the given team.
|
||||
/// </summary>
|
||||
/// <param name="id">The team identifier</param>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-team-repos">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>A list of the team's <see cref="Repository"/>(ies).</returns>
|
||||
public IObservable<Repository> GetRepositories(int id)
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,30 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
Task Delete(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to add to the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was added to the team; <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> AddMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="User"/> from a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to remove from the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> RemoveMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the user with the given <paramref name="login"/>
|
||||
/// is a member of the team with the given <paramref name="id"/>.
|
||||
@@ -73,5 +97,16 @@ namespace Octokit
|
||||
/// <param name="login">The user to check.</param>
|
||||
/// <returns><see langword="true"/> if the user is a member of the team; <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> IsMember(int id, string login);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Repository"/>(ies) associated with the given team.
|
||||
/// </summary>
|
||||
/// <param name="id">The team identifier</param>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-team-repos">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>A list of the team's <see cref="Repository"/>(ies).</returns>
|
||||
Task<IReadOnlyList<Repository>> GetRepositories(int id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,62 @@ namespace Octokit
|
||||
return ApiConnection.Delete(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to add to the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was added to the team; <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> AddMember(int id, string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
|
||||
var endpoint = ApiUrls.TeamMember(id, login);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await ApiConnection.Connection.Put(endpoint);
|
||||
|
||||
return httpStatusCode == System.Net.HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="User"/> from a <see cref="Team"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-member">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="id">The team identifier.</param>
|
||||
/// <param name="login">The user to remove from the team.</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> RemoveMember(int id, string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
|
||||
var endpoint = ApiUrls.TeamMember(id, login);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await ApiConnection.Connection.Delete(endpoint);
|
||||
|
||||
return httpStatusCode == System.Net.HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the user with the given <paramref name="login"/>
|
||||
/// is a member of the team with the given <paramref name="id"/>.
|
||||
@@ -130,5 +186,21 @@ namespace Octokit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Repository"/>(ies) associated with the given team.
|
||||
/// </summary>
|
||||
/// <param name="id">The team identifier</param>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-team-repos">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>A list of the team's <see cref="Repository"/>(ies).</returns>
|
||||
public Task<IReadOnlyList<Repository>> GetRepositories(int id)
|
||||
{
|
||||
var endpoint = ApiUrls.TeamRepositories(id);
|
||||
|
||||
return ApiConnection.GetAll<Repository>(endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -954,6 +954,15 @@ namespace Octokit
|
||||
return "teams/{0}/members".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the <see cref="Uri"/> for listing team repositories
|
||||
/// </summary>
|
||||
/// <param name="id">The team id</param>
|
||||
public static Uri TeamRepositories(int id)
|
||||
{
|
||||
return "teams/{0}/repos".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the <see cref="Uri"/> for teams
|
||||
/// use for update or deleting a team
|
||||
|
||||
Reference in New Issue
Block a user