Skip to content

Commit 3e3f03c

Browse files
authored
Change create fork options from url param to body param (#2490)
Fixes: #2489.
1 parent 44d91eb commit 3e3f03c

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

github/repos_forks.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ package github
77

88
import (
99
"context"
10-
"fmt"
11-
1210
"encoding/json"
11+
"fmt"
1312
)
1413

1514
// RepositoryListForksOptions specifies the optional parameters to the
@@ -53,9 +52,9 @@ func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string,
5352
// RepositoriesService.CreateFork method.
5453
type RepositoryCreateForkOptions struct {
5554
// The organization to fork the repository into.
56-
Organization string `url:"organization,omitempty"`
57-
Name string `url:"name,omitempty"`
58-
DefaultBranchOnly bool `url:"default_branch_only,omitempty"`
55+
Organization string `json:"organization,omitempty"`
56+
Name string `json:"name,omitempty"`
57+
DefaultBranchOnly bool `json:"default_branch_only,omitempty"`
5958
}
6059

6160
// CreateFork creates a fork of the specified repository.
@@ -70,12 +69,8 @@ type RepositoryCreateForkOptions struct {
7069
// GitHub API docs: https://docs.github.com/en/rest/repos/forks#create-a-fork
7170
func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) {
7271
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
73-
u, err := addOptions(u, opts)
74-
if err != nil {
75-
return nil, nil, err
76-
}
7772

78-
req, err := s.client.NewRequest("POST", u, nil)
73+
req, err := s.client.NewRequest("POST", u, opts)
7974
if err != nil {
8075
return nil, nil, err
8176
}

github/repos_forks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestRepositoriesService_CreateFork(t *testing.T) {
7373

7474
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
7575
testMethod(t, r, "POST")
76-
testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"})
76+
testBody(t, r, `{"organization":"o","name":"n","default_branch_only":true}`+"\n")
7777
fmt.Fprint(w, `{"id":1}`)
7878
})
7979

@@ -110,7 +110,7 @@ func TestRepositoriesService_CreateFork_deferred(t *testing.T) {
110110

111111
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
112112
testMethod(t, r, "POST")
113-
testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"})
113+
testBody(t, r, `{"organization":"o","name":"n","default_branch_only":true}`+"\n")
114114
// This response indicates the fork will happen asynchronously.
115115
w.WriteHeader(http.StatusAccepted)
116116
fmt.Fprint(w, `{"id":1}`)

0 commit comments

Comments
 (0)