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:
Wenkai Yin(尹文开) 2020-03-16 14:28:59 +08:00 committed by GitHub
parent d250e6998e
commit 89eeeb29ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -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:

View File

@ -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)
}