Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit bc6554d

Browse files
authored
Merge pull request #2053 from heidiberry/add-update-pages-settings
Add support for updating a project's GitLab Pages settings
2 parents 5548b4f + fb6678a commit bc6554d

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

pages.go

+35
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,38 @@ func (s *PagesService) GetPages(gid interface{}, options ...RequestOptionFunc) (
9090

9191
return p, resp, nil
9292
}
93+
94+
// UpdatePages represents the available UpdatePages() options.
95+
//
96+
// GitLab API docs:
97+
// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
98+
type UpdatePagesOptions struct {
99+
PagesUniqueDomainEnabled *bool `url:"pages_unique_domain_enabled,omitempty" json:"pages_unique_domain_enabled,omitempty"`
100+
PagesHTTPSOnly *bool `url:"pages_https_only,omitempty" json:"pages_https_only,omitempty"`
101+
}
102+
103+
// UpdatePages updates Pages settings for a project. The user must have
104+
// administrator privileges.
105+
//
106+
// GitLab API Docs:
107+
// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
108+
func (s *PagesService) UpdatePages(pid interface{}, opt UpdatePagesOptions, options ...RequestOptionFunc) (*Pages, *Response, error) {
109+
project, err := parseID(pid)
110+
if err != nil {
111+
return nil, nil, err
112+
}
113+
u := fmt.Sprintf("projects/%s/pages", PathEscape(project))
114+
115+
req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
116+
if err != nil {
117+
return nil, nil, err
118+
}
119+
120+
p := new(Pages)
121+
resp, err := s.client.Do(req, p)
122+
if err != nil {
123+
return nil, resp, err
124+
}
125+
126+
return p, resp, nil
127+
}

pages_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,47 @@ func TestGetPages(t *testing.T) {
7878
require.NotNil(t, resp)
7979
require.Equal(t, want, p)
8080
}
81+
82+
func TestUpdatePages(t *testing.T) {
83+
mux, client := setup(t)
84+
mux.HandleFunc("/api/v4/projects/2/pages", func(w http.ResponseWriter, r *http.Request) {
85+
testMethod(t, r, http.MethodPatch)
86+
fmt.Fprint(w, `
87+
{
88+
"url": "https://ssl.domain.example",
89+
"deployments": [
90+
{
91+
"created_at": "2021-04-27T21:27:38.584Z",
92+
"url": "https://ssl.domain.example/",
93+
"path_prefix": "",
94+
"root_directory": null
95+
}
96+
],
97+
"is_unique_domain_enabled": true,
98+
"force_https": false
99+
}
100+
`)
101+
})
102+
103+
want := &Pages{
104+
URL: "https://ssl.domain.example",
105+
IsUniqueDomainEnabled: true,
106+
ForceHTTPS: false,
107+
Deployments: []*PagesDeployment{
108+
{
109+
CreatedAt: time.Date(2021, time.April, 27, 21, 27, 38, 584000000, time.UTC),
110+
URL: "https://ssl.domain.example/",
111+
PathPrefix: "",
112+
RootDirectory: "",
113+
},
114+
},
115+
}
116+
117+
p, resp, err := client.Pages.UpdatePages(2, UpdatePagesOptions{
118+
PagesUniqueDomainEnabled: Ptr(true),
119+
PagesHTTPSOnly: Ptr(false),
120+
})
121+
require.NoError(t, err)
122+
require.NotNil(t, resp)
123+
require.Equal(t, want, p)
124+
}

0 commit comments

Comments
 (0)