Skip to content

Commit

Permalink
Dynamic forge request size (#2622)
Browse files Browse the repository at this point in the history
and remove checks for gitea 1.18 which is quite old already and
shouldn't be used anymore

closes #1038
  • Loading branch information
qwerty287 authored Oct 23, 2023
1 parent 5b62214 commit ce85a60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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
}

0 comments on commit ce85a60

Please sign in to comment.