Skip to content

Commit

Permalink
refactor(gitlab): added debug log
Browse files Browse the repository at this point in the history
Signed-off-by: lxShaDoWxl <lxshadowxkingxl@gmail.com>
(cherry picked from commit 7328062)
  • Loading branch information
lxShaDoWxl authored and chlins committed Apr 26, 2023
1 parent 7f251b3 commit e0e1896
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/pkg/reg/adapter/gitlab/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (a *adapter) FetchArtifacts(filters []*model.Filter) ([]*model.Resource, er
} else {
pathPatterns = append(pathPatterns, nameFilter)
}
log.Debugf("Patterns: %v", pathPatterns)

for _, project := range projects {
if !project.RegistryEnabled {
Expand All @@ -144,8 +145,10 @@ func (a *adapter) FetchArtifacts(filters []*model.Filter) ([]*model.Resource, er
}
for _, repository := range repositories {
if !existPatterns(repository.Path, pathPatterns) {
log.Debugf("Skipping repository path=%s and id=%d", repository.Path, repository.ID)
continue
}
log.Debugf("Search tags repository path=%s and id=%d", repository.Path, repository.ID)
vTags, err := a.clientGitlabAPI.getTags(project.ID, repository.ID)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions src/pkg/reg/adapter/gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/goharbor/harbor/src/lib/log"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -94,6 +95,7 @@ func (c *Client) getRepositories(projectID int64) ([]*Repository, error) {
if err := c.GetAndIteratePagination(urlAPI, &repositories); err != nil {
return nil, err
}
log.Debugf("Count repositories %d in project %d", len(repositories), projectID)
return repositories, nil
}

Expand All @@ -103,6 +105,7 @@ func (c *Client) getTags(projectID int64, repositoryID int64) ([]*Tag, error) {
if err := c.GetAndIteratePagination(urlAPI, &tags); err != nil {
return nil, err
}
log.Debugf("Count tags %d in repository %d, and project %d", len(tags), repositoryID, projectID)
return tags, nil
}

Expand All @@ -113,7 +116,6 @@ func (c *Client) GetAndIteratePagination(endpoint string, v interface{}) error {
if err != nil {
return err
}

rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr {
return errors.New("v should be a pointer to a slice")
Expand All @@ -122,7 +124,7 @@ func (c *Client) GetAndIteratePagination(endpoint string, v interface{}) error {
if elemType.Kind() != reflect.Slice {
return errors.New("v should be a pointer to a slice")
}

log.Debugf("Gitlab request %s", urlAPI)
resources := reflect.Indirect(reflect.New(elemType))
for len(endpoint) > 0 {
req, err := c.newRequest(http.MethodGet, endpoint, nil)
Expand Down

0 comments on commit e0e1896

Please sign in to comment.