Add GetGlobalAPISettings Function (#404)

Get Global Limitation Settings

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/404
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-09-07 03:09:10 +00:00 committed by techknowlogick
parent 88552ee13a
commit 6594bf0b20
2 changed files with 30 additions and 2 deletions

View file

@ -15,6 +15,14 @@ type GlobalRepoSettings struct {
HTTPGitDisabled bool `json:"http_git_disabled"`
}
// GlobalAPISettings contains global api settings exposed by it
type GlobalAPISettings struct {
MaxResponseItems int `json:"max_response_items"`
DefaultPagingNum int `json:"default_paging_num"`
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
}
// 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 {
@ -32,3 +40,12 @@ func (c *Client) GetGlobalRepoSettings() (settings *GlobalRepoSettings, err erro
conf := new(GlobalRepoSettings)
return conf, c.getParsedResponse("GET", "/settings/repository", jsonHeader, nil, &conf)
}
// GetGlobalAPISettings get global api settings witch are exposed by it
func (c *Client) GetGlobalAPISettings() (settings *GlobalAPISettings, err error) {
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
return nil, err
}
conf := new(GlobalAPISettings)
return conf, c.getParsedResponse("GET", "/settings/api", jsonHeader, nil, &conf)
}

View file

@ -22,6 +22,17 @@ func TestGetGlobalSettings(t *testing.T) {
repoSettings, err := c.GetGlobalRepoSettings()
assert.NoError(t, err)
assert.False(t, repoSettings.HTTPGitDisabled)
assert.False(t, repoSettings.MirrorsDisabled)
assert.EqualValues(t, &GlobalRepoSettings{
HTTPGitDisabled: false,
MirrorsDisabled: false,
}, repoSettings)
apiSettings, err := c.GetGlobalAPISettings()
assert.NoError(t, err)
assert.EqualValues(t, &GlobalAPISettings{
MaxResponseItems: 50,
DefaultPagingNum: 30,
DefaultGitTreesPerPage: 1000,
DefaultMaxBlobSize: 10485760,
}, apiSettings)
}