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

Commit

Permalink
Refactor PR so it matches the rest of the package
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Oct 13, 2023
1 parent 9548712 commit 520bee9
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 109 deletions.
85 changes: 38 additions & 47 deletions appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ package gitlab

import "net/http"

// AppearanceService handles communication with appearance
// of the Gitlab API.
// AppearanceService handles communication with appearance of the Gitlab API.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/appearance.html
type AppearanceService struct {
client *Client
}

// Appearance represents a GitLab appearance
// Appearance represents a GitLab appearance.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/appearance.html
type Appearance struct {
Title string `json:"title"`
Description string `json:"description"`
PwaName string `json:"pwa_name"`
PwaShortName string `json:"pwa_short_name"`
PwaDescription string `json:"pwa_description"`
PwaIcon string `json:"pwa_icon"`
PWAName string `json:"pwa_name"`
PWAShortName string `json:"pwa_short_name"`
PWADescription string `json:"pwa_description"`
PWAIcon string `json:"pwa_icon"`
Logo string `json:"logo"`
HeaderLogo string `json:"header_logo"`
Favicon string `json:"favicon"`
Expand All @@ -46,71 +47,61 @@ type Appearance struct {
EmailHeaderAndFooterEnabled bool `json:"email_header_and_footer_enabled"`
}

// GetAppearance Get current appearance configuration
// List the current appearance configuration of the GitLab instance.
// GetAppearance gets the current appearance configuration of the GitLab instance.
//
// Gitlab API docs : https://docs.gitlab.com/ee/api/appearance.html#get-current-appearance-configuration
// 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)

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)
as := new(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.
// ChangeAppearanceOptions represents the available ChangeAppearance() 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"`
type ChangeAppearanceOptions 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.
// ChangeAppearance changes the 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) {
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/appearance.html#change-appearance-configuration
func (s *AppearanceService) ChangeAppearance(opt *ChangeAppearanceOptions, 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)
as := new(Appearance)
resp, err := s.client.Do(req, as)
if err != nil {
return nil, resp, err
}
Expand Down
124 changes: 62 additions & 62 deletions appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ func TestGetAppearance(t *testing.T) {
mux.HandleFunc("/api/v4/application/appearance", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"title": "GitLab Test Instance",
"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
}`)
"title": "GitLab Test Instance",
"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
}`)
})

appearance, _, err := client.Appearance.GetAppearance()
Expand All @@ -56,10 +56,10 @@ func TestGetAppearance(t *testing.T) {
want := &Appearance{
Title: "GitLab Test Instance",
Description: "gitlab-test.example.com",
PwaName: "GitLab PWA",
PwaShortName: "GitLab",
PwaDescription: "GitLab as PWA",
PwaIcon: "/uploads/-/system/appearance/pwa_icon/1/pwa_logo.png",
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",
Expand All @@ -77,62 +77,62 @@ func TestGetAppearance(t *testing.T) {
}
}

func TestPutAppearance(t *testing.T) {
func TestChangeAppearance(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
}`)
"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,
opt := &ChangeAppearanceOptions{
Title: String("GitLab Test Instance - 001"),
Description: String("gitlab-test.example.com"),
PWAName: String("GitLab PWA"),
PWAShortName: String("GitLab"),
PWADescription: String("GitLab as PWA"),
PWAIcon: String("/uploads/-/system/appearance/pwa_icon/1/pwa_logo.png"),
Logo: String("/uploads/-/system/appearance/logo/1/logo.png"),
HeaderLogo: String("/uploads/-/system/appearance/header_logo/1/header.png"),
Favicon: String("/uploads/-/system/appearance/favicon/1/favicon.png"),
NewProjectGuidelines: String("Please read the FAQs for help."),
ProfileImageGuidelines: String("Custom profile image guidelines"),
HeaderMessage: String(""),
FooterMessage: String(""),
MessageBackgroundColor: String("#e75e40"),
MessageFontColor: String("#ffffff"),
EmailHeaderAndFooterEnabled: Bool(false),
}

appearance, _, err := client.Appearance.PutAppearance(opt)
appearance, _, err := client.Appearance.ChangeAppearance(opt)
if err != nil {
t.Errorf("Appearance.GetAppearance returned error: %v", err)
t.Errorf("Appearance.ChangeAppearance 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",
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",
Expand Down

0 comments on commit 520bee9

Please sign in to comment.