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

feat: added license related changes from metadata #213

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions api/v1/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ service ProjectService {
}

message GenerateCodeRequest {
string projectVersion = 1;
string compageCoreVersion = 1;
string projectName = 2;
string projectJSON = 3;
string gitRepositoryName = 4;
string gitPlatformName = 5;
string gitPlatformURL = 6;
string gitPlatformUserName = 7;
string projectMetadata = 8;
string projectMetadata = 4;
string gitRepositoryName = 5;
string gitPlatformName = 6;
string gitPlatformURL = 7;
string gitPlatformUserName = 8;
}

message GenerateCodeResponse{
Expand Down
2 changes: 1 addition & 1 deletion cmd/dotnet-config.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: {{.ProjectName}}
version: v1.0.0
compageCoreVersion: v1.0.0
git:
repository:
name: {{.GitRepositoryName}}
Expand Down
72 changes: 57 additions & 15 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
ociregistry "github.com/intelops/compage/cmd/artifacts"
"github.com/intelops/compage/cmd/models"
"github.com/intelops/compage/internal/converter/cmd"
Expand Down Expand Up @@ -62,38 +63,79 @@
return err
}

if len(coreProject.License.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err := filepath.Abs(coreProject.License.Path)
if err != nil {
log.Errorf("error while getting absolute path [" + err.Error() + "]")
return err
if project.Metadata != nil {
license := &models.License{}
l, ok := project.Metadata["license"]
if ok {

Check warning on line 69 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L66-L69

Added lines #L66 - L69 were not covered by tests
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
return err1

Check warning on line 74 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L71-L74

Added lines #L71 - L74 were not covered by tests
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
return err1

Check warning on line 80 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L77-L80

Added lines #L77 - L80 were not covered by tests
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {

Check warning on line 83 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L83

Added line #L83 was not covered by tests
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
return err2

Check warning on line 88 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L85-L88

Added lines #L85 - L88 were not covered by tests
}
license.Path = absPath

Check warning on line 90 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L90

Added line #L90 was not covered by tests
}
project.Metadata["license"] = license
} else {
log.Warn("license data not found in project metadata")

Check warning on line 94 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L92-L94

Added lines #L92 - L94 were not covered by tests
}
coreProject.License.Path = absPath
}

// assign absolute path to the license file path if it's not (if supplied for the nodes)
for _, node := range coreProject.CompageJSON.Nodes {
if len(node.License.Path) > 0 {
absPath, err := filepath.Abs(node.License.Path)
if err != nil {
log.Errorf("error while getting absolute path [" + err.Error() + "]")
return err
license := &models.License{}
l, ok := node.Metadata["license"]
if ok {

Check warning on line 102 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L100-L102

Added lines #L100 - L102 were not covered by tests
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
return err1

Check warning on line 107 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L104-L107

Added lines #L104 - L107 were not covered by tests
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
return err1

Check warning on line 113 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L110-L113

Added lines #L110 - L113 were not covered by tests
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {

Check warning on line 116 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L116

Added line #L116 was not covered by tests
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
return err2

Check warning on line 121 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L118-L121

Added lines #L118 - L121 were not covered by tests
}
license.Path = absPath

Check warning on line 123 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L123

Added line #L123 was not covered by tests
}
node.License.Path = absPath
node.Metadata["license"] = license

Check warning on line 125 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L125

Added line #L125 was not covered by tests
}
}

// pull all required templates
// pull the common templates
err = ociregistry.PullOCIArtifact("common", project.Version)
err = ociregistry.PullOCIArtifact("common", project.CompageCoreVersion)

Check warning on line 131 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L131

Added line #L131 was not covered by tests
if err != nil {
log.Errorf("error while pulling the common templates [" + err.Error() + "]")
return err
}
for _, node := range coreProject.CompageJSON.Nodes {
// make sure that the latest template is pulled
err = ociregistry.PullOCIArtifact(node.Language, project.Version)
err = ociregistry.PullOCIArtifact(node.Language, project.CompageCoreVersion)

Check warning on line 138 in cmd/generate.go

View check run for this annotation

Codecov / codecov/patch

cmd/generate.go#L138

Added line #L138 was not covered by tests
if err != nil {
log.Errorf("error while pulling the template [" + err.Error() + "]")
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-config.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: {{.ProjectName}}
version: v1.0.0
compageCoreVersion: v1.0.0
git:
repository:
name: {{.GitRepositoryName}}
Expand Down
17 changes: 8 additions & 9 deletions cmd/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ type GitDetails struct {
}

type License struct {
Name string `yaml:"name,omitempty"`
URL string `yaml:"url,omitempty"`
Path string `yaml:"path,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
URL string `yaml:"url,omitempty" json:"url,omitempty"`
Path string `yaml:"path,omitempty" json:"path,omitempty"`
}

type Project struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
License License `yaml:"license"`
GitDetails GitDetails `yaml:"git"`
CompageJSON map[string]interface{} `yaml:"compageJSON"`
ProjectMetadata string `yaml:"projectMetadata"`
Name string `yaml:"name"`
CompageCoreVersion string `yaml:"compageCoreVersion"`
GitDetails GitDetails `yaml:"git"`
CompageJSON map[string]interface{} `yaml:"compageJSON"`
Metadata map[string]interface{} `yaml:"metadata"`
}

func ReadConfigYAMLFile(configFile string) (*Project, error) {
Expand Down
29 changes: 17 additions & 12 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,33 @@

// this will be the version same as release (as the version is not configurable from the ui)
// for local development, you can set the version in the environment variable
version := os.Getenv("COMPAGE_CORE_VERSION")
if version == "" {
compageCoreVersion := os.Getenv("COMPAGE_CORE_VERSION")
if compageCoreVersion == "" {

Check warning on line 56 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L55-L56

Added lines #L55 - L56 were not covered by tests
// default version
version = "v1.0.0"
compageCoreVersion = "v1.0.0"
err := os.Setenv("COMPAGE_CORE_VERSION", compageCoreVersion)
if err != nil {
log.Errorf("error while setting environment variable COMPAGE_CORE_VERSION [%v]", err)
return

Check warning on line 62 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L58-L62

Added lines #L58 - L62 were not covered by tests
}
}
err := ociregistry.PullOCIArtifact("common", version)
err := ociregistry.PullOCIArtifact("common", compageCoreVersion)

Check warning on line 65 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L65

Added line #L65 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("go", version)
err = ociregistry.PullOCIArtifact("go", compageCoreVersion)

Check warning on line 67 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L67

Added line #L67 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("python", version)
err = ociregistry.PullOCIArtifact("python", compageCoreVersion)

Check warning on line 69 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L69

Added line #L69 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("java", version)
err = ociregistry.PullOCIArtifact("java", compageCoreVersion)

Check warning on line 71 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L71

Added line #L71 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("javascript", version)
err = ociregistry.PullOCIArtifact("javascript", compageCoreVersion)

Check warning on line 73 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L73

Added line #L73 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("ruby", version)
err = ociregistry.PullOCIArtifact("ruby", compageCoreVersion)

Check warning on line 75 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L75

Added line #L75 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("rust", version)
err = ociregistry.PullOCIArtifact("rust", compageCoreVersion)

Check warning on line 77 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L77

Added line #L77 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("typescript", version)
err = ociregistry.PullOCIArtifact("typescript", compageCoreVersion)

Check warning on line 79 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L79

Added line #L79 was not covered by tests
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("dotnet", version)
err = ociregistry.PullOCIArtifact("dotnet", compageCoreVersion)

Check warning on line 81 in cmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/start.go#L81

Added line #L81 was not covered by tests
cobra.CheckErr(err)

// check if the language templates have been pulled (mainly need to check this on developer's machine)
Expand Down
112 changes: 56 additions & 56 deletions gen/api/v1/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions internal/converter/cmd/converter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"github.com/intelops/compage/internal/converter"
log "github.com/sirupsen/logrus"
"time"

"github.com/intelops/compage/cmd/models"
"github.com/intelops/compage/internal/converter"
"github.com/intelops/compage/internal/core"
)

Expand All @@ -20,14 +20,13 @@
return &core.Project{
CompageJSON: compageJSON,
Name: input.Name,
Version: input.Version,
License: &input.License,
CompageCoreVersion: input.CompageCoreVersion,

Check warning on line 23 in internal/converter/cmd/converter.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/cmd/converter.go#L23

Added line #L23 was not covered by tests
GitPlatformName: input.GitDetails.Platform.Name,
GitPlatformURL: input.GitDetails.Platform.URL,
GitPlatformUserName: input.GitDetails.Platform.UserName,
GitRepositoryName: input.GitDetails.Repository.Name,
GitRepositoryURL: input.GitDetails.Repository.URL,
Metadata: converter.GetMetadata(input.ProjectMetadata),
Metadata: input.Metadata,

Check warning on line 29 in internal/converter/cmd/converter.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/cmd/converter.go#L29

Added line #L29 was not covered by tests
ModificationDetails: core.ModificationDetails{
CreatedBy: input.GitDetails.Platform.UserName,
UpdatedBy: input.GitDetails.Platform.UserName,
Expand Down
Loading
Loading