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

Commit

Permalink
✨ Appearance API: Get current 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 c7a9790 commit 8fd9735
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
66 changes: 66 additions & 0 deletions appearance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Copyright 2023, 徐晓伟 <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package gitlab

import "net/http"

// 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
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"`
Logo string `json:"logo"`
HeaderLogo string `json:"header_logo"`
Favicon string `json:"favicon"`
NewProjectGuidelines string `json:"new_project_guidelines"`
ProfileImageGuidelines string `json:"profile_image_guidelines"`
HeaderMessage string `json:"header_message"`
FooterMessage string `json:"footer_message"`
MessageBackgroundColor string `json:"message_background_color"`
MessageFontColor string `json:"message_font_color"`
EmailHeaderAndFooterEnabled bool `json:"email_header_and_footer_enabled"`
}

// GetAppearance
//
// 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
}

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

return as, resp, nil
}
78 changes: 78 additions & 0 deletions appearance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// Copyright 2023, 徐晓伟 <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package gitlab

import (
"fmt"
"net/http"
"reflect"
"testing"
)

func TestGetAppearance(t *testing.T) {
mux, client := setup(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
}`)
})

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

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",
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)
}
}
2 changes: 2 additions & 0 deletions gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type Client struct {

// Services used for talking to different parts of the GitLab API.
AccessRequests *AccessRequestsService
Appearance *AppearanceService
Applications *ApplicationsService
AuditEvents *AuditEventsService
Avatar *AvatarRequestsService
Expand Down Expand Up @@ -328,6 +329,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {

// Create all the public services.
c.AccessRequests = &AccessRequestsService{client: c}
c.Appearance = &AppearanceService{client: c}
c.Applications = &ApplicationsService{client: c}
c.AuditEvents = &AuditEventsService{client: c}
c.Avatar = &AvatarRequestsService{client: c}
Expand Down

0 comments on commit 8fd9735

Please sign in to comment.