forked from forgejo/forgejo
Add skip and limit to git.GetTags (#16897)
* Make GetTags() api similar to GetBranches() * Use it for Tag/Release page
This commit is contained in:
parent
9ca0e7905c
commit
77f604a928
6 changed files with 33 additions and 20 deletions
|
@ -547,7 +547,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
|||
return
|
||||
}
|
||||
|
||||
tags, err := ctx.Repo.GitRepo.GetTags()
|
||||
tags, err := ctx.Repo.GitRepo.GetTags(0, 0)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTags", err)
|
||||
return
|
||||
|
|
|
@ -21,7 +21,8 @@ func (repo *Repository) IsTagExist(name string) bool {
|
|||
}
|
||||
|
||||
// GetTags returns all tags of the repository.
|
||||
func (repo *Repository) GetTags() ([]string, error) {
|
||||
// returning at most limit tags, or all if limit is 0.
|
||||
func (repo *Repository) GetTags(skip, limit int) ([]string, error) {
|
||||
var tagNames []string
|
||||
|
||||
tags, err := repo.gogitRepo.Tags()
|
||||
|
@ -40,5 +41,15 @@ func (repo *Repository) GetTags() ([]string, error) {
|
|||
tagNames[i], tagNames[j] = tagNames[j], tagNames[i]
|
||||
}
|
||||
|
||||
// since we have to reverse order we can paginate only afterwards
|
||||
if len(tagNames) < skip {
|
||||
tagNames = []string{}
|
||||
} else {
|
||||
tagNames = tagNames[skip:]
|
||||
}
|
||||
if limit != 0 && len(tagNames) > limit {
|
||||
tagNames = tagNames[:limit]
|
||||
}
|
||||
|
||||
return tagNames, nil
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ func (repo *Repository) IsTagExist(name string) bool {
|
|||
}
|
||||
|
||||
// GetTags returns all tags of the repository.
|
||||
func (repo *Repository) GetTags() (tags []string, err error) {
|
||||
tags, _, err = callShowRef(repo.Path, TagPrefix, "--tags", 0, 0)
|
||||
// returning at most limit tags, or all if limit is 0.
|
||||
func (repo *Repository) GetTags(skip, limit int) (tags []string, err error) {
|
||||
tags, _, err = callShowRef(repo.Path, TagPrefix, "--tags", skip, limit)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) erro
|
|||
}
|
||||
}
|
||||
}
|
||||
tags, err := gitRepo.GetTags()
|
||||
tags, err := gitRepo.GetTags(0, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTags: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue