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

Commit

Permalink
✨ Appearance API: Change appearance configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaowei-com-cn committed Oct 8, 2023
1 parent 8fd9735 commit 9548712
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 2 deletions.
57 changes: 55 additions & 2 deletions appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,69 @@ type Appearance struct {
EmailHeaderAndFooterEnabled bool `json:"email_header_and_footer_enabled"`
}

// GetAppearance
// GetAppearance Get current appearance configuration
// List the current appearance configuration of the GitLab instance.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/appearance.html#get-current-appearance-configuration
func (s *AppearanceService) GetAppearance(options ...RequestOptionFunc) (*Appearance, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "/application/appearance", nil, options)
req, err := s.client.NewRequest(http.MethodGet, "application/appearance", nil, options)

if err != nil {
return nil, nil, err
}

// as := new(Appearance)
// resp, err := s.client.Do(req, as)
var as *Appearance
resp, err := s.client.Do(req, &as)
if err != nil {
return nil, resp, err
}

return as, resp, nil
}

// PutAppearanceRequestOptions represents the available
// PutAppearance() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/appearance.html#change-appearance-configuration
type PutAppearanceRequestOptions struct {
Title string `url:"title,omitempty" json:"title,omitempty"`
Description string `url:"description,omitempty" json:"description,omitempty"`
PwaName string `url:"pwa_name,omitempty" json:"pwa_name,omitempty"`
PwaShortName string `url:"pwa_short_name,omitempty" json:"pwa_short_name,omitempty"`
PwaDescription string `url:"pwa_description,omitempty" json:"pwa_description,omitempty"`
PwaIcon string `url:"pwa_icon,omitempty" json:"pwa_icon,omitempty"`
Logo string `url:"logo,omitempty" json:"logo,omitempty"`
HeaderLogo string `url:"header_logo,omitempty" json:"header_logo,omitempty"`
Favicon string `url:"favicon,omitempty" json:"favicon,omitempty"`
NewProjectGuidelines string `url:"new_project_guidelines,omitempty" json:"new_project_guidelines,omitempty"`
ProfileImageGuidelines string `url:"profile_image_guidelines,omitempty" json:"profile_image_guidelines,omitempty"`
HeaderMessage string `url:"header_message,omitempty" json:"header_message,omitempty"`
FooterMessage string `url:"footer_message,omitempty" json:"footer_message,omitempty"`
MessageBackgroundColor string `url:"message_background_color,omitempty" json:"message_background_color,omitempty"`
MessageFontColor string `url:"message_font_color,omitempty" json:"message_font_color,omitempty"`
EmailHeaderAndFooterEnabled bool `url:"email_header_and_footer_enabled,omitempty" json:"email_header_and_footer_enabled,omitempty"`
URL string `url:"url,omitempty" json:"url,omitempty"`
}

// PutAppearance Change appearance configuration
// Use an API

// PutAppearance Change appearance configuration
// Use an API call to modify GitLab instance appearance configuration.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/appearance.html#change-appearance-configuration
func (s *AppearanceService) PutAppearance(opt *PutAppearanceRequestOptions, options ...RequestOptionFunc) (*Appearance, *Response, error) {
req, err := s.client.NewRequest(http.MethodPut, "application/appearance", opt, options)

if err != nil {
return nil, nil, err
}

// as := new(Appearance)
// resp, err := s.client.Do(req, as)
var as *Appearance
resp, err := s.client.Do(req, &as)
if err != nil {
Expand Down
73 changes: 73 additions & 0 deletions appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,76 @@ func TestGetAppearance(t *testing.T) {
t.Errorf("Appearance.GetAppearance returned %+v, want %+v", appearance, want)
}
}

func TestPutAppearance(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/application/appearance", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{
"title": "GitLab Test Instance - 001",
"description": "gitlab-test.example.com",
"pwa_name": "GitLab PWA",
"pwa_short_name": "GitLab",
"pwa_description": "GitLab as PWA",
"pwa_icon": "/uploads/-/system/appearance/pwa_icon/1/pwa_logo.png",
"logo": "/uploads/-/system/appearance/logo/1/logo.png",
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"profile_image_guidelines": "Custom profile image guidelines",
"header_message": "",
"footer_message": "",
"message_background_color": "#e75e40",
"message_font_color": "#ffffff",
"email_header_and_footer_enabled": false
}`)
})

opt := &PutAppearanceRequestOptions{
Title: "GitLab Test Instance - 001",
Description: "gitlab-test.example.com",
PwaName: "GitLab PWA",
PwaShortName: "GitLab",
PwaDescription: "GitLab as PWA",
PwaIcon: "/uploads/-/system/appearance/pwa_icon/1/pwa_logo.png",
Logo: "/uploads/-/system/appearance/logo/1/logo.png",
HeaderLogo: "/uploads/-/system/appearance/header_logo/1/header.png",
Favicon: "/uploads/-/system/appearance/favicon/1/favicon.png",
NewProjectGuidelines: "Please read the FAQs for help.",
ProfileImageGuidelines: "Custom profile image guidelines",
HeaderMessage: "",
FooterMessage: "",
MessageBackgroundColor: "#e75e40",
MessageFontColor: "#ffffff",
EmailHeaderAndFooterEnabled: false,
}

appearance, _, err := client.Appearance.PutAppearance(opt)
if err != nil {
t.Errorf("Appearance.GetAppearance returned error: %v", err)
}

want := &Appearance{
Title: "GitLab Test Instance - 001",
Description: "gitlab-test.example.com",
PwaName: "GitLab PWA",
PwaShortName: "GitLab",
PwaDescription: "GitLab as PWA",
PwaIcon: "/uploads/-/system/appearance/pwa_icon/1/pwa_logo.png",
Logo: "/uploads/-/system/appearance/logo/1/logo.png",
HeaderLogo: "/uploads/-/system/appearance/header_logo/1/header.png",
Favicon: "/uploads/-/system/appearance/favicon/1/favicon.png",
NewProjectGuidelines: "Please read the FAQs for help.",
ProfileImageGuidelines: "Custom profile image guidelines",
HeaderMessage: "",
FooterMessage: "",
MessageBackgroundColor: "#e75e40",
MessageFontColor: "#ffffff",
EmailHeaderAndFooterEnabled: false,
}

if !reflect.DeepEqual(want, appearance) {
t.Errorf("Appearance.GetAppearance returned %+v, want %+v", appearance, want)
}
}

0 comments on commit 9548712

Please sign in to comment.