Add Function to get GetGlobalSettings and GetSettingAllowedReactions #359

Merged
techknowlogick merged 1 commits from 6543/go-sdk:get-global-settings into master 2020-06-09 00:19:30 +00:00
2 changed files with 46 additions and 0 deletions
Showing only changes of commit 768b132587 - Show all commits

25
gitea/settings.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
// GlobalSettings represent the global settings of a gitea instance witch is exposed by API
type GlobalSettings struct {
AllowedReactions []string
}
// GetGlobalSettings get all global settings witch are exposed by API
func (c *Client) GetGlobalSettings() (settings GlobalSettings, err error) {
settings.AllowedReactions, err = c.GetSettingAllowedReactions()
return
}
// GetSettingAllowedReactions return reactions witch are allowed on a instance
func (c *Client) GetSettingAllowedReactions() ([]string, error) {
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
return nil, err
}
var reactions []string
return reactions, c.getParsedResponse("GET", "/settings/allowed_reactions", jsonHeader, nil, &reactions)
}

21
gitea/settings_test.go Normal file
View File

@ -0,0 +1,21 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
import (
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetGlobalSettings(t *testing.T) {
log.Println("== TestGetGlobalSettings ==")
c := newTestClient()
settings, err := c.GetGlobalSettings()
assert.NoError(t, err)
expectedAllowedReactions := []string{"+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"}
assert.ElementsMatch(t, expectedAllowedReactions, settings.AllowedReactions)
}