From 6594bf0b20ccf66bb8c77634d605d467f824fcac Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Mon, 7 Sep 2020 03:09:10 +0000 Subject: [PATCH] Add GetGlobalAPISettings Function (#404) Get Global Limitation Settings Co-authored-by: techknowlogick Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/404 Reviewed-by: Andrew Thornton Reviewed-by: techknowlogick --- gitea/settings.go | 17 +++++++++++++++++ gitea/settings_test.go | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gitea/settings.go b/gitea/settings.go index 42d2bd9..1e8cd2a 100644 --- a/gitea/settings.go +++ b/gitea/settings.go @@ -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) +} diff --git a/gitea/settings_test.go b/gitea/settings_test.go index 5a83241..cd9a43c 100644 --- a/gitea/settings_test.go +++ b/gitea/settings_test.go @@ -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) }