From fae64746269f2633f88f5b4f6a7255783560d05b Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 11 Jul 2026 07:39:31 +0900 Subject: [PATCH] refactor!: Pass `TemplateRepoRequest` by value in `Repositories.CreateFromTemplate` Towards #3644. BREAKING CHANGE: Repositories.CreateFromTemplate now takes TemplateRepoRequest by value, and TemplateRepoRequest.Name is now a non-pointer string. --- .golangci.yml | 1 - github/github-accessors.go | 6 +++--- github/github-accessors_test.go | 5 +---- github/repos.go | 4 ++-- github/repos_test.go | 4 ++-- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f97cf33fd65..bdb33697bc4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -269,7 +269,6 @@ linters: - TeamAddTeamRepoOptions - TeamLDAPMapping - TeamProjectOptions - - TemplateRepoRequest - UpdateCodespaceOptions - UpdateDefaultSetupConfigurationOptions - UpdateProjectItemOptions diff --git a/github/github-accessors.go b/github/github-accessors.go index 630f6f82b94..978d190471a 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -41494,12 +41494,12 @@ func (t *TemplateRepoRequest) GetIncludeAllBranches() bool { return *t.IncludeAllBranches } -// GetName returns the Name field if it's non-nil, zero value otherwise. +// GetName returns the Name field. func (t *TemplateRepoRequest) GetName() string { - if t == nil || t.Name == nil { + if t == nil { return "" } - return *t.Name + return t.Name } // GetOwner returns the Owner field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a3e50ffc4d1..791b5fbd9b4 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -52006,10 +52006,7 @@ func TestTemplateRepoRequest_GetIncludeAllBranches(tt *testing.T) { func TestTemplateRepoRequest_GetName(tt *testing.T) { tt.Parallel() - var zeroValue string - t := &TemplateRepoRequest{Name: &zeroValue} - t.GetName() - t = &TemplateRepoRequest{} + t := &TemplateRepoRequest{} t.GetName() t = nil t.GetName() diff --git a/github/repos.go b/github/repos.go index f1217533d36..ed894f01d45 100644 --- a/github/repos.go +++ b/github/repos.go @@ -621,7 +621,7 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo // TemplateRepoRequest represents a request to create a repository from a template. type TemplateRepoRequest struct { // Name is required when creating a repo. - Name *string `json:"name,omitempty"` + Name string `json:"name"` Owner *string `json:"owner,omitempty"` Description *string `json:"description,omitempty"` @@ -634,7 +634,7 @@ type TemplateRepoRequest struct { // GitHub API docs: https://docs.github.com/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-using-a-template // //meta:operation POST /repos/{template_owner}/{template_repo}/generate -func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo string, body *TemplateRepoRequest) (*Repository, *Response, error) { +func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo string, body TemplateRepoRequest) (*Repository, *Response, error) { u := fmt.Sprintf("repos/%v/%v/generate", templateOwner, templateRepo) req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/repos_test.go b/github/repos_test.go index cd206c654e1..8b4c558a0a5 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -341,8 +341,8 @@ func TestRepositoriesService_CreateFromTemplate(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - templateRepoReq := &TemplateRepoRequest{ - Name: Ptr("n"), + templateRepoReq := TemplateRepoRequest{ + Name: "n", } mux.HandleFunc("/repos/to/tr/generate", func(w http.ResponseWriter, r *http.Request) {