From 0e821a923739392c641a7b2a00d53b4da5f44de7 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 5 Dec 2019 19:50:45 +0800 Subject: [PATCH] Sort the tag before returning the list when calling API Sort the tag before returning the list when calling API list tag API Signed-off-by: Wenkai Yin --- src/core/api/repository.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/api/repository.go b/src/core/api/repository.go index b08ee90a6..9764a286a 100755 --- a/src/core/api/repository.go +++ b/src/core/api/repository.go @@ -615,21 +615,24 @@ func (ra *RepositoryAPI) GetTags() { } tags = ts } - + result := []*models.TagResp{} detail, err := ra.GetBool("detail", true) if !detail && err == nil { - ra.Data["json"] = simpleTags(tags) - ra.ServeJSON() - return + result = simpleTags(tags) + } else { + result = assembleTagsInParallel( + client, + project.ProjectID, + repoName, + tags, + ra.SecurityCtx.GetUsername(), + ) } - - ra.Data["json"] = assembleTagsInParallel( - client, - project.ProjectID, - repoName, - tags, - ra.SecurityCtx.GetUsername(), - ) + // sort by tag name + sort.Slice(result, func(i, j int) bool { + return result[i].Name < result[j].Name + }) + ra.Data["json"] = result ra.ServeJSON() }