Update GetGlobalSettings Functions #376

Merged
6543 merged 2 commits from 6543/go-sdk:update_settings-endpoint into master 2020-06-30 20:29:14 +00:00
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)
}