update models with updated permission enum#2633
Conversation
|
I have added two new enums, NewTeamPermission and TeamPermission to model the enum values from the openapi schema. Also, updated the NewTeam.cs to use the NewTeamPermission, and UpdateTeam.cs and Team.cs to use TeamPermission. I am having some trouble running the integration tests for TeamsClientTests, all the tests are marked with OrganizationTest. I have added an organization to my test account for integration, is there a setup doc that I am missing? Also, I see that the permission is marked as Deprecated on the docs as well as the rest open api schema. Are these permissions getting deprecated? |
How are you attempting to run the tests? What platform are you doing it on? The only doc I'm aware of that's relevant is this one.
I don't have any cool insider information here, sorry. I would guess if they're marked as deprecated, they will be deprecated, but I'm not sure of the timeframe. |
|
@kfcampbell, thanks for your response, I guess I did not provide enough context for my problem. Figured out the issue, I had not set the OCTOKIT_GITHUBORGANIZATION environment variable and the OrganizationTests requires that variable be set. |
| var teamDescription = Helper.MakeNameWithTimestamp("updated description"); | ||
|
|
||
| // setting TeamPermission.Admin fails with Octokit.ApiValidationException : Setting team permission to admin is no longer supported | ||
| var teamPermission = TeamPermission.Push; |
There was a problem hiding this comment.
It seems to me that admin is not being accepted as a permission value, even though the docs say it can be.
I can get this test passing with Pull and Push values, but passing admin just fails with
setting TeamPermission.Admin fails with Octokit.ApiValidationException : Setting team permission to admin is no longer supported
curl also gets me the same error
{
"message": "Setting team permission to admin is no longer supported",
"documentation_url": "https://docs.github.com/rest/reference/teams/#update-a-team-legacy"
}|
What I propose is we make TeamPermission enum with pull and push values, and use that in NewTeam, UpdateTeam and Team classes. I can see that when you edit and Organization from the web UI, there is no option to set the permission, I am guessing since the permission is marked as deprecated, they don't a. I have kept both the current and legacy versions for Update a team and Delete a team, as can be seen in the ITeamsClient, I have renamed the Update and Delete contract as UpdateLegacy and DeleteLegacy respectively, and created Update and Delete contracts that exposes the current endpoint. Not sure whether to keep the legacy endpoints exposed but I think we can leave that on the ITeamsContract. Also, not dealing with RepositoryPermissions (also called ReviewPermissions) for collaborators as @nickfloyd mentioned in the issue, want to tackle it in a separate PR. Hopefully, I am moving in the right direction with this PR, let me know what you think. |
This sounds like a reasonable solution to me. I always get confused by the push/pull and read/write permission splits.
My vote is to keep the legacy behavior around in the SDK until it's dropped by the API.
👍 This direction makes sense to me. |
…tauserx/octokit.net into update-team-permissions-enums
|
Here's a summary of my changes so far
"permission": {
"type": "string"
},
"permissions": {
"type": "object",
"properties": {
"pull": {
"type": "boolean"
},
"triage": {
"type": "boolean"
},
"push": {
"type": "boolean"
},
"maintain": {
"type": "boolean"
},
"admin": {
"type": "boolean"
}
},
"required": [
"pull",
"triage",
"push",
"maintain",
"admin"
]
},
|
.editorconfig
Outdated
| @@ -0,0 +1,3 @@ | |||
| root = true | |||
| [*.cs] | |||
| end_of_line = lf | |||
There was a problem hiding this comment.
I've added this file because I was having trouble with inconsistent line ending.
I can remove this file if necessary. But I think having an editorconfig file greatly improves the dev experience. This one is by no means complete.
There was a problem hiding this comment.
I'd prefer that this is added in a separate PR if you don't mind.
There was a problem hiding this comment.
That sounds reasonable. Removed the file and set a global gitignore for my local editorconfig
Not to my knowledge, though perhaps @nickfloyd has opinions on this matter?
👍
I've added the "Type: Breaking Change" label to this PR. When releasing a new version, we'll have to be careful to increment to v5.0.0 as well. |
kfcampbell
left a comment
There was a problem hiding this comment.
Thank you for contributing! I have several naive questions, I hope that's okay.
.editorconfig
Outdated
| @@ -0,0 +1,3 @@ | |||
| root = true | |||
| [*.cs] | |||
| end_of_line = lf | |||
There was a problem hiding this comment.
I'd prefer that this is added in a separate PR if you don't mind.
| /// <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. |
There was a problem hiding this comment.
What are your thoughts on providing a link or some other manner to direct users towards the new endpoint?
There was a problem hiding this comment.
That is a great suggestion. I will provide a link to the new endpoint in the comments.
There was a problem hiding this comment.
Sounds good, looking forward to it!
| // 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" |
There was a problem hiding this comment.
Do you mind explaining to me the reason for this change?
There was a problem hiding this comment.
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
| /// <exception cref="ApiException">Thrown when a general API error occurs.</exception> | ||
| /// <returns></returns> | ||
| [ManualRoute("PUT", "/orgs/{org}/team/{team_slug}/repos/{owner}/{repo}")] | ||
| [ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")] |
There was a problem hiding this comment.
What's the reason you went with the strategy of changing routes here and adding new ones with a different method name to the client?
I'm naively thinking it might be easier to avoid a breaking change here by isolating the new functionality to new methods.
There was a problem hiding this comment.
This is the legacy endpoint that is currently implemented in the project, however, it gets the endpoint uri from ApiUrls.TeamRepository which returns the /teams/{team_id}/repos/{owner}/{repo}, so I've decided to update the ManualRoute attribute value to match the correct url from the docs.
There was a problem hiding this comment.
Ahh, thanks for explaining! @nickfloyd has mentioned to me that ManualRoute is used for documentation generation rather than implementation, so this makes sense.
| /// <param name="uri">URI of the API resource to put</param> | ||
| /// <param name="data">Object that describes the API resource; this will be serialized and used as the request's body</param> | ||
| /// <returns>A <see cref="Task"/> for the request's execution.</returns> | ||
| public Task Put(Uri uri, object data) |
There was a problem hiding this comment.
Do you mind ELI5ing the reason for this helper?
There was a problem hiding this comment.
I needed a non-generic Put method where I could pass data for the request's body for AddOrUpdateTeamRepositoryPermissions method on TeamsClients, which returns a 204.
Co-authored-by: Keegan Campbell <[email protected]>
I am glad you took the time to review and give me some feedback. Appreciate it! |
kfcampbell
left a comment
There was a problem hiding this comment.
Thank you for your patience! @nickfloyd and I had a few more questions on this review for you before we get this wrapped up. Looking forward to getting the PR merged and released!
| /// <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. |
There was a problem hiding this comment.
Sounds good, looking forward to it!
| /// <exception cref="ApiException">Thrown when a general API error occurs.</exception> | ||
| /// <returns></returns> | ||
| [ManualRoute("PUT", "/orgs/{org}/team/{team_slug}/repos/{owner}/{repo}")] | ||
| [ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")] |
There was a problem hiding this comment.
Ahh, thanks for explaining! @nickfloyd has mentioned to me that ManualRoute is used for documentation generation rather than implementation, so this makes sense.
| /// <param name="body">The object to serialize as the body of the request</param> | ||
| /// <returns>The returned <seealso cref="HttpStatusCode"/></returns> | ||
| public async Task<HttpStatusCode> Put(Uri uri, string accepts) | ||
| public async Task<HttpStatusCode> Put(Uri uri, object body) |
There was a problem hiding this comment.
Would you mind explaining why accepts has been removed here? I'm following that you want to PUT the dynamic object similarly to in ApiConnection.cs, but I'm unsure why that means accepts is no longer desirable/needed.
There was a problem hiding this comment.
I've double-checked with the current main branch, and this method has only one reference to IConnection.cs.
Since I needed to pass an object, initially I added the object body as an additional parameter. Then I saw that the string accepts is not being passed from anywhere in the codebase, so I decided to remove that argument.
|
I'll be 👍 on landing this after a small comment update to link to the REST API docs issue! |
|
@kfcampbell I have added the changes based on your review. Do you think we can get this merged? |
kfcampbell
left a comment
There was a problem hiding this comment.
Thanks for working with me on this change!
|
🎉 Great to see 🎉. What's the plans around merging and releasing? |
|
v5.0.0 has been released with this change in it! |
|
@kfcampbell thank you for merging my changes. |
|
|
||
| /// <summary> | ||
| /// permission attached to this team | ||
| /// Deprecated. The permission that new repositories will be added to the team with when none is specified |
There was a problem hiding this comment.
I'm not sure this is right. This model is returned from gitHubClient.Repository.GetAllTeams(repositoryOwner, repositoryName), so the permission is actually "what permission does this team have for this repo".
There was a problem hiding this comment.
(Previously PermissionLevel was wrong too)
There was a problem hiding this comment.
@matt-richardson you are correct! This comment is more suitable for NewTeam.cs and UpdateTeam.cs than the Team.cs.
From the API reference here, the permission has a description of "Permission that the team will have for its repositories", which I think would be a better comment for this property. I can submit a quick patch updating the comment if we can agree on that.
I am currently working on a PR that takes care of all the other outdated permissions.
Resolves #2323
Behavior
Before the change?
After the change?
Based on the schema
Other information
Additional info
Pull request checklist
Does this introduce a breaking change?
Type: Breaking changelabel)Changes to the request(NewTeam.cs, UpdateTeam.cs) and response(Team.cs) model
Changed Permission property type from Permission to TeamPermission on NewTeam and UpdateTeam request models
Changed Permission property type from StringEnum to string
Pull request type