Skip to content

Commit 8728f7d

Browse files
Merge pull request #213 from intelops/add-license-related-changes
feat: added license related changes from metadata
2 parents e32c008 + 124efc2 commit 8728f7d

File tree

27 files changed

+278
-159
lines changed

27 files changed

+278
-159
lines changed

api/v1/project.proto

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ service ProjectService {
99
}
1010

1111
message GenerateCodeRequest {
12-
string projectVersion = 1;
12+
string compageCoreVersion = 1;
1313
string projectName = 2;
1414
string projectJSON = 3;
15-
string gitRepositoryName = 4;
16-
string gitPlatformName = 5;
17-
string gitPlatformURL = 6;
18-
string gitPlatformUserName = 7;
19-
string projectMetadata = 8;
15+
string projectMetadata = 4;
16+
string gitRepositoryName = 5;
17+
string gitPlatformName = 6;
18+
string gitPlatformURL = 7;
19+
string gitPlatformUserName = 8;
2020
}
2121

2222
message GenerateCodeResponse{

cmd/dotnet-config.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: {{.ProjectName}}
2-
version: v1.0.0
2+
compageCoreVersion: v1.0.0
33
git:
44
repository:
55
name: {{.GitRepositoryName}}

cmd/generate.go

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
ociregistry "github.com/intelops/compage/cmd/artifacts"
56
"github.com/intelops/compage/cmd/models"
67
"github.com/intelops/compage/internal/converter/cmd"
@@ -62,38 +63,79 @@ func GenerateCode() error {
6263
return err
6364
}
6465

65-
if len(coreProject.License.Path) > 0 {
66-
// assign absolute path to the license file Path if it's not
67-
absPath, err := filepath.Abs(coreProject.License.Path)
68-
if err != nil {
69-
log.Errorf("error while getting absolute path [" + err.Error() + "]")
70-
return err
66+
if project.Metadata != nil {
67+
license := &models.License{}
68+
l, ok := project.Metadata["license"]
69+
if ok {
70+
// convert the license data to byte array
71+
licenseData, err1 := json.Marshal(l)
72+
if err1 != nil {
73+
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
74+
return err1
75+
}
76+
// convert the license data to license struct
77+
err1 = json.Unmarshal(licenseData, license)
78+
if err1 != nil {
79+
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
80+
return err1
81+
}
82+
// assign absolute path to the license file Path if it's not set
83+
if len(license.Path) > 0 {
84+
// assign absolute path to the license file Path if it's not
85+
absPath, err2 := filepath.Abs(license.Path)
86+
if err2 != nil {
87+
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
88+
return err2
89+
}
90+
license.Path = absPath
91+
}
92+
project.Metadata["license"] = license
93+
} else {
94+
log.Warn("license data not found in project metadata")
7195
}
72-
coreProject.License.Path = absPath
7396
}
7497

7598
// assign absolute path to the license file path if it's not (if supplied for the nodes)
7699
for _, node := range coreProject.CompageJSON.Nodes {
77-
if len(node.License.Path) > 0 {
78-
absPath, err := filepath.Abs(node.License.Path)
79-
if err != nil {
80-
log.Errorf("error while getting absolute path [" + err.Error() + "]")
81-
return err
100+
license := &models.License{}
101+
l, ok := node.Metadata["license"]
102+
if ok {
103+
// convert the license data to byte array
104+
licenseData, err1 := json.Marshal(l)
105+
if err1 != nil {
106+
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
107+
return err1
108+
}
109+
// convert the license data to license struct
110+
err1 = json.Unmarshal(licenseData, license)
111+
if err1 != nil {
112+
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
113+
return err1
114+
}
115+
// assign absolute path to the license file Path if it's not set
116+
if len(license.Path) > 0 {
117+
// assign absolute path to the license file Path if it's not
118+
absPath, err2 := filepath.Abs(license.Path)
119+
if err2 != nil {
120+
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
121+
return err2
122+
}
123+
license.Path = absPath
82124
}
83-
node.License.Path = absPath
125+
node.Metadata["license"] = license
84126
}
85127
}
86128

87129
// pull all required templates
88130
// pull the common templates
89-
err = ociregistry.PullOCIArtifact("common", project.Version)
131+
err = ociregistry.PullOCIArtifact("common", project.CompageCoreVersion)
90132
if err != nil {
91133
log.Errorf("error while pulling the common templates [" + err.Error() + "]")
92134
return err
93135
}
94136
for _, node := range coreProject.CompageJSON.Nodes {
95137
// make sure that the latest template is pulled
96-
err = ociregistry.PullOCIArtifact(node.Language, project.Version)
138+
err = ociregistry.PullOCIArtifact(node.Language, project.CompageCoreVersion)
97139
if err != nil {
98140
log.Errorf("error while pulling the template [" + err.Error() + "]")
99141
return err

cmd/go-config.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: {{.ProjectName}}
2-
version: v1.0.0
2+
compageCoreVersion: v1.0.0
33
git:
44
repository:
55
name: {{.GitRepositoryName}}

cmd/models/config.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ type GitDetails struct {
2323
}
2424

2525
type License struct {
26-
Name string `yaml:"name,omitempty"`
27-
URL string `yaml:"url,omitempty"`
28-
Path string `yaml:"path,omitempty"`
26+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
27+
URL string `yaml:"url,omitempty" json:"url,omitempty"`
28+
Path string `yaml:"path,omitempty" json:"path,omitempty"`
2929
}
3030

3131
type Project struct {
32-
Name string `yaml:"name"`
33-
Version string `yaml:"version"`
34-
License License `yaml:"license"`
35-
GitDetails GitDetails `yaml:"git"`
36-
CompageJSON map[string]interface{} `yaml:"compageJSON"`
37-
ProjectMetadata string `yaml:"projectMetadata"`
32+
Name string `yaml:"name"`
33+
CompageCoreVersion string `yaml:"compageCoreVersion"`
34+
GitDetails GitDetails `yaml:"git"`
35+
CompageJSON map[string]interface{} `yaml:"compageJSON"`
36+
Metadata map[string]interface{} `yaml:"metadata"`
3837
}
3938

4039
func ReadConfigYAMLFile(configFile string) (*Project, error) {

cmd/start.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,33 @@ This command will start thr gRPC server and allow the gRPC clients to get connec
5252

5353
// this will be the version same as release (as the version is not configurable from the ui)
5454
// for local development, you can set the version in the environment variable
55-
version := os.Getenv("COMPAGE_CORE_VERSION")
56-
if version == "" {
55+
compageCoreVersion := os.Getenv("COMPAGE_CORE_VERSION")
56+
if compageCoreVersion == "" {
5757
// default version
58-
version = "v1.0.0"
58+
compageCoreVersion = "v1.0.0"
59+
err := os.Setenv("COMPAGE_CORE_VERSION", compageCoreVersion)
60+
if err != nil {
61+
log.Errorf("error while setting environment variable COMPAGE_CORE_VERSION [%v]", err)
62+
return
63+
}
5964
}
60-
err := ociregistry.PullOCIArtifact("common", version)
65+
err := ociregistry.PullOCIArtifact("common", compageCoreVersion)
6166
cobra.CheckErr(err)
62-
err = ociregistry.PullOCIArtifact("go", version)
67+
err = ociregistry.PullOCIArtifact("go", compageCoreVersion)
6368
cobra.CheckErr(err)
64-
err = ociregistry.PullOCIArtifact("python", version)
69+
err = ociregistry.PullOCIArtifact("python", compageCoreVersion)
6570
cobra.CheckErr(err)
66-
err = ociregistry.PullOCIArtifact("java", version)
71+
err = ociregistry.PullOCIArtifact("java", compageCoreVersion)
6772
cobra.CheckErr(err)
68-
err = ociregistry.PullOCIArtifact("javascript", version)
73+
err = ociregistry.PullOCIArtifact("javascript", compageCoreVersion)
6974
cobra.CheckErr(err)
70-
err = ociregistry.PullOCIArtifact("ruby", version)
75+
err = ociregistry.PullOCIArtifact("ruby", compageCoreVersion)
7176
cobra.CheckErr(err)
72-
err = ociregistry.PullOCIArtifact("rust", version)
77+
err = ociregistry.PullOCIArtifact("rust", compageCoreVersion)
7378
cobra.CheckErr(err)
74-
err = ociregistry.PullOCIArtifact("typescript", version)
79+
err = ociregistry.PullOCIArtifact("typescript", compageCoreVersion)
7580
cobra.CheckErr(err)
76-
err = ociregistry.PullOCIArtifact("dotnet", version)
81+
err = ociregistry.PullOCIArtifact("dotnet", compageCoreVersion)
7782
cobra.CheckErr(err)
7883

7984
// check if the language templates have been pulled (mainly need to check this on developer's machine)

gen/api/v1/project.pb.go

Lines changed: 56 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/converter/cmd/converter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package cmd
22

33
import (
4+
"github.com/intelops/compage/internal/converter"
45
log "github.com/sirupsen/logrus"
56
"time"
67

78
"github.com/intelops/compage/cmd/models"
8-
"github.com/intelops/compage/internal/converter"
99
"github.com/intelops/compage/internal/core"
1010
)
1111

@@ -20,14 +20,13 @@ func GetProject(input *models.Project) (*core.Project, error) {
2020
return &core.Project{
2121
CompageJSON: compageJSON,
2222
Name: input.Name,
23-
Version: input.Version,
24-
License: &input.License,
23+
CompageCoreVersion: input.CompageCoreVersion,
2524
GitPlatformName: input.GitDetails.Platform.Name,
2625
GitPlatformURL: input.GitDetails.Platform.URL,
2726
GitPlatformUserName: input.GitDetails.Platform.UserName,
2827
GitRepositoryName: input.GitDetails.Repository.Name,
2928
GitRepositoryURL: input.GitDetails.Repository.URL,
30-
Metadata: converter.GetMetadata(input.ProjectMetadata),
29+
Metadata: input.Metadata,
3130
ModificationDetails: core.ModificationDetails{
3231
CreatedBy: input.GitDetails.Platform.UserName,
3332
UpdatedBy: input.GitDetails.Platform.UserName,

0 commit comments

Comments
 (0)