MCPcopy Index your code
hub / github.com/coder/coder / discoverDevcontainersInProject

Method discoverDevcontainersInProject

agent/agentcontainers/api.go:481–575  ·  view source on GitHub ↗
(projectPath string)

Source from the content-addressed store, hash-verified

479}
480
481func (api *API) discoverDevcontainersInProject(projectPath string) error {
482 logger := api.logger.
483 Named("project-discovery").
484 With(slog.F("project_path", projectPath))
485
486 globalPatterns, err := ignore.LoadGlobalPatterns(api.fs)
487 if err != nil {
488 return xerrors.Errorf("read global git ignore patterns: %w", err)
489 }
490
491 patterns, err := ignore.ReadPatterns(api.ctx, logger, api.fs, projectPath)
492 if err != nil {
493 return xerrors.Errorf("read git ignore patterns: %w", err)
494 }
495
496 matcher := gitignore.NewMatcher(append(globalPatterns, patterns...))
497
498 devcontainerConfigPaths := []string{
499 "/.devcontainer/devcontainer.json",
500 "/.devcontainer.json",
501 }
502
503 return afero.Walk(api.fs, projectPath, func(path string, info fs.FileInfo, err error) error {
504 if err != nil {
505 logger.Error(api.ctx, "encountered error while walking for dev container projects",
506 slog.F("path", path),
507 slog.Error(err))
508 return nil
509 }
510
511 pathParts := ignore.FilePathToParts(path)
512
513 // We know that a directory entry cannot be a `devcontainer.json` file, so we
514 // always skip processing directories. If the directory happens to be ignored
515 // by git then we'll make sure to ignore all of the children of that directory.
516 if info.IsDir() {
517 if matcher.Match(pathParts, true) {
518 return fs.SkipDir
519 }
520
521 return nil
522 }
523
524 if matcher.Match(pathParts, false) {
525 return nil
526 }
527
528 for _, relativeConfigPath := range devcontainerConfigPaths {
529 if !strings.HasSuffix(path, relativeConfigPath) {
530 continue
531 }
532
533 workspaceFolder := strings.TrimSuffix(path, relativeConfigPath)
534
535 logger := logger.With(slog.F("workspace_folder", workspaceFolder))
536 logger.Debug(api.ctx, "discovered dev container project")
537
538 api.mu.Lock()

Callers 1

Calls 14

CreateDevcontainerMethod · 0.95
LoadGlobalPatternsFunction · 0.92
ReadPatternsFunction · 0.92
FilePathToPartsFunction · 0.92
NamedMethod · 0.80
MatchMethod · 0.80
GoMethod · 0.80
NewMethod · 0.65
ReadConfigMethod · 0.65
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected