Skip to content

Commit 94c5255

Browse files
authored
Merge pull request #58 from sacha-c/ignore-project-list-fix
fix: ignore fetched projects with ignore list
2 parents 18e12b0 + 7c5b816 commit 94c5255

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

internal/patrol/patrol.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,6 @@ func (s *sheriffService) scanAndGetReports(locations []config.ProjectLocation, i
145145
}
146146

147147
func (s *sheriffService) getProjectList(locs []config.ProjectLocation, ignored []config.ProjectLocation) (projects []repository.Project, warn error) {
148-
// Filter out locations that are in the ignored list
149-
locs = pie.Filter(locs, func(loc config.ProjectLocation) bool {
150-
return !slices.ContainsFunc(ignored, func(ignoredPath config.ProjectLocation) bool {
151-
ignore := ignoredPath.Path == loc.Path && ignoredPath.Type == loc.Type
152-
if ignore {
153-
log.Info().Str("path", loc.Path).Msg("Ignoring project location as it is in the ignored list")
154-
}
155-
return ignore
156-
})
157-
})
158-
159148
gitlabLocs := pie.Map(
160149
pie.Filter(locs, func(loc config.ProjectLocation) bool { return loc.Type == repository.Gitlab }),
161150
func(loc config.ProjectLocation) string { return loc.Path },
@@ -185,6 +174,17 @@ func (s *sheriffService) getProjectList(locs []config.ProjectLocation, ignored [
185174
projects = append(projects, githubProjects...)
186175
}
187176

177+
// Filter out locations that are in the ignored list
178+
projects = pie.Filter(projects, func(project repository.Project) bool {
179+
return !slices.ContainsFunc(ignored, func(ignoredPath config.ProjectLocation) bool {
180+
ignore := ignoredPath.Path == project.Path && ignoredPath.Type == project.Repository
181+
if ignore {
182+
log.Info().Str("path", project.Path).Msg("Ignoring project location as it is in the ignored list")
183+
}
184+
return ignore
185+
})
186+
})
187+
188188
return
189189
}
190190

internal/patrol/patrol_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestMarkOutdatedAcknowledgements(t *testing.T) {
194194

195195
func TestGetProjectList_IgnoresProject(t *testing.T) {
196196
mockClient := &mockClient{}
197-
mockClient.On("GetProjectList", []string{"group/to/scan"}).Return([]repository.Project{{Name: "Hello World", RepoUrl: "https://gitlab.com/group/to/scan.git", Repository: repository.Gitlab}}, nil)
197+
mockClient.On("GetProjectList", []string{"group/to/scan"}).Return([]repository.Project{{Path: "path/of/project", Repository: repository.Gitlab}}, nil)
198198

199199
mockRepoService := &mockRepoService{}
200200
mockRepoService.On("Provide", repository.Gitlab).Return(mockClient)
@@ -204,11 +204,11 @@ func TestGetProjectList_IgnoresProject(t *testing.T) {
204204
// The ignored list contains the project path, so it should be filtered out
205205
projects, warn := svc.(*sheriffService).getProjectList(
206206
[]config.ProjectLocation{{Type: repository.Gitlab, Path: "group/to/scan"}},
207-
[]config.ProjectLocation{{Type: repository.Gitlab, Path: "group/to/scan"}},
207+
[]config.ProjectLocation{{Type: repository.Gitlab, Path: "path/of/project"}},
208208
)
209209
assert.Nil(t, warn)
210210
assert.Empty(t, projects)
211-
mockClient.AssertNotCalled(t, "GetProjectList", []string{"group/to/scan"})
211+
mockClient.AssertNotCalled(t, "GetProjectList", []string{"path/of/project"})
212212
}
213213

214214
type mockRepoService struct {

0 commit comments

Comments
 (0)