diff --git a/docs/docs/30-administration/11-forges/10-overview.md b/docs/docs/30-administration/11-forges/10-overview.md index 047c0a8918..b260018d4f 100644 --- a/docs/docs/30-administration/11-forges/10-overview.md +++ b/docs/docs/30-administration/11-forges/10-overview.md @@ -9,6 +9,4 @@ | Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Event: Deploy | :white_check_mark: | :x: | :x: | :x: | | [Multiple workflows](../../20-usage/25-workflows.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| [when.path filter](../../20-usage/20-workflow-syntax.md#path) | :white_check_mark: | :white_check_mark:¹ | :white_check_mark: | :x: | - -¹ for pull requests at least Gitea version 1.17 is required +| [when.path filter](../../20-usage/20-workflow-syntax.md#path) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index 9913edfbba..0d2f218863 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -47,7 +47,7 @@ import ( const ( authorizeTokenURL = "%s/login/oauth/authorize" accessTokenURL = "%s/login/oauth/access_token" - perPage = 50 + defaultPageSize = 50 giteaDevVersion = "v1.18.0" ) @@ -56,6 +56,7 @@ type Gitea struct { ClientID string ClientSecret string SkipVerify bool + pageSize int } // Opts defines configuration options. @@ -207,7 +208,7 @@ func (c *Gitea) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) gitea.ListOrgsOptions{ ListOptions: gitea.ListOptions{ Page: page, - PageSize: perPage, + PageSize: c.perPage(ctx), }, }, ) @@ -263,7 +264,7 @@ func (c *Gitea) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) gitea.ListReposOptions{ ListOptions: gitea.ListOptions{ Page: page, - PageSize: perPage, + PageSize: c.perPage(ctx), }, }, ) @@ -621,12 +622,6 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde return nil, err } - if client.CheckServerVersionConstraint(">= 1.18.0") != nil { - // version too low - log.Debug().Msg("Gitea version does not support getting changed files for PRs") - return []string{}, nil - } - return shared_utils.Paginate(func(page int) ([]string, error) { giteaFiles, _, err := client.ListPullRequestFiles(repo.Owner, repo.Name, index, gitea.ListPullRequestFilesOptions{ListOptions: gitea.ListOptions{Page: page}}) @@ -641,3 +636,19 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde return files, nil }) } + +func (c *Gitea) perPage(ctx context.Context) int { + if c.pageSize == 0 { + client, err := c.newClientToken(ctx, "") + if err != nil { + return defaultPageSize + } + + api, _, err := client.GetGlobalAPISettings() + if err != nil { + return defaultPageSize + } + c.pageSize = api.MaxResponseItems + } + return c.pageSize +}