From 444cae9ebb7fe13078a3de7cbeae49d1bb5a60c1 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 13 Oct 2023 16:49:32 +0200 Subject: [PATCH] Refactor PR so it matches the rest of the package --- appearance.go | 85 ++++++++++++++----------------- appearance_test.go | 124 ++++++++++++++++++++++----------------------- 2 files changed, 100 insertions(+), 109 deletions(-) diff --git a/appearance.go b/appearance.go index bc51f3a02..f21893c0e 100644 --- a/appearance.go +++ b/appearance.go @@ -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"` @@ -46,21 +47,18 @@ 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 } @@ -68,49 +66,42 @@ func (s *AppearanceService) GetAppearance(options ...RequestOptionFunc) (*Appear 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 } diff --git a/appearance_test.go b/appearance_test.go index ba3298919..771452e27 100644 --- a/appearance_test.go +++ b/appearance_test.go @@ -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() @@ -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", @@ -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",