@@ -10,7 +10,6 @@ import (
1010 "path/filepath"
1111 "regexp"
1212 "strings"
13- "sync"
1413
1514 "github.com/CompassSecurity/pipeleak/cmd/gitlab/util"
1615 "github.com/CompassSecurity/pipeleak/pkg/format"
@@ -132,30 +131,14 @@ func scanNamespace(git *gitlab.Client, namespace string) {
132131 IncludeSubGroups : gitlab .Ptr (true ),
133132 }
134133
135- for {
136- projects , resp , err := git .Groups .ListGroupProjects (group .ID , projectOpts )
137- if err != nil {
138- log .Error ().Stack ().Err (err ).Int ("page" , page ).Msg ("Failed fetching projects" )
139- break
140- }
141-
142- var wg sync.WaitGroup
143- for _ , project := range projects {
144- wg .Add (1 )
145- go func (proj * gitlab.Project ) {
146- defer wg .Done ()
147- log .Debug ().Str ("url" , proj .WebURL ).Msg ("Check project" )
148- identifyRenovateBotJob (git , proj )
149- }(project )
150- }
151- wg .Wait ()
152-
153- if resp .NextPage == 0 {
154- break
155- }
156-
157- projectOpts .Page = resp .NextPage
158- log .Info ().Int ("currentPage" , projectOpts .Page ).Msg ("Fetched projects page" )
134+ err = util .IterateGroupProjects (git , group .ID , projectOpts , func (project * gitlab.Project ) error {
135+ log .Debug ().Str ("url" , project .WebURL ).Msg ("Check project" )
136+ identifyRenovateBotJob (git , project )
137+ return nil
138+ })
139+ if err != nil {
140+ log .Error ().Stack ().Err (err ).Msg ("Failed iterating group projects" )
141+ return
159142 }
160143
161144 log .Info ().Msg ("Fetched all namespace projects" )
@@ -175,30 +158,14 @@ func fetchProjects(git *gitlab.Client) {
175158 Search : gitlab .Ptr (projectSearchQuery ),
176159 }
177160
178- for {
179- projects , resp , err := git .Projects .ListProjects (projectOpts )
180- if err != nil {
181- log .Error ().Stack ().Err (err ).Int ("page" , page ).Msg ("Failed fetching projects" )
182- break
183- }
184-
185- var wg sync.WaitGroup
186- for _ , project := range projects {
187- wg .Add (1 )
188- go func (proj * gitlab.Project ) {
189- defer wg .Done ()
190- log .Debug ().Str ("url" , proj .WebURL ).Msg ("Check project" )
191- identifyRenovateBotJob (git , proj )
192- }(project )
193- }
194- wg .Wait ()
195-
196- if resp .NextPage == 0 {
197- break
198- }
199-
200- projectOpts .Page = resp .NextPage
201- log .Info ().Int ("currentPage" , projectOpts .Page ).Msg ("Fetched projects page" )
161+ err := util .IterateProjects (git , projectOpts , func (project * gitlab.Project ) error {
162+ log .Debug ().Str ("url" , project .WebURL ).Msg ("Check project" )
163+ identifyRenovateBotJob (git , project )
164+ return nil
165+ })
166+ if err != nil {
167+ log .Error ().Stack ().Err (err ).Msg ("Failed iterating projects" )
168+ return
202169 }
203170
204171 log .Info ().Msg ("Fetched all projects" )
0 commit comments