Navigation Menu

Skip to content

Commit

Permalink
Change create fork options from url param to body param (#2490)
Browse files Browse the repository at this point in the history
Fixes: #2489.
  • Loading branch information
valbeat committed Dec 9, 2022
1 parent 44d91eb commit 3e3f03c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions github/repos_forks.go
Expand Up @@ -7,9 +7,8 @@ package github

import (
"context"
"fmt"

"encoding/json"
"fmt"
)

// RepositoryListForksOptions specifies the optional parameters to the
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions github/repos_forks_test.go
Expand Up @@ -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}`)
})

Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit 3e3f03c

Please sign in to comment.