Skip to content

Commit

Permalink
Clone sub project repos once (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Jun 24, 2020
1 parent 49708ea commit c24707e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions cmds/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,6 @@ func processSubProject(p api.Product, v api.ProductVersion, rootDir, vDir string
// create project version specific subfolder for the subprojects
tmpDir := filepath.Join(rootTempDir, p.Key+"-"+v.Version, spKey)
repoDir := filepath.Join(tmpDir, "repo")
err := os.MkdirAll(repoDir, 0755)
if err != nil {
return err
}

pfile := filepath.Join(rootDir, "data", "products", spKey+".json")
fmt.Println("using product_listing_file=", pfile)
Expand All @@ -679,14 +675,20 @@ func processSubProject(p api.Product, v api.ProductVersion, rootDir, vDir string
return err
}

err = os.MkdirAll(tmpDir, 0755)
if err != nil {
return err
}
if !exists(repoDir) {
err = sh.Command("git", "clone", sp.RepoURL, repoDir).Run()
if err != nil {
return err
}
}

for _, mapping := range info.Mappings {
if sets.NewString(mapping.Versions...).Has(v.Version) {

err = sh.Command("git", "clone", sp.RepoURL, repoDir).Run()
if err != nil {
return err
}

for _, spVersion := range mapping.SubProjectVersions {
spv, err := findVersion(sp.Versions, spVersion)
if err != nil {
Expand Down Expand Up @@ -855,3 +857,11 @@ func findVersion(versions []api.ProductVersion, x string) (api.ProductVersion, e
}
return api.ProductVersion{}, fmt.Errorf("version %s not found", x)
}

// exists reports whether the named file or directory Exists.
func exists(name string) bool {
if _, err := os.Stat(name); os.IsNotExist(err) {
return false
}
return true
}

0 comments on commit c24707e

Please sign in to comment.