Skip to content

Commit

Permalink
update models with updated permission enum (#2633)
Browse files Browse the repository at this point in the history
* update models with updated permission enum

* add suppress message attribute

* update integration tests

* refactor: new and legacy update teams endpint

* refactor: add new delete team endpoint

* use TeamPermission on NewTeam

* use updated delete on team context dispose

* add permission enum for team response object

* refactor: remove legacy suffix from method names

* introduce permissions object on Team

* refactor: rename enum to TeamRepositoryPermission

* fix formatting

* change Permission to string to match api specs

* add TeamRepository

* add CheckTeamPermission endpoint support

* fix convention tests

* update comments on TeamRepository props

* add two new endpoints in TeamsClient

* refactor: rename ApiUrl for TeamPermission

* fix test

* implement methods for new endpoints

* add the integration tests

* fix spelling

* update comments

* refactor: rename method name

* fix: add end tag for remarks

* refactor: remove unused method param

* fix docstring comment

* the unit tests are in finally

* add docs for teams api

* split CheckTeamPermissions into two methods

* Update ObservableTeamsClientTests.cs based on review

Co-authored-by: Keegan Campbell <[email protected]>

* add cref to legacy update and delete endpoints

* remove editorconfig file

* Update Octokit.Tests/Clients/TeamsClientTests.cs

Co-authored-by: Keegan Campbell <[email protected]>

* remove unused line

* rename variable based on review

* rename prop to match constructor param

* add comment to explain TeamPermission enum values on update

Co-authored-by: notauserx <[email protected]>
Co-authored-by: Keegan Campbell <[email protected]>
  • Loading branch information
3 people authored Jan 20, 2023
1 parent bf66785 commit 891015c
Show file tree
Hide file tree
Showing 24 changed files with 2,052 additions and 37 deletions.
107 changes: 106 additions & 1 deletion Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,54 @@ public interface IObservableTeamsClient
/// <returns>Newly created <see cref="Team"/></returns>
IObservable<Team> Create(string org, NewTeam 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>
IObservable<Team> Update(string org, string teamSlug, UpdateTeam 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>
IObservable<Team> Update(int id, UpdateTeam team);

/// <summary>
/// Delete a team - must have owner permissions to this
/// 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="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
IObservable<Unit> Delete(string org, string teamSlug);

/// <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="id">The unique identifier of the team.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
IObservable<Unit> Delete(int id);
Expand Down Expand Up @@ -257,5 +295,72 @@ public interface IObservableTeamsClient
/// <param name="options">Options to change API behaviour.</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id, ApiOptions 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="teamSlug">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>
IObservable<bool> CheckTeamPermissionsForARepository(string org, string teamSlug, string owner, string repo);

/// <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="teamSlug">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>
IObservable<TeamRepository> CheckTeamPermissionsForARepositoryWithCustomAcceptHeader(string org, string teamSlug, string owner, string repo);

/// <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="teamSlug">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>
IObservable<Unit> AddOrUpdateTeamRepositoryPermissions(string org, string teamSlug, string owner, string repo, string 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="teamSlug">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>
IObservable<Unit> RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo);
}
}
134 changes: 133 additions & 1 deletion Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,34 @@ public IObservable<Team> Create(string org, NewTeam team)
return _client.Create(org, team).ToObservable();
}

/// <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>
public IObservable<Team> Update(string org, string teamSlug, UpdateTeam team)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(teamSlug, nameof(teamSlug));
Ensure.ArgumentNotNull(team, nameof(team));

return _client.Update(org, teamSlug, team).ToObservable();
}

/// <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>
public IObservable<Team> Update(int id, UpdateTeam team)
Expand All @@ -206,8 +231,34 @@ public IObservable<Team> Update(int id, UpdateTeam team)
}

/// <summary>
/// Delete a team - must have owner permissions to this
/// 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="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<Unit> Delete(string org, string teamSlug)
{
Ensure.ArgumentNotNull(org, nameof(org));
Ensure.ArgumentNotNull(teamSlug, nameof(teamSlug));

return _client.Delete(org, teamSlug).ToObservable();
}

/// <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="id">The unique identifier of the team.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<Unit> Delete(int id)
Expand Down Expand Up @@ -391,5 +442,86 @@ public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(in

return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.TeamPendingInvitations(id), 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="teamSlug">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>
public IObservable<bool> CheckTeamPermissionsForARepository(string org, string teamSlug, string owner, string repo)
{
return _client.CheckTeamPermissionsForARepository(org, teamSlug, owner, repo).ToObservable();
}

/// <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="teamSlug">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>
public IObservable<TeamRepository> CheckTeamPermissionsForARepositoryWithCustomAcceptHeader(string org, string teamSlug, string owner, string repo)
{
return _client.CheckTeamPermissionsForARepositoryWithCustomAcceptHeader(org, teamSlug, owner, repo).ToObservable();
}

/// <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="teamSlug">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 IObservable<Unit> AddOrUpdateTeamRepositoryPermissions(string org, string teamSlug, string owner, string repo, string permission)
{
return _client.AddOrUpdateTeamRepositoryPermissions(org, teamSlug, owner, repo, permission).ToObservable();
}

/// <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="teamSlug">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 IObservable<Unit> RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo)
{
return _client.RemoveRepositoryFromATeam(org, teamSlug, owner, repo).ToObservable();
}
}
}
3 changes: 2 additions & 1 deletion Octokit.Tests.Conventions/PreviewsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void NoStalePreviews()
// https://developer.github.com/v3/repos/commits/#get-a-single-commit
"application/vnd.github.v3.sha",
// https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
"application/vnd.github.v3.star+json"
"application/vnd.github.v3.star+json",
"application/vnd.github.v3.repository+json"
};

var validHeaders = defaultHeaders.Concat(previewAcceptHeaders);
Expand Down
Loading

0 comments on commit 891015c

Please sign in to comment.