From 10669e6c6bcb6923f024b40ca2614a2f3129a26b Mon Sep 17 00:00:00 2001 From: Takuma Kajikawa Date: Thu, 1 Sep 2022 08:58:16 +0900 Subject: [PATCH] Additional options name, default_branch_only for create a fork (#2448) Fixes: #2447. --- github/repos_forks.go | 4 +++- github/repos_forks_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/github/repos_forks.go b/github/repos_forks.go index 97bb328ffb..5c7d5dbd78 100644 --- a/github/repos_forks.go +++ b/github/repos_forks.go @@ -53,7 +53,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"` + Organization string `url:"organization,omitempty"` + Name string `url:"name,omitempty"` + DefaultBranchOnly bool `url:"default_branch_only,omitempty"` } // CreateFork creates a fork of the specified repository. diff --git a/github/repos_forks_test.go b/github/repos_forks_test.go index 83b7a82781..07be423bc3 100644 --- a/github/repos_forks_test.go +++ b/github/repos_forks_test.go @@ -73,11 +73,11 @@ 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"}) + testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"}) fmt.Fprint(w, `{"id":1}`) }) - opt := &RepositoryCreateForkOptions{Organization: "o"} + opt := &RepositoryCreateForkOptions{Organization: "o", Name: "n", DefaultBranchOnly: true} ctx := context.Background() repo, _, err := client.Repositories.CreateFork(ctx, "o", "r", opt) if err != nil { @@ -110,13 +110,13 @@ 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"}) + testFormValues(t, r, values{"organization": "o", "name": "n", "default_branch_only": "true"}) // This response indicates the fork will happen asynchronously. w.WriteHeader(http.StatusAccepted) fmt.Fprint(w, `{"id":1}`) }) - opt := &RepositoryCreateForkOptions{Organization: "o"} + opt := &RepositoryCreateForkOptions{Organization: "o", Name: "n", DefaultBranchOnly: true} ctx := context.Background() repo, _, err := client.Repositories.CreateFork(ctx, "o", "r", opt) if _, ok := err.(*AcceptedError); !ok {