From ae6a52440ac47b8d0eed5875de9d801bc68c1a4a Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:43:26 +0200 Subject: [PATCH] Fix panic in team repos API (#19431) * Fix panic in team repos API * Fix pagination * fmt --- models/organization/team_repo.go | 2 +- routers/api/v1/org/team.go | 2 +- routers/web/misc/markdown.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/models/organization/team_repo.go b/models/organization/team_repo.go index 03ca4678a..657e83aaa 100644 --- a/models/organization/team_repo.go +++ b/models/organization/team_repo.go @@ -48,7 +48,7 @@ func GetTeamRepositories(ctx context.Context, opts *SearchTeamRepoOptions) ([]*r ) } if opts.PageSize > 0 { - sess.Limit(opts.PageSize, opts.Page*opts.PageSize) + sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } var repos []*repo_model.Repository return repos, sess.OrderBy("repository.name"). diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index d0f1fbef7..322196b81 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -545,7 +545,7 @@ func GetTeamRepos(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err) return } - repos := make([]*api.Repository, len(team.Repos)) + repos := make([]*api.Repository, len(teamRepos)) for i, repo := range teamRepos { access, err := models.AccessLevel(ctx.Doer, repo) if err != nil { diff --git a/routers/web/misc/markdown.go b/routers/web/misc/markdown.go index b37aaf10f..0567cbb30 100644 --- a/routers/web/misc/markdown.go +++ b/routers/web/misc/markdown.go @@ -16,6 +16,7 @@ import ( api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" + "mvdan.cc/xurls/v2" )