Skip to content

Commit d261782

Browse files
committed
refactoring
1 parent 0f7cbe5 commit d261782

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

internal/orchestrator/bricks/bricks.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,12 @@ func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,
163163
}
164164
})
165165

166-
appList, err := getAppList(cfg)
167-
if err != nil {
168-
slog.Error("unable to get app list", slog.String("error", err.Error()))
169-
return BrickDetailsResult{}, fmt.Errorf("unable to get app list: %w", err)
170-
}
171-
usedByApps, err := getUsedByApps(appList, brick.ID, idProvider)
166+
usedByApps, err := getUsedByApps(cfg, brick.ID, idProvider)
172167
if err != nil {
173168
slog.Error("unable to get used by apps", slog.String("error", err.Error()))
174169
return BrickDetailsResult{}, fmt.Errorf("unable to get used by apps: %w", err)
175170
}
171+
176172
return BrickDetailsResult{
177173
ID: id,
178174
Name: brick.Name,
@@ -188,16 +184,15 @@ func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,
188184
}, nil
189185
}
190186

191-
func getAppList(
192-
cfg config.Configuration,
193-
) ([]app.ArduinoApp, error) {
187+
func getUsedByApps(
188+
cfg config.Configuration, brickId string, idProvider *app.IDProvider) ([]AppReference, error) {
194189
var (
195190
pathsToExplore paths.PathList
196191
appPaths paths.PathList
197192
)
198193
pathsToExplore.Add(cfg.ExamplesDir())
199194
pathsToExplore.Add(cfg.AppsDir())
200-
arduinoApps := []app.ArduinoApp{}
195+
usedByApps := []AppReference{}
201196

202197
for _, p := range pathsToExplore {
203198
res, err := p.ReadDirRecursiveFiltered(func(file *paths.Path) bool {
@@ -212,29 +207,19 @@ func getAppList(
212207

213208
if err != nil {
214209
slog.Error("unable to list apps", slog.String("error", err.Error()))
215-
return arduinoApps, err
210+
return usedByApps, err
216211
}
217212
appPaths.AddAllMissing(res)
218213
}
219214

220215
for _, file := range appPaths {
221216
app, err := app.Load(file.String())
222217
if err != nil {
223-
/* result.BrokenApps = append(result.BrokenApps, orchestrator.BrokenAppInfo{
224-
Name: file.Base(),
225-
Error: fmt.Sprintf("unable to parse the app.yaml: %s", err.Error()),
226-
})*/
218+
//we are not considering the borken apps
219+
slog.Warn("unable to parse app.yaml, skipping", "path", file.String(), "error", err.Error())
227220
continue
228221
}
229222

230-
arduinoApps = append(arduinoApps, app)
231-
}
232-
return arduinoApps, nil
233-
}
234-
235-
func getUsedByApps(apps []app.ArduinoApp, brickId string, idProvider *app.IDProvider) ([]AppReference, error) {
236-
usedByApps := []AppReference{}
237-
for _, app := range apps {
238223
for _, b := range app.Descriptor.Bricks {
239224
if b.ID == brickId {
240225
id, err := idProvider.IDFromPath(app.FullPath)

0 commit comments

Comments
 (0)