Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change create fork options from url param to body param #2490

Merged
merged 3 commits into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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