mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* Fixes ids for Releases, Collaborators, and Contributors * updates the interface for releases * update the obverable release client * updates ids from int to long based on GH database schema * converts a test condition to use the proper type * updates generated paging and observable classes
713 lines
32 KiB
C#
713 lines
32 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's Organization Teams API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Organization Teams API documentation</a> for more information.
|
|
/// </remarks>
|
|
public class TeamsClient : ApiClient, ITeamsClient
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new GitHub Orgs Team API client.
|
|
/// </summary>
|
|
/// <param name="apiConnection">An API connection.</param>
|
|
public TeamsClient(IApiConnection apiConnection)
|
|
: base(apiConnection)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a single <see cref="Team"/> by identifier.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#get-team
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier.</param>
|
|
/// <returns>The <see cref="Team"/> with the given identifier.</returns>
|
|
[ManualRoute("GET", "/teams/{team_id}")]
|
|
public Task<Team> Get(long teamId)
|
|
{
|
|
var endpoint = ApiUrls.Teams(teamId);
|
|
|
|
return ApiConnection.Get<Team>(endpoint);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all <see cref="Team" />s for the current org.
|
|
/// </summary>
|
|
/// <param name="org">Organization to list teams of.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
|
|
[ManualRoute("GET", "/orgs/{org}/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAll(string org)
|
|
{
|
|
return GetAll(org, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all <see cref="Team" />s for the current org.
|
|
/// </summary>
|
|
/// <param name="org">Organization to list teams of.</param>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
|
|
[ManualRoute("GET", "/orgs/{org}/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAll(string org, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.OrganizationTeams(org);
|
|
return ApiConnection.GetAll<Team>(endpoint, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all <see cref="Team" />s for the current user.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
|
|
[ManualRoute("GET", "/user/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAllForCurrent()
|
|
{
|
|
return GetAllForCurrent(ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all <see cref="Team" />s for the current user.
|
|
/// </summary>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
|
|
[ManualRoute("GET", "/user/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAllForCurrent(ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.UserTeams();
|
|
|
|
return ApiConnection.GetAll<Team>(endpoint, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all child teams of the given team.
|
|
/// </summary>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-child-teams
|
|
/// </remarks>
|
|
[ManualRoute("GET", "/teams{id}/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAllChildTeams(long teamId)
|
|
{
|
|
return GetAllChildTeams(teamId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all child teams of the given team.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-child-teams
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
[ManualRoute("GET", "/teams{id}/teams")]
|
|
public Task<IReadOnlyList<Team>> GetAllChildTeams(long teamId, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.TeamChildTeams(teamId);
|
|
|
|
return ApiConnection.GetAll<Team>(endpoint, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all members of the given team.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-team-members
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
[ManualRoute("GET", "/teams{id}/members")]
|
|
public Task<IReadOnlyList<User>> GetAllMembers(long teamId)
|
|
{
|
|
return GetAllMembers(teamId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all members of the given team.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-team-members
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
[ManualRoute("GET", "/teams{id}/members")]
|
|
public Task<IReadOnlyList<User>> GetAllMembers(long teamId, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.TeamMembers(teamId);
|
|
|
|
return ApiConnection.GetAll<User>(endpoint, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all members with the specified role in the given team of the given role.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-team-members
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <param name="request">The request filter</param>
|
|
[ManualRoute("GET", "/teams{id}/members")]
|
|
public Task<IReadOnlyList<User>> GetAllMembers(long teamId, TeamMembersRequest request)
|
|
{
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return GetAllMembers(teamId, request, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all members with the specified role in the given team of the given role.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/orgs/teams/#list-team-members
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <param name="request">The request filter</param>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
[ManualRoute("GET", "/teams{id}/members")]
|
|
public Task<IReadOnlyList<User>> GetAllMembers(long teamId, TeamMembersRequest request, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.TeamMembers(teamId);
|
|
|
|
return ApiConnection.GetAll<User>(endpoint, request.ToParametersDictionary(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets whether the user with the given <paramref name="login"/>
|
|
/// is a member of the team with the given <paramref name="teamId"/>.
|
|
/// A <see cref="NotFoundException"/> is thrown if the user is not a member.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/orgs/teams/#get-team-membership">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="teamId">The team to check.</param>
|
|
/// <param name="login">The user to check.</param>
|
|
[ManualRoute("GET", "/teams/{team_id}/memberships/{username}")]
|
|
public Task<TeamMembershipDetails> GetMembershipDetails(long teamId, string login)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(login, nameof(login));
|
|
|
|
var endpoint = ApiUrls.TeamMember(teamId, login);
|
|
|
|
return ApiConnection.Get<TeamMembershipDetails>(endpoint);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns newly created <see cref="Team" /> for the current org.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>Newly created <see cref="Team"/></returns>
|
|
[ManualRoute("POST", "/orgs/{org}/teams")]
|
|
public Task<Team> Create(string org, NewTeam team)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNull(team, nameof(team));
|
|
|
|
var endpoint = ApiUrls.OrganizationTeams(org);
|
|
return ApiConnection.Post<Team>(endpoint, team);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates a team
|
|
/// To edit a team, the authenticated user must either be an organization owner or a team maintainer
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#update-a-team">API documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <returns>updated <see cref="Team" /> for the current org</returns>
|
|
[ManualRoute("PATCH", "/orgs/{org}/teams/{team_slug}")]
|
|
public Task<Team> Update(string org, string teamId, UpdateTeam team)
|
|
{
|
|
Ensure.ArgumentNotNull(org, nameof(org));
|
|
Ensure.ArgumentNotNull(teamId, nameof(teamId));
|
|
Ensure.ArgumentNotNull(team, nameof(team));
|
|
|
|
var endpoint = ApiUrls.TeamsByOrganizationAndSlug(org, teamId);
|
|
return ApiConnection.Patch<Team>(endpoint, team);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns updated <see cref="Team" /> for the current org.
|
|
/// This endpoint route is deprecated and will be removed from the Teams API.
|
|
/// We recommend migrating your existing code to use the new Update a team endpoint.
|
|
/// <see cref="Update(string, string, UpdateTeam)"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#update-a-team-legacy">API documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>Updated <see cref="Team"/></returns>
|
|
[ManualRoute("PATCH", "/teams/{team_id}")]
|
|
public Task<Team> Update(long teamId, UpdateTeam team)
|
|
{
|
|
Ensure.ArgumentNotNull(team, nameof(team));
|
|
|
|
var endpoint = ApiUrls.Teams(teamId);
|
|
return ApiConnection.Patch<Team>(endpoint, team);
|
|
}
|
|
|
|
/// <summary>
|
|
/// To delete a team, the authenticated user must be an organization owner or team maintainer.
|
|
/// If you are an organization owner, deleting a parent team will delete all of its child teams as well.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#delete-a-team">API documentation</a>
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("DELETE", "/orgs/{org}/teams/{team_slug}")]
|
|
public Task Delete(string org, string teamId)
|
|
{
|
|
Ensure.ArgumentNotNull(org, nameof(org));
|
|
Ensure.ArgumentNotNull(teamId, nameof(teamId));
|
|
|
|
var endpoint = ApiUrls.TeamsByOrganizationAndSlug(org, teamId);
|
|
|
|
return ApiConnection.Delete(endpoint);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete a team - must have owner permissions to do this
|
|
/// This endpoint route is deprecated and will be removed from the Teams API.
|
|
/// We recommend migrating your existing code to use the new Delete a team endpoint.
|
|
/// <see cref="Delete(string, string)"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#delete-a-team-legacy">API documentation</a>
|
|
/// </remarks>
|
|
/// <param name="teamId">The unique identifier of the team.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("DELETE", "/teams/{team_id}")]
|
|
public Task Delete(long teamId)
|
|
{
|
|
var endpoint = ApiUrls.Teams(teamId);
|
|
|
|
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-or-update-team-membership">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier.</param>
|
|
/// <param name="login">The user to add to the team.</param>
|
|
/// <param name="request">Additional parameters for the request</param>
|
|
[ManualRoute("PUT", "/teams/{team_id}/memberships/{username}")]
|
|
public Task<TeamMembershipDetails> AddOrEditMembership(long teamId, string login, UpdateTeamMembership request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(login, nameof(login));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
var endpoint = ApiUrls.TeamMember(teamId, login);
|
|
|
|
return ApiConnection.Put<TeamMembershipDetails>(endpoint, request);
|
|
}
|
|
|
|
/// <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="teamId">The team identifier.</param>
|
|
/// <param name="login">The user to remove from the team.</param>
|
|
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
|
|
[ManualRoute("DELETE", "/teams/{team_id}/memberships/{username}")]
|
|
public async Task<bool> RemoveMembership(long teamId, string login)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(login, nameof(login));
|
|
|
|
var endpoint = ApiUrls.TeamMember(teamId, login);
|
|
|
|
try
|
|
{
|
|
var httpStatusCode = await ApiConnection.Connection.Delete(endpoint).ConfigureAwait(false);
|
|
|
|
return httpStatusCode == HttpStatusCode.NoContent;
|
|
}
|
|
catch (NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all team's repositories.
|
|
/// </summary>
|
|
/// <param name="teamId">Team Id.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>The team's repositories</returns>
|
|
[ManualRoute("GET", "/teams/{team_id}/repos")]
|
|
public Task<IReadOnlyList<Repository>> GetAllRepositories(long teamId)
|
|
{
|
|
return GetAllRepositories(teamId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all team's repositories.
|
|
/// </summary>
|
|
/// <param name="teamId">Team Id.</param>
|
|
/// <param name="options">Options to change API behaviour.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns>The team's repositories</returns>
|
|
[ManualRoute("GET", "/teams/{team_id}/repos")]
|
|
public Task<IReadOnlyList<Repository>> GetAllRepositories(long teamId, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, nameof(options));
|
|
|
|
var endpoint = ApiUrls.TeamRepositories(teamId);
|
|
|
|
return ApiConnection.GetAll<Repository>(endpoint, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add or update team repository permissions (Legacy)
|
|
/// Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API.
|
|
/// We recommend migrating your existing code to use the new "Add or update team repository permissions" endpoint.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")]
|
|
public async Task<bool> AddRepository(long teamId, string organization, string repoName)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
|
|
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
|
|
|
|
// TODO: I am very suspicious of this due to the documentation
|
|
// https://developer.github.com/v3/teams/#add-or-update-team-repository
|
|
//
|
|
// Recommended:
|
|
// PUT /orgs/:org/teams/:team_slug/repos/:owner/:repo
|
|
//
|
|
// or
|
|
//
|
|
// PUT /organizations/:org_id/team/:team_id/repos/:owner/:repo
|
|
//
|
|
// Likely will require a breaking change
|
|
|
|
var endpoint = ApiUrls.TeamRepository(teamId, organization, repoName);
|
|
|
|
try
|
|
{
|
|
var httpStatusCode = await ApiConnection.Connection.Put(endpoint).ConfigureAwait(false);
|
|
return httpStatusCode == HttpStatusCode.NoContent;
|
|
}
|
|
catch (NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add or update team repository permissions (Legacy)
|
|
/// Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API.
|
|
/// We recommend migrating your existing code to use the new "Add or update team repository permissions" endpoint.
|
|
/// </summary>
|
|
/// <param name="teamId">The team identifier.</param>
|
|
/// <param name="organization">Org to associate the repo with.</param>
|
|
/// <param name="repoName">Name of the repo.</param>
|
|
/// <param name="permission">The permission to grant the team on this repository.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")]
|
|
public async Task<bool> AddRepository(long teamId, string organization, string repoName, RepositoryPermissionRequest permission)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
|
|
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
|
|
|
|
// TODO: I am very suspicious of this due to the documentation
|
|
// https://developer.github.com/v3/teams/#add-or-update-team-repository
|
|
//
|
|
// Recommended:
|
|
// PUT /orgs/:org/teams/:team_slug/repos/:owner/:repo
|
|
//
|
|
// or
|
|
//
|
|
// PUT /organizations/:org_id/team/:team_id/repos/:owner/:repo
|
|
//
|
|
// Likely will require a breaking change
|
|
|
|
var endpoint = ApiUrls.TeamRepository(teamId, organization, repoName);
|
|
|
|
try
|
|
{
|
|
var httpStatusCode = await ApiConnection.Connection.Put<HttpStatusCode>(endpoint, permission).ConfigureAwait(false);
|
|
return httpStatusCode.HttpResponse.StatusCode == HttpStatusCode.NoContent;
|
|
}
|
|
catch (NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a repository from a team (Legacy)
|
|
/// Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API.
|
|
/// We recommend migrating your existing code to use the new Remove a repository from a team endpoint.
|
|
/// </summary>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("DELETE", "/teams/{team_id}/repos/{owner}/{repo}")]
|
|
public async Task<bool> RemoveRepository(long teamId, string organization, string repoName)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
|
|
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
|
|
|
|
// TODO: I am very suspicious of this due to the documentation
|
|
// https://developer.github.com/v3/teams/#remove-team-repository
|
|
//
|
|
// Recommended:
|
|
// DELETE /orgs/:org/teams/:team_slug/repos/:owner/:repo
|
|
//
|
|
// or
|
|
//
|
|
// DELETE /organizations/:org_id/team/:team_id/repos/:owner/:repo
|
|
//
|
|
// Likely will require a breaking change
|
|
|
|
var endpoint = ApiUrls.TeamRepository(teamId, organization, repoName);
|
|
|
|
try
|
|
{
|
|
var httpStatusCode = await ApiConnection.Connection.Delete(endpoint).ConfigureAwait(false);
|
|
|
|
return httpStatusCode == HttpStatusCode.NoContent;
|
|
}
|
|
catch (NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets whether or not the given repository is managed by the given team.
|
|
/// </summary>
|
|
/// <param name="teamId">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>
|
|
[ManualRoute("GET", "/teams/{team_id}/repos/{owner}/{name}")]
|
|
public async Task<bool> IsRepositoryManagedByTeam(long teamId, string owner, string repo)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
|
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
|
|
|
|
var endpoint = ApiUrls.TeamRepository(teamId, owner, repo);
|
|
|
|
try
|
|
{
|
|
var response = await ApiConnection.Connection.Get<string>(endpoint, null, AcceptHeaders.StableVersionJson).ConfigureAwait(false);
|
|
return response.HttpResponse.StatusCode == HttpStatusCode.NoContent;
|
|
}
|
|
catch (NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// List all pending invitations for the given team.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <returns></returns>
|
|
[ManualRoute("GET", "/teams/{team_id}/invitations")]
|
|
public Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllPendingInvitations(long teamId)
|
|
{
|
|
Ensure.ArgumentNotNull(teamId, nameof(teamId));
|
|
|
|
return GetAllPendingInvitations(teamId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// List all pending invitations for the given team.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="teamId">The team identifier</param>
|
|
/// <param name="options">Options to change API behaviour</param>
|
|
/// <returns></returns>
|
|
[ManualRoute("GET", "/teams/{team_id}/invitations")]
|
|
public Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllPendingInvitations(long teamId, ApiOptions options)
|
|
{
|
|
return ApiConnection.GetAll<OrganizationMembershipInvitation>(ApiUrls.TeamPendingInvitations(teamId), null, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether a team has admin, push, maintain, triage, or pull permission for a repository.
|
|
/// Repositories inherited through a parent team will also be checked.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#check-team-permissions-for-a-repository">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <param name="owner">The account owner of the repository. The name is not case sensitive.</param>
|
|
/// <param name="repo">The name of the repository. The name is not case sensitive.</param>
|
|
/// <returns></returns>
|
|
[ManualRoute("GET", "/orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}")]
|
|
public async Task<bool> CheckTeamPermissionsForARepository(string org, string teamId, string owner, string repo)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNullOrEmptyString(teamId, nameof(teamId));
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
|
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
|
|
|
|
var endpoint = ApiUrls.TeamPermissionsForARepository(org, teamId, owner, repo);
|
|
|
|
try
|
|
{
|
|
var response = await ApiConnection.Get<TeamRepository>(endpoint);
|
|
return response == null;
|
|
}
|
|
catch(NotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether a team has admin, push, maintain, triage, or pull permission for a repository.
|
|
/// Repositories inherited through a parent team will also be checked.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#check-team-permissions-for-a-repository">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <param name="owner">The account owner of the repository. The name is not case sensitive.</param>
|
|
/// <param name="repo">The name of the repository. The name is not case sensitive.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("GET", "/orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}")]
|
|
public Task<TeamRepository> CheckTeamPermissionsForARepositoryWithCustomAcceptHeader(string org, string teamId, string owner, string repo)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNullOrEmptyString(teamId, nameof(teamId));
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
|
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
|
|
|
|
var endpoint = ApiUrls.TeamPermissionsForARepository(org, teamId, owner, repo);
|
|
|
|
return ApiConnection.Get<TeamRepository>(endpoint, null, AcceptHeaders.RepositoryContentMediaType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add or update team repository permissions
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#add-or-update-team-repository-permissions">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <param name="owner">The account owner of the repository. The name is not case sensitive.</param>
|
|
/// <param name="repo">The name of the repository. The name is not case sensitive.</param>
|
|
/// <param name="permission">
|
|
/// The permission to grant the team on this repository. We accept the following permissions to be set:
|
|
/// pull, triage, push, maintain, admin and you can also specify a custom repository role name, if the
|
|
/// owning organization has defined any. If no permission is specified, the team's permission attribute
|
|
/// will be used to determine what permission to grant the team on this repository
|
|
/// </param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("PUT", "/orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}")]
|
|
public Task AddOrUpdateTeamRepositoryPermissions(string org, string teamId, string owner, string repo, string permission)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNullOrEmptyString(teamId, nameof(teamId));
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
|
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
|
|
|
|
var endpoint = ApiUrls.TeamPermissionsForARepository(org, teamId, owner, repo);
|
|
|
|
return ApiConnection.Put(endpoint, new { permission });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a repository from a team
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#remove-a-repository-from-a-team">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <param name="owner">The account owner of the repository. The name is not case sensitive.</param>
|
|
/// <param name="repo">The name of the repository. The name is not case sensitive.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <returns></returns>
|
|
[ManualRoute("DELETE", "/orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}")]
|
|
public Task RemoveRepositoryFromATeam(string org, string teamId, string owner, string repo)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNullOrEmptyString(teamId, nameof(teamId));
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
|
Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo));
|
|
|
|
var endpoint = ApiUrls.TeamPermissionsForARepository(org, teamId, owner, repo);
|
|
|
|
return ApiConnection.Delete(endpoint);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a team by slug name
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name">API Documentation</a>
|
|
/// for more information.
|
|
/// </remarks>
|
|
/// <param name="org">The organization name. The name is not case sensitive.</param>
|
|
/// <param name="teamId">The slug of the team name.</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
/// <exception cref="NotFoundException">Thrown when the team wasn't found</exception>
|
|
/// <returns>A <see cref="Team"/> instance if found, otherwise a <see cref="NotFoundException"/></returns>
|
|
[ManualRoute("GET", "/orgs/{org}/teams/{teamId}")]
|
|
public Task<Team> GetByName(string org, string teamId)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
|
Ensure.ArgumentNotNullOrEmptyString(teamId, nameof(teamId));
|
|
|
|
var endpoint = ApiUrls.TeamsByOrganizationAndSlug(org, teamId);
|
|
return ApiConnection.Get<Team>(endpoint);
|
|
}
|
|
}
|
|
}
|