Code can be found here but pasting in here as well.
// You can edit this code!
// Click here and start typing.
package main
import (
"os"
"path/filepath"
)
func main() {
sourcePath := "foobar"
var repos []*config.GitRepo
var sourceRepos = make(map[string]*config.GitSource)
err := filepath.Walk(sourcePath,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
//some condition met.
repos = append(repos, newRepo)
if source, ok := sourceRepos[remoteURL]; ok {
sourceName = source.Name
} else {
newSource := &config.GitSource{
Name: slug.Make(remoteURL),
Uri: remoteURL,
}
if slices.Contains([]string{"master", "main"}, s.Name().String()) {
newSource.DefaultBranch = s.Name().String()
}
sourceName = newSource.Name
sourceRepos[remoteURL] = newSource
}
})
if err != nil {
// at this point, repos is valid, but sourceRepos is nil. Why is that?
}
return nil
}