Skip to content

Commit

Permalink
Fix regression by sparse checkout dir PR (#3258)
Browse files Browse the repository at this point in the history
fix regression caused by rebase to master.
Also add github, zip as supported project types.
  • Loading branch information
Aditi Sharma committed May 28, 2020
1 parent b50c52c commit b6e6243
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
49 changes: 34 additions & 15 deletions pkg/devfile/parser/data/1.0.0/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ func (d *Devfile100) GetProjects() []common.DevfileProject {

var projects []common.DevfileProject
for _, v := range d.Projects {
// We are only supporting ProjectType git in V1
if v.Source.Type == ProjectTypeGit {
projects = append(projects, convertV1ProjectToCommon(v))
}
projects = append(projects, convertV1ProjectToCommon(v))

}

return projects
Expand Down Expand Up @@ -166,21 +164,42 @@ func convertV1VolumeToCommon(v DockerimageVolume) common.VolumeMount {
}

func convertV1ProjectToCommon(p Project) common.DevfileProject {
var project = common.DevfileProject{
ClonePath: p.ClonePath,
Name: p.Name,
}

switch p.Source.Type {
case ProjectTypeGit:
git := common.Git{
Branch: p.Source.Branch,
Location: p.Source.Location,
SparseCheckoutDir: p.Source.SparseCheckoutDir,
StartPoint: p.Source.StartPoint,
}

git := common.Git{
Branch: p.Source.Branch,
Location: p.Source.Location,
SparseCheckoutDir: p.Source.SparseCheckoutDir,
StartPoint: p.Source.StartPoint,
}
project.Git = &git

case ProjectTypeGitHub:
github := common.Github{
Branch: p.Source.Branch,
Location: p.Source.Location,
SparseCheckoutDir: p.Source.SparseCheckoutDir,
StartPoint: p.Source.StartPoint,
}
project.Github = &github

case ProjectTypeZip:
zip := common.Zip{
Location: p.Source.Location,
SparseCheckoutDir: p.Source.SparseCheckoutDir,
}
project.Zip = &zip

return common.DevfileProject{
ClonePath: p.ClonePath,
Git: &git,
Name: p.Name,
SourceType: common.GitProjectSourceType,
}

return project

}

func getGroup(name string) *common.Group {
Expand Down
4 changes: 3 additions & 1 deletion pkg/devfile/parser/data/1.0.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type Devfile100 struct {
type ProjectType string

const (
ProjectTypeGit ProjectType = "git"
ProjectTypeGit ProjectType = "git"
ProjectTypeGitHub ProjectType = "github"
ProjectTypeZip ProjectType = "zip"
)

var SupportedProjectTypes = []ProjectType{ProjectTypeGit}
Expand Down
18 changes: 7 additions & 11 deletions pkg/odo/cli/component/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,14 @@ func (co *CreateOptions) downloadProject(projectPassed string) error {
return err
}

var url string
var url, sparseDir string
if project.Git != nil {
if strings.Contains(project.Git.Location, "github.com") {
url, err = util.GetGitHubZipURL(project.Git.Location)
if err != nil {
return err
}
sparseDir = project.Git.SparseCheckoutDir
} else {
return errors.Errorf("Project type git with non github url not supported")
}
Expand All @@ -785,13 +786,15 @@ func (co *CreateOptions) downloadProject(projectPassed string) error {
if err != nil {
return err
}
sparseDir = project.Github.SparseCheckoutDir
} else if project.Zip != nil {
url = project.Zip.Location
sparseDir = project.Github.SparseCheckoutDir
} else {
return errors.Errorf("Project type not supported")
}

err = checkoutProject(project, url, path)
err = checkoutProject(sparseDir, url, path)

if err != nil {
return err
Expand Down Expand Up @@ -904,15 +907,8 @@ func ensureAndLogProperResourceUsage(resource, resourceMin, resourceMax, resourc
}
}

func checkoutProject(project common.DevfileProject, zipURL, path string) error {
var sparseCheckoutDir string
if project.Git.SparseCheckoutDir != "" {
sparseCheckoutDir = project.Git.SparseCheckoutDir
} else if project.Github.SparseCheckoutDir != "" {
sparseCheckoutDir = project.Github.SparseCheckoutDir
} else if project.Zip.SparseCheckoutDir != "" {
sparseCheckoutDir = project.Zip.SparseCheckoutDir
}
func checkoutProject(sparseCheckoutDir, zipURL, path string) error {

if sparseCheckoutDir != "" {
err := util.GetAndExtractZip(zipURL, path, sparseCheckoutDir)
if err != nil {
Expand Down

0 comments on commit b6e6243

Please sign in to comment.