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:
parent
316d2391df
commit
c388803b68
2 changed files with 28 additions and 13 deletions
|
@ -4,22 +4,31 @@
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
// GlobalSettings represent the global settings of a gitea instance witch is exposed by API
|
// GlobalUISettings represent the global ui settings of a gitea instance witch is exposed by API
|
||||||
type GlobalSettings struct {
|
type GlobalUISettings struct {
|
||||||
AllowedReactions []string
|
AllowedReactions []string `json:"allowed_reactions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGlobalSettings get all global settings witch are exposed by API
|
// GlobalRepoSettings represent the global repository settings of a gitea instance witch is exposed by API
|
||||||
func (c *Client) GetGlobalSettings() (settings GlobalSettings, err error) {
|
type GlobalRepoSettings struct {
|
||||||
settings.AllowedReactions, err = c.GetSettingAllowedReactions()
|
MirrorsDisabled bool `json:"mirrors_disabled"`
|
||||||
return
|
HTTPGitDisabled bool `json:"http_git_disabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSettingAllowedReactions return reactions witch are allowed on a instance
|
// GetGlobalUISettings get global ui settings witch are exposed by API
|
||||||
func (c *Client) GetSettingAllowedReactions() ([]string, error) {
|
func (c *Client) GetGlobalUISettings() (settings *GlobalUISettings, err error) {
|
||||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var reactions []string
|
conf := new(GlobalUISettings)
|
||||||
return reactions, c.getParsedResponse("GET", "/settings/allowed_reactions", jsonHeader, nil, &reactions)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,14 @@ import (
|
||||||
func TestGetGlobalSettings(t *testing.T) {
|
func TestGetGlobalSettings(t *testing.T) {
|
||||||
log.Println("== TestGetGlobalSettings ==")
|
log.Println("== TestGetGlobalSettings ==")
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
settings, err := c.GetGlobalSettings()
|
|
||||||
|
uiSettings, err := c.GetGlobalUISettings()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expectedAllowedReactions := []string{"+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"}
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue