Repository: google/go-github
Pull request #3034 (2023-12-19 15:21:54)

Fix copilot API payload
small fix to #2973

cc @gmlewis @o-sama 

gmlewis: Investigating why tests are failing...
gmlewis: Oh, I see... the unit tests need updating.
@zetaab - please make sure unit tests pass on your side... then push the changes (not force-push) to this PR to fix them.
Please see CONTRIBUTING.md step 4 for details.  Thanks.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3034?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`9d6658a`)](https://app.codecov.io/gh/google/go-github/commit/9d6658a678d61dcbb8b63b53eb12f519a221c749?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) 97.71% compared to head [(`af72ec5`)](https://app.codecov.io/gh/google/go-github/pull/3034?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) 97.71%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #3034   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files         152      152           
  Lines       13241    13241           
=======================================
  Hits        12939    12939           
  Misses        213      213           
  Partials       89       89           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3034?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).


Patch:
diff --git a/github/copilot.go b/github/copilot.go
index 3f3d73b2..51c938c9 100644
--- a/github/copilot.go
+++ b/github/copilot.go
@@ -241,9 +241,9 @@ func (s *CopilotService) AddCopilotUsers(ctx context.Context, org string, users
 	u := fmt.Sprintf("orgs/%v/copilot/billing/selected_users", org)
 
 	body := struct {
-		SelectedUsers []string `json:"selected_users"`
+		SelectedUsernames []string `json:"selected_usernames"`
 	}{
-		SelectedUsers: users,
+		SelectedUsernames: users,
 	}
 
 	req, err := s.client.NewRequest("POST", u, body)
@@ -269,9 +269,9 @@ func (s *CopilotService) RemoveCopilotUsers(ctx context.Context, org string, use
 	u := fmt.Sprintf("orgs/%v/copilot/billing/selected_users", org)
 
 	body := struct {
-		SelectedUsers []string `json:"selected_users"`
+		SelectedUsernames []string `json:"selected_usernames"`
 	}{
-		SelectedUsers: users,
+		SelectedUsernames: users,
 	}
 
 	req, err := s.client.NewRequest("DELETE", u, body)


Test patch:
diff --git a/github/copilot_test.go b/github/copilot_test.go
index 9df2c9a4..c65fda0f 100644
--- a/github/copilot_test.go
+++ b/github/copilot_test.go
@@ -680,7 +680,7 @@ func TestCopilotService_AddCopilotUsers(t *testing.T) {
 
 	mux.HandleFunc("/orgs/o/copilot/billing/selected_users", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "POST")
-		testBody(t, r, `{"selected_users":["user1","user2"]}`+"\n")
+		testBody(t, r, `{"selected_usernames":["user1","user2"]}`+"\n")
 		fmt.Fprint(w, `{"seats_created": 2}`)
 	})
 
@@ -718,7 +718,7 @@ func TestCopilotService_RemoveCopilotUsers(t *testing.T) {
 
 	mux.HandleFunc("/orgs/o/copilot/billing/selected_users", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "DELETE")
-		testBody(t, r, `{"selected_users":["user1","user2"]}`+"\n")
+		testBody(t, r, `{"selected_usernames":["user1","user2"]}`+"\n")
 		fmt.Fprint(w, `{"seats_cancelled": 2}`)
 	})