Skip to content

Commit

Permalink
Additional options name, default_branch_only for create a fork (#2448)
Browse files Browse the repository at this point in the history
Fixes: #2447.
  • Loading branch information
valbeat committed Aug 31, 2022
1 parent 243bda8 commit 10669e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion github/repos_forks.go
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions github/repos_forks_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 10669e6

Please sign in to comment.