forked from redhat-developer/odo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select and pull a devfile using Alizer (redhat-developer#5464)
* Add alizer library and test functionality <!-- Thank you for opening a PR! Here are some things you need to know before submitting: 1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Developer-Guidelines 2. Label this PR accordingly with the '/kind' line 3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Writing-and-running-tests 4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/PR-Review Documentation: If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Contributing-to-Docs --> **What type of PR is this:** <!-- Add one of the following kinds: /kind bug /kind cleanup /kind tests /kind documentation Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well. --> /kind feature **What does this PR do / why we need it:** Adds the alizer library from https://github.com/redhat-developer/alizer/tree/main/go as part of our implementaion of `odo dev` and `odo init`. This builds upon @feloy 's PR located here: redhat-developer#5434 **Which issue(s) this PR fixes:** <!-- Specifying the issue will automatically close it when this PR is merged --> Fixes # **PR acceptance criteria:** - [X] Unit test - [X] Integration test - [X] Documentation **How to test changes / Special notes to the reviewer:** N/A. Only function implementation * New alizer version * Use alizer for odo init * Add integration tests * Add Alizer to odo deploy * review * Ask component name for odo deploy * Fix unit test Co-authored-by: Charlie Drage <[email protected]>
- Loading branch information
Showing
74 changed files
with
13,223 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package backend | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
"github.com/devfile/library/pkg/devfile/parser" | ||
"github.com/redhat-developer/alizer/go/pkg/apis/recognizer" | ||
"github.com/redhat-developer/odo/pkg/catalog" | ||
"github.com/redhat-developer/odo/pkg/init/asker" | ||
"github.com/redhat-developer/odo/pkg/testingutil/filesystem" | ||
) | ||
|
||
type AlizerBackend struct { | ||
askerClient asker.Asker | ||
catalogClient catalog.Client | ||
} | ||
|
||
func NewAlizerBackend(askerClient asker.Asker, catalogClient catalog.Client) *AlizerBackend { | ||
return &AlizerBackend{ | ||
askerClient: askerClient, | ||
catalogClient: catalogClient, | ||
} | ||
} | ||
|
||
func (o *AlizerBackend) Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error { | ||
return nil | ||
} | ||
|
||
// detectFramework uses the alizer library in order to detect the devfile | ||
// to use depending on the files in the path | ||
func (o *AlizerBackend) detectFramework(path string) (recognizer.DevFileType, catalog.Registry, error) { | ||
types := []recognizer.DevFileType{} | ||
components, err := o.catalogClient.ListDevfileComponents("") | ||
if err != nil { | ||
return recognizer.DevFileType{}, catalog.Registry{}, err | ||
} | ||
for _, component := range components.Items { | ||
types = append(types, recognizer.DevFileType{ | ||
Name: component.Name, | ||
Language: component.Language, | ||
ProjectType: component.ProjectType, | ||
Tags: component.Tags, | ||
}) | ||
} | ||
typ, err := recognizer.SelectDevFileFromTypes(path, types) | ||
if err != nil { | ||
return recognizer.DevFileType{}, catalog.Registry{}, err | ||
} | ||
|
||
// TODO(feloy): This part won't be necessary when SelectDevFileFromTypes returns the index | ||
var indexOfDetected int | ||
for i, typeFromList := range types { | ||
if reflect.DeepEqual(typeFromList, typ) { | ||
indexOfDetected = i | ||
break | ||
} | ||
} | ||
registry := components.Items[indexOfDetected].Registry | ||
return typ, registry, nil | ||
} | ||
|
||
// SelectDevfile calls thz Alizer to detect the devfile and asks for confirmation to the user | ||
func (o *AlizerBackend) SelectDevfile(flags map[string]string, fs filesystem.Filesystem, dir string) (location *DevfileLocation, err error) { | ||
selected, registry, err := o.detectFramework(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fmt.Printf("Based on the files in the current directory odo detected\nLanguage: %s\nProject type: %s\n", selected.Language, selected.ProjectType) | ||
fmt.Printf("The devfile %q from the registry %q will be downloaded.\n", selected.Name, registry.Name) | ||
confirm, err := o.askerClient.AskCorrect() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !confirm { | ||
return nil, nil | ||
} | ||
return &DevfileLocation{ | ||
Devfile: selected.Name, | ||
DevfileRegistry: registry.Name, | ||
}, nil | ||
} | ||
|
||
func (o *AlizerBackend) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string) (starter *v1alpha2.StarterProject, err error) { | ||
return nil, nil | ||
} | ||
|
||
func (o *AlizerBackend) PersonalizeName(devfile parser.DevfileObj, flags map[string]string) error { | ||
return nil | ||
} |
Oops, something went wrong.