From 73eced37ff9bb5eb3528f813e97ece102237fc29 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Wed, 6 Jul 2022 23:52:03 +0200 Subject: [PATCH 1/2] Support PagesSource as struct for update pages api --- github/github-accessors.go | 4 ++-- github/github-accessors_test.go | 3 +-- github/repos_pages.go | 6 ++++-- github/repos_pages_test.go | 16 ++++++++-------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index da146bcbf2..5a2857ad73 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10791,9 +10791,9 @@ func (p *PagesUpdate) GetPublic() bool { } // GetSource returns the Source field if it's non-nil, zero value otherwise. -func (p *PagesUpdate) GetSource() string { +func (p *PagesUpdate) GetSource() PagesSource { if p == nil || p.Source == nil { - return "" + return PagesSource{} } return *p.Source } diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 5d30ec960a..584475091a 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -12643,8 +12643,7 @@ func TestPagesUpdate_GetPublic(tt *testing.T) { } func TestPagesUpdate_GetSource(tt *testing.T) { - var zeroValue string - p := &PagesUpdate{Source: &zeroValue} + p := &PagesUpdate{Source: &PagesSource{}} p.GetSource() p = &PagesUpdate{} p.GetSource() diff --git a/github/repos_pages.go b/github/repos_pages.go index 9b864eb090..737cec0f22 100644 --- a/github/repos_pages.go +++ b/github/repos_pages.go @@ -93,8 +93,10 @@ type PagesUpdate struct { // Leaving CNAME empty will remove the custom domain. CNAME *string `json:"cname"` // Source must include the branch name, and may optionally specify the subdirectory "/docs". - // Possible values are: "gh-pages", "master", and "master /docs". - Source *string `json:"source,omitempty"` + // Possible values for Source.Branch are usually "gh-pages", "main", and "master", + // or any other existing branch name. + // Possible values for Source.Path are: "/", and "/docs". + Source *PagesSource `json:"source,omitempty"` // Public configures access controls for the site. // If "true", the site will be accessible to anyone on the internet. If "false", // the site will be accessible to anyone with read access to the repository that diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go index 46bffcff59..ed17e73520 100644 --- a/github/repos_pages_test.go +++ b/github/repos_pages_test.go @@ -76,7 +76,7 @@ func TestRepositoriesService_UpdatePages(t *testing.T) { input := &PagesUpdate{ CNAME: String("www.my-domain.com"), - Source: String("gh-pages"), + Source: &PagesSource{Branch: String("gh-pages")}, } mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { @@ -84,12 +84,12 @@ func TestRepositoriesService_UpdatePages(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PUT") - want := &PagesUpdate{CNAME: String("www.my-domain.com"), Source: String("gh-pages")} + want := &PagesUpdate{CNAME: String("www.my-domain.com"), Source: &PagesSource{Branch: String("gh-pages")}} if !cmp.Equal(v, want) { t.Errorf("Request body = %+v, want %+v", v, want) } - fmt.Fprint(w, `{"cname":"www.my-domain.com","source":"gh-pages"}`) + fmt.Fprint(w, `{"cname":"www.my-domain.com","source":{"branch":"gh-pages"}}`) }) ctx := context.Background() @@ -114,7 +114,7 @@ func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) { defer teardown() input := &PagesUpdate{ - Source: String("gh-pages"), + Source: &PagesSource{Branch: String("gh-pages")}, } mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { @@ -123,12 +123,12 @@ func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) { t.Fatalf("unable to read body: %v", err) } - want := []byte(`{"cname":null,"source":"gh-pages"}` + "\n") + want := []byte(`{"cname":null,"source":{"branch":"gh-pages"}}` + "\n") if !bytes.Equal(got, want) { t.Errorf("Request body = %+v, want %+v", got, want) } - fmt.Fprint(w, `{"cname":null,"source":"gh-pages"}`) + fmt.Fprint(w, `{"cname":null,"source":{"branch":"gh-pages"}}`) }) ctx := context.Background() @@ -393,12 +393,12 @@ func TestPagesUpdate_Marshal(t *testing.T) { u := &PagesUpdate{ CNAME: String("cname"), - Source: String("src"), + Source: &PagesSource{Path: String("src")}, } want := `{ "cname": "cname", - "source": "src" + "source": { "path": "src" } }` testJSONMarshal(t, u, want) From 24023c479c625331985bf324cbf92c570ea37e8e Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Thu, 7 Jul 2022 17:04:12 +0200 Subject: [PATCH 2/2] Let go generate do its work --- github/github-accessors.go | 10 +++++----- github/github-accessors_test.go | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 5a2857ad73..2efe1d43e3 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10790,12 +10790,12 @@ func (p *PagesUpdate) GetPublic() bool { return *p.Public } -// GetSource returns the Source field if it's non-nil, zero value otherwise. -func (p *PagesUpdate) GetSource() PagesSource { - if p == nil || p.Source == nil { - return PagesSource{} +// GetSource returns the Source field. +func (p *PagesUpdate) GetSource() *PagesSource { + if p == nil { + return nil } - return *p.Source + return p.Source } // GetHook returns the Hook field. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 584475091a..ac370a0f1d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -12643,9 +12643,7 @@ func TestPagesUpdate_GetPublic(tt *testing.T) { } func TestPagesUpdate_GetSource(tt *testing.T) { - p := &PagesUpdate{Source: &PagesSource{}} - p.GetSource() - p = &PagesUpdate{} + p := &PagesUpdate{} p.GetSource() p = nil p.GetSource()