mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-07 07:21:22 +01:00
Change tag count to artifact count in search result (#11068)
Change tag count to artifact count in search result Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
d250e6998e
commit
89eeeb29ca
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user