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

Commit

Permalink
Merge pull request #2053 from heidiberry/add-update-pages-settings
Browse files Browse the repository at this point in the history
Add support for updating a project's GitLab Pages settings
  • Loading branch information
svanharmelen authored Nov 3, 2024
2 parents 5548b4f + fb6678a commit bc6554d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,38 @@ func (s *PagesService) GetPages(gid interface{}, options ...RequestOptionFunc) (

return p, resp, nil
}

// UpdatePages represents the available UpdatePages() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
type UpdatePagesOptions struct {
PagesUniqueDomainEnabled *bool `url:"pages_unique_domain_enabled,omitempty" json:"pages_unique_domain_enabled,omitempty"`
PagesHTTPSOnly *bool `url:"pages_https_only,omitempty" json:"pages_https_only,omitempty"`
}

// UpdatePages updates Pages settings for a project. The user must have
// administrator privileges.
//
// GitLab API Docs:
// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
func (s *PagesService) UpdatePages(pid interface{}, opt UpdatePagesOptions, options ...RequestOptionFunc) (*Pages, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pages", PathEscape(project))

req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
if err != nil {
return nil, nil, err
}

p := new(Pages)
resp, err := s.client.Do(req, p)
if err != nil {
return nil, resp, err
}

return p, resp, nil
}
44 changes: 44 additions & 0 deletions pages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,47 @@ func TestGetPages(t *testing.T) {
require.NotNil(t, resp)
require.Equal(t, want, p)
}

func TestUpdatePages(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/projects/2/pages", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
fmt.Fprint(w, `
{
"url": "https://ssl.domain.example",
"deployments": [
{
"created_at": "2021-04-27T21:27:38.584Z",
"url": "https://ssl.domain.example/",
"path_prefix": "",
"root_directory": null
}
],
"is_unique_domain_enabled": true,
"force_https": false
}
`)
})

want := &Pages{
URL: "https://ssl.domain.example",
IsUniqueDomainEnabled: true,
ForceHTTPS: false,
Deployments: []*PagesDeployment{
{
CreatedAt: time.Date(2021, time.April, 27, 21, 27, 38, 584000000, time.UTC),
URL: "https://ssl.domain.example/",
PathPrefix: "",
RootDirectory: "",
},
},
}

p, resp, err := client.Pages.UpdatePages(2, UpdatePagesOptions{
PagesUniqueDomainEnabled: Ptr(true),
PagesHTTPSOnly: Ptr(false),
})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, p)
}

0 comments on commit bc6554d

Please sign in to comment.