Unverified Commit 89eeeb29 authored by Wenkai Yin(尹文开)'s avatar Wenkai Yin(尹文开) Committed by GitHub
Browse files

Change tag count to artifact count in search result (#11068)


Change tag count to artifact count in search result
Signed-off-by: default avatarWenkai Yin <yinw@vmware.com>
parent d250e699
Showing with 17 additions and 4 deletions
+17 -4
......@@ -4362,9 +4362,9 @@ definitions:
pull_count:
type: integer
description: The count how many times the repository is pulled
tags_count:
artifact_count:
type: integer
description: The count of tags in the repository
description: The count of artifacts in the repository
ProjectReq:
type: object
properties:
......
......@@ -18,11 +18,14 @@ import (
"fmt"
"strings"
"github.com/goharbor/harbor/src/api/artifact"
"github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/common/utils/log"
"github.com/goharbor/harbor/src/core/config"
"github.com/goharbor/harbor/src/internal/orm"
"github.com/goharbor/harbor/src/pkg/q"
"k8s.io/helm/cmd/helm/search"
)
......@@ -166,6 +169,7 @@ func filterRepositories(projects []*models.Project, keyword string) (
projectMap[project.Name] = project
}
ctx := orm.NewContext(nil, dao.GetOrmer())
for _, repository := range repositories {
projectName, _ := utils.ParseRepository(repository.Name)
project, exist := projectMap[projectName]
......@@ -179,8 +183,17 @@ func filterRepositories(projects []*models.Project, keyword string) (
entry["project_public"] = project.IsPublic()
entry["pull_count"] = repository.PullCount
// TODO populate artifact count
// entry["tags_count"] = len(tags)
count, err := artifact.Ctl.Count(ctx, &q.Query{
Keywords: map[string]interface{}{
"RepositoryID": repository.RepositoryID,
},
})
if err != nil {
log.Errorf("failed to get the count of artifacts under the repository %s: %v",
repository.Name, err)
} else {
entry["artifact_count"] = count
}
result = append(result, entry)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment