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

Allow create custom repository/organization roles without permission #3235

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

andriyun
Copy link
Contributor

Changes related to the issue #3226

Copy link

google-cla bot commented Aug 13, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.94%. Comparing base (2b8c7fa) to head (da56a8b).
Report is 95 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3235      +/-   ##
==========================================
- Coverage   97.72%   92.94%   -4.78%     
==========================================
  Files         153      171      +18     
  Lines       13390    11633    -1757     
==========================================
- Hits        13085    10812    -2273     
- Misses        215      727     +512     
- Partials       90       94       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andriyun
Copy link
Contributor Author

See a discussion about the approach in the relevant issue #3226

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

So this is much closer, but my point was that we need two NEW endpoints so as to not affect the people who are currently not modifying the permissions (and therefore need the omitempty).

We need a new CreateCustomOrgRoleNoPermissions and a new CreateCustomRepoRoleNoPermissions that both use the "trick" of an inline struct that removes the omitempty like you have done here.
The comment for each of these need to clearly state why these two endpoints are needed.

@andriyun
Copy link
Contributor Author

I don't think I understand the need of having separate endpoint.

It is clear for me that method CreateCustomRepoRole will fail if you call it without any of properties of type CreateOrUpdateCustomRepoRoleOptions. Which is expected and makes sense after reading GitHub Rest API

However it will also fail when you call it with defined values for each of the properties where empty array is used as value for Permission. Which is my case exactly.

The aim of this PR is to fix the bug. While still using the same methods without breaking current API as you requested :)

Taking into account above written, what would be the benefits from having extra endpoint?

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 14, 2024

So isn't it true that users will want the omitempty when they wish to not modify existing permissions?
Or are you saying that there is never a usage for not sending the permissions field?
I'll go read the docs again as well.

I know we have other endpoints where we must differentiate between an omitted field and an empty field, and I thought this was one of those cases.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 14, 2024

@andriyun
Copy link
Contributor Author

So isn't it true that users will want the omitempty when they wish to not modify existing permissions?

Yes it is true. In this case I would expect Permission property to be nil, so condition will return false and parameters would be send untouched.

The intention of the changes is to rewrite type for the case when Permissions property has an empty array as value

@andriyun
Copy link
Contributor Author

However, this endpoint makes NO MENTION of the permissions field: https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#create-a-custom-organization-role

This link lead me to: Get all organization roles

If you open this link https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#create-a-custom-organization-role

You find permission key as required

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 14, 2024

OK, so if I'm reading the docs correctly, then the permissions field is ALWAYS required, correct?

If so, I truly apologize for chasing you down an incorrect rabbit hole that I created.

So it looks like completely removing the omitempty is simply the right choice afterall, agreed?

@andriyun
Copy link
Contributor Author

NP. Glad we clarified the intention here :)

Unfortunatelly type CreateOrUpdateCustomRepoRoleOptions used for both Create (where all the properties are required) and Update where all of them are optional 😀

So we either rewrite API or use tweaks like I suggested in the PR

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 14, 2024

OK, now that we've tried all the possibilities, I'll let you decide which you think is most appropriate.
Please let me know when you want me to take another look.
If it requires breaking the API, then so be it. If, however, you can avoid it, that would be nice-to-have.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 15, 2024

@andriyun - can you please explain to me how what you have written is different from simply removing the omitempty on lines 56 and 64?

I'm honestly having troubles understanding the difference.

@andriyun
Copy link
Contributor Author

andriyun commented Aug 16, 2024

You are right %)
I was wrong in my assumption before and solution here is way simpler

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @andriyun !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 16, 2024

(nit: @andriyun - In the future, please don't use force-push in this repo, as the history of all the experiments we went through and discussed are now lost and we can't refer to them in case others want to discuss them. Also, we always squash-and-merge in this repo so there is never a concern about bloated history in the final commits.)

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Aug 16, 2024
@andriyun
Copy link
Contributor Author

andriyun commented Aug 16, 2024

Ohhh.. ok, got you. I have previous changes saved in separate branches locally.

Do you want me to add them?
@gmlewis

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 16, 2024

No, that's OK... if someone in the future wants to dig up what we discussed, we can try and recreate then. 😂
Thank you for offering, though! 😄

Copy link
Contributor

@tomfeigin tomfeigin left a comment

Choose a reason for hiding this comment

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

LGTM

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Aug 19, 2024
@gmlewis
Copy link
Collaborator

gmlewis commented Aug 19, 2024

Thank you, @tomfeigin !
Merging.

@gmlewis gmlewis merged commit 3085a9c into google:master Aug 19, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants