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

Add suspended as option to AdminService.CreateUser() #3049

Merged
merged 3 commits into from Feb 1, 2024

Conversation

ttomsu
Copy link
Contributor

@ttomsu ttomsu commented Jan 12, 2024

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b61795d) 97.71% compared to head (3e623b8) 97.71%.

❗ Current head 3e623b8 differs from pull request most recent head db9c8bc. Consider uploading reports for the commit db9c8bc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3049      +/-   ##
==========================================
- Coverage   97.71%   97.71%   -0.01%     
==========================================
  Files         152      152              
  Lines       13326    13321       -5     
==========================================
- Hits        13021    13016       -5     
  Misses        215      215              
  Partials       90       90              

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

}

// CreateUser creates a new user in GitHub Enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-server@3.11/rest/enterprise-admin/users#create-a-user
//
//meta:operation POST /admin/users
func (s *AdminService) CreateUser(ctx context.Context, login, email string) (*User, *Response, error) {
func (s *AdminService) CreateUser(ctx context.Context, login, email string, suspended bool) (*User, *Response, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the official docs: https://docs.github.com/en/enterprise-server@3.11/rest/enterprise-admin/users?apiVersion=2022-11-28#create-a-user
I'm noticing that both the email and suspended fields are optional.

Since we are breaking the API with this PR, I'm wondering if it might make more sense to create a new CreateUserOptions struct containing these optional fields? In addition, login is required, so maybe change line 16 above to Login string json:"login"`.

In other words, we would still use the private createUserRequest but we would copy fields in from opts where the new signature would be:

unc (s *AdminService) CreateUser(ctx context.Context, login string, opts *CreateUserOptions) (*User, *Response, error) {

If we do this now, then we might have a bit more flexibility in the future to add new fields to the CreateUserOptions struct without breaking the API again.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Glenn - I like the idea to break it only once if we have to break it at all.

Taking a look at other examples around the codebase, it looks like one pattern is to pass URL path segments individually, then the whole object that would end up in the request body. Examples

Following this pattern, it seems a more consistent option would be to export the createUserRequest object and pass that as the second param (after ctx).

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes, I see what you are saying. Path query parameters should be listed as separate arguments, and then you can have another parameter:

func (s *AdminService) CreateUser(ctx context.Context, req CreateUserRequest) (*User, *Response, error) {

where:

// CreateUserRequest represents the fields sent to the `CreateUser` endpoint.
// Note that `Login` is a required field.
type CreateUserRequest struct {
	Login     string `json:"login"`
	Email     *string `json:"email,omitempty"`
	Suspended *bool   `json:"suspended,omitempty"`
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change implemented. PTAL

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 23, 2024

In the future, please don't use force-push in this repo, as we always squash-and-merge at the end. See CONTRIBUTING.md for more details. Thanks.

github/admin_users.go Outdated Show resolved Hide resolved
github/admin_users.go Outdated Show resolved Hide resolved
github/admin_users.go Outdated Show resolved Hide resolved
@gmlewis gmlewis added NeedsReview PR is awaiting a review before merging. Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). labels Jan 23, 2024
@ttomsu
Copy link
Contributor Author

ttomsu commented Jan 23, 2024

Apologies for the force commit, my local branch got out of whack and I didn't realize it.

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, @ttomsu !
LGTM.

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

@ttomsu
Copy link
Contributor Author

ttomsu commented Jan 26, 2024

@gmlewis Anyone you can ping to get a second set of eyes on?

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 26, 2024

All contributors to this repo are volunteers and I typically try not to ping individuals unless there is an urgent need.

@fchimpan
Copy link
Contributor

fchimpan commented Feb 1, 2024

Hi, @ttomsu !
Thanks your implementation. LGTM! Great job!

If we do this now, then we might have a bit more flexibility in the future to add new fields to the CreateUserOptions struct without breaking the API again.

I agree it. It's a good design.

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

gmlewis commented Feb 1, 2024

Thank you, @fchimpan !
Merging.

@gmlewis gmlewis merged commit 2b8c7fa into google:master Feb 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants