From dbc8ab091148ed20b0c621cbda586f7f5d5a8576 Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 09:11:23 +0530 Subject: [PATCH 1/7] refactor!: rename UsersService.Edit to Update and pass User by value --- github/users.go | 2 +- github/users_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/github/users.go b/github/users.go index d06a2dfe138..6b47f4c3524 100644 --- a/github/users.go +++ b/github/users.go @@ -161,7 +161,7 @@ func (s *UsersService) GetByID(ctx context.Context, id int64) (*User, *Response, // GitHub API docs: https://docs.github.com/rest/users/users?apiVersion=2022-11-28#update-the-authenticated-user // //meta:operation PATCH /user -func (s *UsersService) Edit(ctx context.Context, body *User) (*User, *Response, error) { +func (s *UsersService) Update(ctx context.Context, body User) (*User, *Response, error) { u := "user" req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { diff --git a/github/users_test.go b/github/users_test.go index 41f5d10349a..63e5f01ed28 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -113,11 +113,11 @@ func TestUsersService_GetByID(t *testing.T) { }) } -func TestUsersService_Edit(t *testing.T) { +func TestUsersService_Update(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &User{Name: Ptr("n")} + input := User{Name: Ptr("n")} mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") @@ -126,7 +126,7 @@ func TestUsersService_Edit(t *testing.T) { }) ctx := t.Context() - user, _, err := client.Users.Edit(ctx, input) + user, _, err := client.Users.Update(ctx, input) if err != nil { t.Errorf("Users.Edit returned error: %v", err) } @@ -138,7 +138,7 @@ func TestUsersService_Edit(t *testing.T) { const methodName = "Edit" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Users.Edit(ctx, input) + got, resp, err := client.Users.Update(ctx, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } From 1e88d7b15e76fb1cf520e8e0397a5953411d7d2b Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 09:26:33 +0530 Subject: [PATCH 2/7] feat: Added UpdateUserRequest for body --- github/users.go | 14 +++++++++++++- github/users_test.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/github/users.go b/github/users.go index 6b47f4c3524..3106cc3ffc8 100644 --- a/github/users.go +++ b/github/users.go @@ -101,6 +101,18 @@ type User struct { Inherited *bool `json:"inherited,omitempty"` } +// UserUpdateRequest represents the request body for updating a user. +type UserUpdateRequest struct { + Name *string `json:"name,omitempty"` + Email *string `json:"email,omitempty"` + Blog *string `json:"blog,omitempty"` + TwitterUsername *string `json:"twitter_username,omitempty"` + Company *string `json:"company,omitempty"` + Location *string `json:"location,omitempty"` + Hireable *bool `json:"hireable,omitempty"` + Bio *string `json:"bio,omitempty"` +} + func (u User) String() string { return Stringify(u) } @@ -161,7 +173,7 @@ func (s *UsersService) GetByID(ctx context.Context, id int64) (*User, *Response, // GitHub API docs: https://docs.github.com/rest/users/users?apiVersion=2022-11-28#update-the-authenticated-user // //meta:operation PATCH /user -func (s *UsersService) Update(ctx context.Context, body User) (*User, *Response, error) { +func (s *UsersService) Update(ctx context.Context, body UserUpdateRequest) (*User, *Response, error) { u := "user" req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { diff --git a/github/users_test.go b/github/users_test.go index 63e5f01ed28..1820ba35bb0 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -117,7 +117,7 @@ func TestUsersService_Update(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := User{Name: Ptr("n")} + input := UserUpdateRequest{Name: Ptr("n")} mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") From e126edc23a7de60c6c28937d39689d371ec19e37 Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 09:27:42 +0530 Subject: [PATCH 3/7] chore: comments fixed --- github/users_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/users_test.go b/github/users_test.go index 1820ba35bb0..7cf364c183c 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -128,15 +128,15 @@ func TestUsersService_Update(t *testing.T) { ctx := t.Context() user, _, err := client.Users.Update(ctx, input) if err != nil { - t.Errorf("Users.Edit returned error: %v", err) + t.Errorf("Users.Update returned error: %v", err) } want := &User{ID: Ptr(int64(1))} if !cmp.Equal(user, want) { - t.Errorf("Users.Edit returned %+v, want %+v", user, want) + t.Errorf("Users.Update returned %+v, want %+v", user, want) } - const methodName = "Edit" + const methodName = "Update" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { got, resp, err := client.Users.Update(ctx, input) if got != nil { From 43ff96bd0e1ff0c7565cc5d8550dcd54993f774e Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 10:18:40 +0530 Subject: [PATCH 4/7] ran script tests --- github/github-accessors.go | 64 ++++++++++++++++++++++++ github/github-accessors_test.go | 88 +++++++++++++++++++++++++++++++++ github/users.go | 16 +++--- 3 files changed, 160 insertions(+), 8 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index c7b472ac943..52548efa281 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -44902,6 +44902,70 @@ func (u *UserSuspendOptions) GetReason() string { return *u.Reason } +// GetBio returns the Bio field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetBio() string { + if u == nil || u.Bio == nil { + return "" + } + return *u.Bio +} + +// GetBlog returns the Blog field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetBlog() string { + if u == nil || u.Blog == nil { + return "" + } + return *u.Blog +} + +// GetCompany returns the Company field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetCompany() string { + if u == nil || u.Company == nil { + return "" + } + return *u.Company +} + +// GetEmail returns the Email field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetEmail() string { + if u == nil || u.Email == nil { + return "" + } + return *u.Email +} + +// GetHireable returns the Hireable field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetHireable() bool { + if u == nil || u.Hireable == nil { + return false + } + return *u.Hireable +} + +// GetLocation returns the Location field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetLocation() string { + if u == nil || u.Location == nil { + return "" + } + return *u.Location +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetName() string { + if u == nil || u.Name == nil { + return "" + } + return *u.Name +} + +// GetTwitterUsername returns the TwitterUsername field if it's non-nil, zero value otherwise. +func (u *UserUpdateRequest) GetTwitterUsername() string { + if u == nil || u.TwitterUsername == nil { + return "" + } + return *u.TwitterUsername +} + // GetEcosystem returns the Ecosystem field if it's non-nil, zero value otherwise. func (v *VulnerabilityPackage) GetEcosystem() string { if v == nil || v.Ecosystem == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c164347030c..b0b73002bba 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -56321,6 +56321,94 @@ func TestUserSuspendOptions_GetReason(tt *testing.T) { u.GetReason() } +func TestUserUpdateRequest_GetBio(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Bio: &zeroValue} + u.GetBio() + u = &UserUpdateRequest{} + u.GetBio() + u = nil + u.GetBio() +} + +func TestUserUpdateRequest_GetBlog(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Blog: &zeroValue} + u.GetBlog() + u = &UserUpdateRequest{} + u.GetBlog() + u = nil + u.GetBlog() +} + +func TestUserUpdateRequest_GetCompany(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Company: &zeroValue} + u.GetCompany() + u = &UserUpdateRequest{} + u.GetCompany() + u = nil + u.GetCompany() +} + +func TestUserUpdateRequest_GetEmail(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Email: &zeroValue} + u.GetEmail() + u = &UserUpdateRequest{} + u.GetEmail() + u = nil + u.GetEmail() +} + +func TestUserUpdateRequest_GetHireable(tt *testing.T) { + tt.Parallel() + var zeroValue bool + u := &UserUpdateRequest{Hireable: &zeroValue} + u.GetHireable() + u = &UserUpdateRequest{} + u.GetHireable() + u = nil + u.GetHireable() +} + +func TestUserUpdateRequest_GetLocation(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Location: &zeroValue} + u.GetLocation() + u = &UserUpdateRequest{} + u.GetLocation() + u = nil + u.GetLocation() +} + +func TestUserUpdateRequest_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{Name: &zeroValue} + u.GetName() + u = &UserUpdateRequest{} + u.GetName() + u = nil + u.GetName() +} + +func TestUserUpdateRequest_GetTwitterUsername(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UserUpdateRequest{TwitterUsername: &zeroValue} + u.GetTwitterUsername() + u = &UserUpdateRequest{} + u.GetTwitterUsername() + u = nil + u.GetTwitterUsername() +} + func TestVulnerabilityPackage_GetEcosystem(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/users.go b/github/users.go index 3106cc3ffc8..2115770f860 100644 --- a/github/users.go +++ b/github/users.go @@ -103,14 +103,14 @@ type User struct { // UserUpdateRequest represents the request body for updating a user. type UserUpdateRequest struct { - Name *string `json:"name,omitempty"` - Email *string `json:"email,omitempty"` - Blog *string `json:"blog,omitempty"` - TwitterUsername *string `json:"twitter_username,omitempty"` - Company *string `json:"company,omitempty"` - Location *string `json:"location,omitempty"` - Hireable *bool `json:"hireable,omitempty"` - Bio *string `json:"bio,omitempty"` + Name *string `json:"name,omitempty"` + Email *string `json:"email,omitempty"` + Blog *string `json:"blog,omitempty"` + TwitterUsername *string `json:"twitter_username,omitempty"` + Company *string `json:"company,omitempty"` + Location *string `json:"location,omitempty"` + Hireable *bool `json:"hireable,omitempty"` + Bio *string `json:"bio,omitempty"` } func (u User) String() string { From 4f4ea96cdc30ad6854c541c21da131f76cfab0d3 Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 12:57:52 +0530 Subject: [PATCH 5/7] fix: change comment from Edit to Update --- github/users.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/users.go b/github/users.go index 2115770f860..e5b92a158d7 100644 --- a/github/users.go +++ b/github/users.go @@ -168,7 +168,7 @@ func (s *UsersService) GetByID(ctx context.Context, id int64) (*User, *Response, return user, resp, nil } -// Edit the authenticated user. +// Update the authenticated user. // // GitHub API docs: https://docs.github.com/rest/users/users?apiVersion=2022-11-28#update-the-authenticated-user // From f9167fa366c7128dddfb043a6e9c53d8d592996c Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 18:26:20 +0530 Subject: [PATCH 6/7] fix: Updated method name from Edit to Update in users integration test --- test/integration/users_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/users_test.go b/test/integration/users_test.go index c9ca6831ddb..7f7c2f52eef 100644 --- a/test/integration/users_test.go +++ b/test/integration/users_test.go @@ -67,7 +67,7 @@ func TestUsers_Update(t *testing.T) { testLoc := fmt.Sprintf("test-%v", rand.Int()) u.Location = &testLoc - _, _, err = client.Users.Edit(t.Context(), u) + _, _, err = client.Users.Update(t.Context(), u) if err != nil { t.Fatalf("Users.Update returned error: %v", err) } @@ -84,9 +84,9 @@ func TestUsers_Update(t *testing.T) { // set location back to the original value u.Location = &location - _, _, err = client.Users.Edit(t.Context(), u) + _, _, err = client.Users.Update(t.Context(), u) if err != nil { - t.Fatalf("Users.Edit returned error: %v", err) + t.Fatalf("Users.Update returned error: %v", err) } } From d69b8f1e648b2a769fb7ffae5edb91388d395ffd Mon Sep 17 00:00:00 2001 From: Manav Sharma Date: Thu, 6 Aug 2026 19:02:57 +0530 Subject: [PATCH 7/7] fixup --- test/integration/users_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/integration/users_test.go b/test/integration/users_test.go index 7f7c2f52eef..f490f4ac1c1 100644 --- a/test/integration/users_test.go +++ b/test/integration/users_test.go @@ -65,9 +65,8 @@ func TestUsers_Update(t *testing.T) { // update location to test value testLoc := fmt.Sprintf("test-%v", rand.Int()) - u.Location = &testLoc - _, _, err = client.Users.Update(t.Context(), u) + _, _, err = client.Users.Update(t.Context(), github.UserUpdateRequest{Location: &testLoc}) if err != nil { t.Fatalf("Users.Update returned error: %v", err) } @@ -83,8 +82,7 @@ func TestUsers_Update(t *testing.T) { } // set location back to the original value - u.Location = &location - _, _, err = client.Users.Update(t.Context(), u) + _, _, err = client.Users.Update(t.Context(), github.UserUpdateRequest{Location: &location}) if err != nil { t.Fatalf("Users.Update returned error: %v", err) }