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

Support PagesSource as struct for update pages API #2407

Merged
merged 2 commits into from Jul 12, 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
10 changes: 5 additions & 5 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions github/repos_pages.go
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions github/repos_pages_test.go
Expand Up @@ -76,20 +76,20 @@ 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) {
v := new(PagesUpdate)
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()
Expand All @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down