Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Devfile Library Get Options #71

Merged
merged 5 commits into from
Mar 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address DevfileOptions feedback
Signed-off-by: Maysun J Faisal <[email protected]>
maysunfaisal committed Mar 17, 2021
commit 9b136b9484251b79dc37971bdec00082243caa15
6 changes: 5 additions & 1 deletion pkg/devfile/parser/data/v2/commands.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v2

import (
"reflect"
"strings"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
@@ -10,6 +11,10 @@ import (
// GetCommands returns the slice of Command objects parsed from the Devfile
func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, error) {

if reflect.DeepEqual(options, common.DevfileOptions{}) {
return d.Commands, nil
}

var commands []v1.Command
for _, command := range d.Commands {
// Filter Command Attributes
@@ -37,7 +42,6 @@ func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, er
continue
}

command.Id = strings.ToLower(command.Id)
commands = append(commands, command)
}

10 changes: 9 additions & 1 deletion pkg/devfile/parser/data/v2/commands_test.go
Original file line number Diff line number Diff line change
@@ -153,10 +153,18 @@ func TestDevfile200_GetCommands(t *testing.T) {
name: "Wrong command type",
currentCommands: []v1.Command{
{
Id: "command1",
Id: "command1",
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
"firstString": "firstStringValue",
}),
CommandUnion: v1.CommandUnion{},
},
},
filterOptions: common.DevfileOptions{
Filter: map[string]interface{}{
"firstString": "firstStringValue",
},
},
wantErr: true,
},
}
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/v2/common/project_helper.go
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ func GetDefaultSource(ps v1.GitLikeProjectSource) (remoteName string, remoteURL

}

// GetProjectSourceType returns the source type of a given project
// GetProjectSourceType returns the source type of a given project source
func GetProjectSourceType(projectSrc v1.ProjectSource) (v1.ProjectSourceType, error) {
switch {
case projectSrc.Git != nil:
12 changes: 10 additions & 2 deletions pkg/devfile/parser/data/v2/components.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package v2

import (
"reflect"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
)

// GetComponents returns the slice of Component objects parsed from the Devfile
func (d *DevfileV2) GetComponents(options common.DevfileOptions) ([]v1.Component, error) {

if reflect.DeepEqual(options, common.DevfileOptions{}) {
return d.Components, nil
}

var components []v1.Component
for _, component := range d.Components {
// Filter Component Attributes
@@ -33,7 +39,8 @@ func (d *DevfileV2) GetComponents(options common.DevfileOptions) ([]v1.Component
return components, nil
}

// GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components. Deprecated, use GetComponents() with the DevfileOptions.
// GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components.
// Deprecated, use GetComponents() with the DevfileOptions.
func (d *DevfileV2) GetDevfileContainerComponents(options common.DevfileOptions) ([]v1.Component, error) {
var components []v1.Component
devfileComponents, err := d.GetComponents(options)
@@ -48,7 +55,8 @@ func (d *DevfileV2) GetDevfileContainerComponents(options common.DevfileOptions)
return components, nil
}

// GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components. Deprecated, use GetComponents() with the DevfileOptions.
// GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components.
// Deprecated, use GetComponents() with the DevfileOptions.
func (d *DevfileV2) GetDevfileVolumeComponents(options common.DevfileOptions) ([]v1.Component, error) {
var components []v1.Component
devfileComponents, err := d.GetComponents(options)
10 changes: 9 additions & 1 deletion pkg/devfile/parser/data/v2/components_test.go
Original file line number Diff line number Diff line change
@@ -278,10 +278,18 @@ func TestGetDevfileComponents(t *testing.T) {
name: "Wrong component type",
component: []v1.Component{
{
Name: "comp1",
Name: "comp1",
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
"firstString": "firstStringValue",
}),
ComponentUnion: v1.ComponentUnion{},
},
},
filterOptions: common.DevfileOptions{
Filter: map[string]interface{}{
"firstString": "firstStringValue",
},
},
wantErr: true,
},
}
13 changes: 11 additions & 2 deletions pkg/devfile/parser/data/v2/projects.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v2

import (
"reflect"
"strings"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
@@ -9,8 +10,12 @@ import (

// GetProjects returns the Project Object parsed from devfile
func (d *DevfileV2) GetProjects(options common.DevfileOptions) ([]v1.Project, error) {
var projects []v1.Project

if reflect.DeepEqual(options, common.DevfileOptions{}) {
return d.Projects, nil
}

var projects []v1.Project
for _, project := range d.Projects {
// Filter Project Attributes
filterIn, err := common.FilterDevfileObject(project.Attributes, options)
@@ -80,8 +85,12 @@ func (d *DevfileV2) DeleteProject(name string) error {

//GetStarterProjects returns the DevfileStarterProject parsed from devfile
func (d *DevfileV2) GetStarterProjects(options common.DevfileOptions) ([]v1.StarterProject, error) {
var starterProjects []v1.StarterProject

if reflect.DeepEqual(options, common.DevfileOptions{}) {
return d.StarterProjects, nil
}

var starterProjects []v1.StarterProject
for _, starterProject := range d.StarterProjects {
// Filter Starter Project Attributes
filterIn, err := common.FilterDevfileObject(starterProject.Attributes, options)
24 changes: 20 additions & 4 deletions pkg/devfile/parser/data/v2/projects_test.go
Original file line number Diff line number Diff line change
@@ -111,13 +111,21 @@ func TestDevfile200_GetProjects(t *testing.T) {
wantErr: false,
},
{
name: "Wrong project type",
name: "Wrong project src type",
currentProjects: []v1.Project{
{
Name: "project1",
Name: "project1",
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
"firstString": "firstStringValue",
}),
ProjectSource: v1.ProjectSource{},
},
},
filterOptions: common.DevfileOptions{
Filter: map[string]interface{}{
"firstString": "firstStringValue",
},
},
wantErr: true,
},
}
@@ -493,13 +501,21 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
wantErr: false,
},
{
name: "Wrong starter project type",
name: "Wrong starter project src type",
currentStarterProjects: []v1.StarterProject{
{
Name: "project1",
Name: "project1",
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
"firstString": "firstStringValue",
}),
ProjectSource: v1.ProjectSource{},
},
},
filterOptions: common.DevfileOptions{
Filter: map[string]interface{}{
"firstString": "firstStringValue",
},
},
wantErr: true,
},
}