Skip to content

Commit ba6ea9d

Browse files
Improve error logging and continue when there are insufficient permissions (#315)
1 parent ea51671 commit ba6ea9d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/sources/gitlab/gitlab.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (s *Source) newClient() (*gitlab.Client, error) {
160160
func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, error) {
161161
// projects without repo will get user projects, groups projects, and subgroup projects.
162162
user, _, err := apiClient.Users.CurrentUser()
163-
//TODO what happens if the user is anonymous
163+
164164
if err != nil {
165165
return nil, errors.Errorf("unable to authenticate using: %s", s.authMethod)
166166
}
@@ -173,7 +173,7 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
173173
for {
174174
userProjects, res, err := apiClient.Projects.ListUserProjects(user.ID, projectQueryOptions)
175175
if err != nil {
176-
return nil, errors.Errorf("received error on listing projects: %s\n", err)
176+
return nil, errors.Errorf("received error on listing user projects: %s\n", err)
177177
}
178178
for _, prj := range userProjects {
179179
projects[prj.ID] = prj
@@ -197,7 +197,7 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
197197
for {
198198
groupList, res, err := apiClient.Groups.ListGroups(&listGroupsOptions)
199199
if err != nil {
200-
return nil, errors.Errorf("received error on listing projects: %s\n", err)
200+
return nil, errors.Errorf("received error on listing groups, you probably don't have permissions to do that: %s\n", err)
201201
}
202202
groups = append(groups, groupList...)
203203
listGroupsOptions.Page = res.NextPage
@@ -214,7 +214,8 @@ func (s *Source) getAllProjects(apiClient *gitlab.Client) ([]*gitlab.Project, er
214214
for {
215215
grpPrjs, res, err := apiClient.Groups.ListGroupProjects(group.ID, listGroupProjectOptions)
216216
if err != nil {
217-
return nil, errors.Errorf("received error on listing projects: %s\n", err)
217+
log.WithError(err).WithField("group", group.FullPath).Warn("received error on listing group projects, you probably don't have permissions to do that")
218+
break
218219
}
219220
for _, prj := range grpPrjs {
220221
projects[prj.ID] = prj

0 commit comments

Comments
 (0)