Update GetGlobalSettings Functions (#376)

extend Test

Update GetGlobalSettings functions

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/376
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: Gary Kim <gary@garykim.dev>
This commit is contained in:
6543 2020-06-30 20:29:09 +00:00
parent 316d2391df
commit c388803b68
2 changed files with 28 additions and 13 deletions

View file

@ -4,22 +4,31 @@
package gitea
// GlobalSettings represent the global settings of a gitea instance witch is exposed by API
type GlobalSettings struct {
AllowedReactions []string
// GlobalUISettings represent the global ui settings of a gitea instance witch is exposed by API
type GlobalUISettings struct {
AllowedReactions []string `json:"allowed_reactions"`
}
// GetGlobalSettings get all global settings witch are exposed by API
func (c *Client) GetGlobalSettings() (settings GlobalSettings, err error) {
settings.AllowedReactions, err = c.GetSettingAllowedReactions()
return
// GlobalRepoSettings represent the global repository settings of a gitea instance witch is exposed by API
type GlobalRepoSettings struct {
MirrorsDisabled bool `json:"mirrors_disabled"`
HTTPGitDisabled bool `json:"http_git_disabled"`
}
// GetSettingAllowedReactions return reactions witch are allowed on a instance
func (c *Client) GetSettingAllowedReactions() ([]string, error) {
// GetGlobalUISettings get global ui settings witch are exposed by API
func (c *Client) GetGlobalUISettings() (settings *GlobalUISettings, err 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)
conf := new(GlobalUISettings)
return conf, c.getParsedResponse("GET", "/settings/ui", jsonHeader, nil, &conf)
}
// GetGlobalRepoSettings get global repository settings witch are exposed by API
func (c *Client) GetGlobalRepoSettings() (settings *GlobalRepoSettings, err error) {
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
return nil, err
}
conf := new(GlobalRepoSettings)
return conf, c.getParsedResponse("GET", "/settings/repository", jsonHeader, nil, &conf)
}

View file

@ -14,8 +14,14 @@ import (
func TestGetGlobalSettings(t *testing.T) {
log.Println("== TestGetGlobalSettings ==")
c := newTestClient()
settings, err := c.GetGlobalSettings()
uiSettings, err := c.GetGlobalUISettings()
assert.NoError(t, err)
expectedAllowedReactions := []string{"+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"}
assert.ElementsMatch(t, expectedAllowedReactions, settings.AllowedReactions)
assert.ElementsMatch(t, expectedAllowedReactions, uiSettings.AllowedReactions)
repoSettings, err := c.GetGlobalRepoSettings()
assert.NoError(t, err)
assert.False(t, repoSettings.HTTPGitDisabled)
assert.False(t, repoSettings.MirrorsDisabled)
}