Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update models with updated permission enum #2633

Merged
merged 47 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
409c586
update models with updated permission enum
notauserx Dec 5, 2022
ce9df33
add suppress message attribute
notauserx Dec 6, 2022
0eed292
update integration tests
notauserx Dec 6, 2022
9b6164a
refactor: new and legacy update teams endpint
notauserx Dec 6, 2022
1ad585e
refactor: add new delete team endpoint
notauserx Dec 6, 2022
9c45e17
Merge branch 'main' into update-team-permissions-enums
kfcampbell Dec 6, 2022
3a3dbdd
use TeamPermission on NewTeam
notauserx Dec 7, 2022
754bece
use updated delete on team context dispose
notauserx Dec 7, 2022
82593bd
Merge branch 'update-team-permissions-enums' of https://github.com/no…
notauserx Dec 7, 2022
b354217
add permission enum for team response object
notauserx Dec 7, 2022
a976530
refactor: remove legacy suffix from method names
notauserx Dec 7, 2022
c22a76d
introduce permissions object on Team
notauserx Dec 7, 2022
c5f0cf4
refactor: rename enum to TeamRepositoryPermission
notauserx Dec 7, 2022
3b16170
fix formatting
notauserx Dec 7, 2022
76cfbff
change Permission to string to match api specs
notauserx Dec 8, 2022
d05c0cd
add TeamRepository
notauserx Dec 8, 2022
baee285
add CheckTeamPermission endpoint support
notauserx Dec 9, 2022
1c6313d
fix convention tests
notauserx Dec 9, 2022
a6be98d
update comments on TeamRepository props
notauserx Dec 9, 2022
d6f345b
add two new endpoints in TeamsClient
notauserx Dec 9, 2022
c01bb60
refactor: rename ApiUrl for TeamPermission
notauserx Dec 9, 2022
d0f4f0c
fix test
notauserx Dec 9, 2022
cba9141
implement methods for new endpoints
notauserx Dec 9, 2022
426abdf
add the integration tests
notauserx Dec 9, 2022
19dd149
fix spelling
notauserx Dec 9, 2022
38b0881
update comments
notauserx Dec 9, 2022
de786e0
refactor: rename method name
notauserx Dec 9, 2022
a76d81a
Merge branch 'main' into update-team-permissions-enums
notauserx Dec 9, 2022
e38ec35
Merge branch 'update-team-permissions-enums' of https://github.com/no…
notauserx Dec 9, 2022
d194b68
fix: add end tag for remarks
notauserx Dec 9, 2022
28a36d6
refactor: remove unused method param
notauserx Dec 9, 2022
662b40a
fix docstring comment
notauserx Dec 11, 2022
2a6497f
the unit tests are in finally
notauserx Dec 11, 2022
d40e981
add docs for teams api
notauserx Dec 11, 2022
f98829f
Merge branch 'main' into update-team-permissions-enums
kfcampbell Dec 12, 2022
a4deb95
split CheckTeamPermissions into two methods
notauserx Dec 13, 2022
f3d6980
Update ObservableTeamsClientTests.cs based on review
notauserx Dec 15, 2022
960382c
add cref to legacy update and delete endpoints
notauserx Dec 15, 2022
62de913
remove editorconfig file
notauserx Dec 16, 2022
7f1bd0e
Merge branch 'main' into update-team-permissions-enums
kfcampbell Jan 3, 2023
b13a43c
Merge branch 'main' into update-team-permissions-enums
kfcampbell Jan 5, 2023
4e2c833
Update Octokit.Tests/Clients/TeamsClientTests.cs
notauserx Jan 6, 2023
aa6788f
remove unused line
notauserx Jan 6, 2023
ca7de3b
rename variable based on review
notauserx Jan 6, 2023
c73545b
rename prop to match constructor param
notauserx Jan 6, 2023
2ec885d
add comment to explain TeamPermission enum values on update
notauserx Jan 7, 2023
31a2e9c
Merge branch 'main' into update-team-permissions-enums
notauserx Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on providing a link or some other manner to direct users towards the new endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great suggestion. I will provide a link to the new endpoint in the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, looking forward to it!

Copy link
Contributor Author

@notauserx notauserx Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a link

/// <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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind explaining to me the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added RepositoryContentMediaType to AcceptHeaders for passing repository media type in CheckTeamPermissionsForARepositoryWithCustomAcceptHeader. This caused this convention test to fail because now it expects "application/vnd.github.v3.repository+json" in defaultHeaders

};

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