Dynamic forge request size (#2622)

and remove checks for gitea 1.18 which is quite old already and
shouldn't be used anymore

closes https://github.com/woodpecker-ci/woodpecker/issues/1038
This commit is contained in:
qwerty287 2023-10-23 09:22:00 +02:00 committed by GitHub
parent 5b62214f27
commit ce85a60e32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View file

@ -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: |

View file

@ -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
}