Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic forge request size #2622

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/docs/30-administration/11-forges/10-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
29 changes: 20 additions & 9 deletions server/forge/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -56,6 +56,7 @@ type Gitea struct {
ClientID string
ClientSecret string
SkipVerify bool
pageSize int
}

// Opts defines configuration options.
Expand Down Expand Up @@ -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),
},
},
)
Expand Down Expand Up @@ -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),
},
},
)
Expand Down Expand Up @@ -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}})
Expand All @@ -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
}