From 3e3f03c6b36d8ff6fb07ecc87c365e855710d14d Mon Sep 17 00:00:00 2001 From: Takuma Kajikawa Date: Sat, 10 Dec 2022 01:20:55 +0900 Subject: [PATCH] Change create fork options from url param to body param (#2490) Fixes: #2489. --- github/repos_forks.go | 15 +++++---------- github/repos_forks_test.go | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/github/repos_forks.go b/github/repos_forks.go index 5c7d5dbd78..f175dfe3b0 100644 --- a/github/repos_forks.go +++ b/github/repos_forks.go @@ -7,9 +7,8 @@ package github import ( "context" - "fmt" - "encoding/json" + "fmt" ) // RepositoryListForksOptions specifies the optional parameters to the @@ -53,9 +52,9 @@ func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, // RepositoriesService.CreateFork method. type RepositoryCreateForkOptions struct { // The organization to fork the repository into. - Organization string `url:"organization,omitempty"` - Name string `url:"name,omitempty"` - DefaultBranchOnly bool `url:"default_branch_only,omitempty"` + Organization string `json:"organization,omitempty"` + Name string `json:"name,omitempty"` + DefaultBranchOnly bool `json:"default_branch_only,omitempty"` } // CreateFork creates a fork of the specified repository. @@ -70,12 +69,8 @@ type RepositoryCreateForkOptions struct { // GitHub API docs: https://docs.github.com/en/rest/repos/forks#create-a-fork func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) { u := fmt.Sprintf("repos/%v/%v/forks", owner, repo) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } - req, err := s.client.NewRequest("POST", u, nil) + req, err := s.client.NewRequest("POST", u, opts) if err != nil { return nil, nil, err } diff --git a/github/repos_forks_test.go b/github/repos_forks_test.go index 07be423bc3..d1a17f62d1 100644 --- a/github/repos_forks_test.go +++ b/github/repos_forks_test.go @@ -73,7 +73,7 @@ func TestRepositoriesService_CreateFork(t *testing.T) { mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"}) + testBody(t, r, `{"organization":"o","name":"n","default_branch_only":true}`+"\n") fmt.Fprint(w, `{"id":1}`) }) @@ -110,7 +110,7 @@ func TestRepositoriesService_CreateFork_deferred(t *testing.T) { mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"}) + testBody(t, r, `{"organization":"o","name":"n","default_branch_only":true}`+"\n") // This response indicates the fork will happen asynchronously. w.WriteHeader(http.StatusAccepted) fmt.Fprint(w, `{"id":1}`)