Skip to content

Commit

Permalink
Improve error logging and continue when there are insufficient permis…
Browse files Browse the repository at this point in the history
…sions (#315)
  • Loading branch information
dustin-decker authored Apr 8, 2022
1 parent ea51671 commit ba6ea9d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/sources/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (s *Source) newClient() (*gitlab.Client, error) {
func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, error) {
// projects without repo will get user projects, groups projects, and subgroup projects.
user, _, err := apiClient.Users.CurrentUser()
//TODO what happens if the user is anonymous

if err != nil {
return nil, errors.Errorf("unable to authenticate using: %s", s.authMethod)
}
Expand All @@ -173,7 +173,7 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
for {
userProjects, res, err := apiClient.Projects.ListUserProjects(user.ID, projectQueryOptions)
if err != nil {
return nil, errors.Errorf("received error on listing projects: %s\n", err)
return nil, errors.Errorf("received error on listing user projects: %s\n", err)
}
for _, prj := range userProjects {
projects[prj.ID] = prj
Expand All @@ -197,7 +197,7 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
for {
groupList, res, err := apiClient.Groups.ListGroups(&listGroupsOptions)
if err != nil {
return nil, errors.Errorf("received error on listing projects: %s\n", err)
return nil, errors.Errorf("received error on listing groups, you probably don't have permissions to do that: %s\n", err)
}
groups = append(groups, groupList...)
listGroupsOptions.Page = res.NextPage
Expand All @@ -214,7 +214,8 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
for {
grpPrjs, res, err := apiClient.Groups.ListGroupProjects(group.ID, listGroupProjectOptions)
if err != nil {
return nil, errors.Errorf("received error on listing projects: %s\n", err)
log.WithError(err).WithField("group", group.FullPath).Warn("received error on listing group projects, you probably don't have permissions to do that")
break
}
for _, prj := range grpPrjs {
projects[prj.ID] = prj
Expand Down

0 comments on commit ba6ea9d

Please sign in to comment.