Skip to content

Commit 68b6bb1

Browse files
fix: end-to-end test cases
1 parent e8ba7d3 commit 68b6bb1

File tree

14 files changed

+168
-136
lines changed

14 files changed

+168
-136
lines changed

app/protobufs/project.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ service ProjectService {
1010

1111
message GenerateCodeRequest {
1212
string projectName = 1;
13-
string projectJson = 2;
13+
string projectJSON = 2;
1414
string gitRepositoryName = 3;
1515
string gitPlatformName = 4;
1616
string gitPlatformURL = 5;

app/setup/ddl.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ CREATE TABLE IF NOT EXISTS compage.projects
6161
owner_email TEXT,
6262
json TEXT,
6363
metadata TEXT,
64+
old_versions TEXT,
6465
git_platform_user_name TEXT,
6566
git_platform_name TEXT,
6667
repository_name TEXT,

app/src/models/code.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ export interface CompageJson {
112112
// grpc client request
113113
export interface Project {
114114
projectName: string;
115-
userName: string;
116-
json: string;
115+
projectJSON: string;
117116
gitRepositoryName: string;
118117
gitRepositoryIsPublic: boolean;
119118
gitRepositoryBranch: string;

app/src/models/project.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export interface ProjectEntity {
88
version: string;
99
owner_email: string;
1010
json: string;
11-
metadata?: string;
11+
metadata: string;
1212
git_platform_user_name: string;
1313
git_platform_name: string;
1414
repository_name: string;
1515
repository_branch: string;
1616
is_repository_public: boolean;
1717
repository_url: string;
18-
old_versions?: string[];
18+
old_versions: string[];
1919
created_at?: string;
2020
updated_at?: string;
2121
}
@@ -116,6 +116,10 @@ export const getListProjectsResponse = (projectEntities: ProjectEntity[]) => {
116116
repositoryBranch: projectEntity.repository_branch,
117117
isRepositoryPublic: projectEntity.is_repository_public,
118118
repositoryUrl: projectEntity.repository_url,
119+
metadata: JSON.parse(projectEntity.metadata),
120+
oldVersions: projectEntity.old_versions ? projectEntity.old_versions.map((oldVersion) => {
121+
return JSON.parse(oldVersion);
122+
}) : [],
119123
};
120124
projectDTOs.push(projectDTO);
121125
});
@@ -137,6 +141,10 @@ export const getProjectEntity = (projectDTO: ProjectDTO) => {
137141
repository_branch: projectDTO.repositoryBranch,
138142
is_repository_public: projectDTO.isRepositoryPublic,
139143
repository_url: projectDTO.repositoryUrl,
144+
metadata: JSON.stringify(projectDTO.metadata),
145+
old_versions: projectDTO.oldVersions ? projectDTO.oldVersions.map((oldVersion) => {
146+
return JSON.stringify(oldVersion);
147+
}) : [],
140148
};
141149
return projectEntity;
142150
};

app/src/routes/codeOperations.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const gitPlatformService = new GitPlatformService();
2525

2626
// generateCode (grpc calls to core)
2727
codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, resource) => {
28-
// TODO the below || op is not required, as the check is already done in middleware.
2928
const ownerEmail = request.header(X_EMAIL_HEADER) || '';
3029
const generateCodeRequest: GenerateCodeRequest = request.body;
3130
const projectId = generateCodeRequest.projectId;
@@ -90,6 +89,9 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
9089
const originalProjectPath = `${os.tmpdir()}/${projectEntity.display_name}`;
9190
const downloadedProjectPath = `${originalProjectPath}_downloaded`;
9291
try {
92+
if (fs.existsSync(downloadedProjectPath)) {
93+
cleanup(downloadedProjectPath);
94+
}
9395
fs.mkdirSync(downloadedProjectPath, {recursive: true});
9496
} catch (err: any) {
9597
if (err.code !== 'EEXIST') {
@@ -101,16 +103,15 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
101103
fs.mkdirSync(downloadedProjectPath, {recursive: true});
102104
}
103105
}
104-
const projectTarFilePath = `${downloadedProjectPath}/${projectEntity.id}_downloaded.tar.gz`;
106+
const projectTarFilePath = `${downloadedProjectPath}_downloaded.tar.gz`;
105107

106108
const gitPlatformEntity: GitPlatformEntity = await gitPlatformService.getGitPlatform(projectEntity.owner_email as string, projectEntity.git_platform_name as string);
107109

108110
// save project metadata (in compage db or somewhere)
109111
// need to save project-name, compage-json version, github repo and latest commit to the db
110112
const payload: Project = {
111113
projectName: projectEntity.display_name,
112-
userName: projectEntity.git_platform_user_name,
113-
json: projectEntity.json,
114+
projectJSON: projectEntity.json,
114115
gitRepositoryName: projectEntity.repository_name,
115116
metadata: projectEntity.metadata as string,
116117
gitRepositoryIsPublic: projectEntity.is_repository_public,
@@ -168,7 +169,7 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
168169
},
169170
projectVersion: projectEntity.version,
170171
generatedProjectPath: `${downloadedProjectPath}` + `${originalProjectPath}`,
171-
existingProject: `${downloadedProjectPath}/projectEntity.repository_name`,
172+
existingProject: `${downloadedProjectPath}/${projectEntity.display_name}`,
172173
};
173174

174175
let error: string = await cloneExistingProjectFromGitServer(existingProjectGitServerRequest);
@@ -192,8 +193,8 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
192193
Logger.debug(`saved ${downloadedProjectPath} to github.`);
193194
cleanup(downloadedProjectPath);
194195

195-
// update status in k8s
196-
const metadata = JSON.parse(projectEntity.metadata as string);
196+
// update status of projectEntity
197+
const metadata = JSON.parse(projectEntity.metadata as string) || new Map<string, string>();
197198
metadata.isGenerated = true;
198199
metadata.version = projectEntity.version;
199200
// add metadata back to projectEntity.spec
@@ -207,6 +208,8 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
207208
projectEntity.version = nextVersion(projectEntity.version);
208209
projectEntity.old_versions.push(JSON.stringify(oldVersion));
209210
}
211+
console.log("projectEntity", projectEntity);
212+
210213
const isUpdated = await projectService.updateProject(projectId, projectEntity);
211214
if (isUpdated) {
212215
// send status back to ui

app/src/store/cassandraProjectDaoImpl.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {generateProjectId} from '../utils/utils';
2-
import {ProjectEntity} from '../models/project';
2+
import {OldVersion, ProjectEntity} from '../models/project';
33
import {cassandraClient} from './cassandra/cassandraClient';
44

55
import {ProjectDao} from './projectDao';
@@ -10,9 +10,11 @@ export class CassandraProjectDaoImpl implements ProjectDao {
1010
const query = `INSERT INTO projects (id, display_name, version, json, git_platform_name, git_platform_user_name,
1111
is_repository_public, repository_branch, repository_name, owner_email,
1212
repository_url,
13+
metadata,
14+
old_versions,
1315
created_at, updated_at)
14-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) IF NOT EXISTS`;
15-
const params = [projectEntity.id, projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.git_platform_name, projectEntity.git_platform_user_name, projectEntity.is_repository_public, projectEntity.repository_branch, projectEntity.repository_name, projectEntity.owner_email, projectEntity.repository_url, projectEntity.created_at, projectEntity.updated_at];
16+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) IF NOT EXISTS`;
17+
const params = [projectEntity.id, projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.git_platform_name, projectEntity.git_platform_user_name, projectEntity.is_repository_public, projectEntity.repository_branch, projectEntity.repository_name, projectEntity.owner_email, projectEntity.repository_url, projectEntity.metadata, projectEntity.created_at, projectEntity.updated_at];
1618
const resultSet = await cassandraClient.execute(query, params, {prepare: true});
1719
if (resultSet.wasApplied()) {
1820
return projectEntity;
@@ -29,6 +31,8 @@ export class CassandraProjectDaoImpl implements ProjectDao {
2931
repository_name: '',
3032
repository_url: '',
3133
owner_email: '',
34+
metadata: '',
35+
old_versions: [],
3236
created_at: '',
3337
updated_at: '',
3438
};
@@ -55,6 +59,10 @@ export class CassandraProjectDaoImpl implements ProjectDao {
5559
json: row.json,
5660
owner_email: row.owner_email,
5761
repository_url: row.repository_url,
62+
metadata: row.metadata,
63+
old_versions: row.old_versions ? row.old_versions.map((oldVersion: OldVersion) => {
64+
return oldVersion;
65+
}) : [],
5866
created_at: row.created_at,
5967
updated_at: row.updated_at,
6068
};
@@ -84,6 +92,8 @@ export class CassandraProjectDaoImpl implements ProjectDao {
8492
repository_name: '',
8593
repository_url: '',
8694
owner_email: '',
95+
metadata: '',
96+
old_versions: [],
8797
created_at: '',
8898
updated_at: '',
8999
};
@@ -101,6 +111,10 @@ export class CassandraProjectDaoImpl implements ProjectDao {
101111
json: row.json,
102112
repository_url: row.repository_url,
103113
owner_email: row.owner_email,
114+
metadata: row.metadata,
115+
old_versions: row.old_versions ? row.old_versions.map((oldVersion: OldVersion) => {
116+
return oldVersion;
117+
}) : [],
104118
created_at: row.created_at,
105119
updated_at: row.updated_at,
106120
};
@@ -111,9 +125,11 @@ export class CassandraProjectDaoImpl implements ProjectDao {
111125
SET display_name = ?,
112126
version = ?,
113127
json = ?,
128+
metadata = ?,
129+
old_versions = ?,
114130
updated_at = ?
115131
WHERE id = ? IF EXISTS`;
116-
const params = [projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.updated_at, id];
132+
const params = [projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.metadata, projectEntity.old_versions, projectEntity.updated_at, id];
117133
const resultSet = await cassandraClient.execute(query, params, {prepare: true});
118134
return resultSet.wasApplied();
119135
}

app/src/store/sqlite/sqliteClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ db.run(`
2525
owner_email TEXT,
2626
json TEXT,
2727
metadata TEXT,
28+
old_versions TEXT,
2829
git_platform_user_name TEXT,
2930
git_platform_name TEXT,
3031
repository_name TEXT,

app/src/store/sqliteProjectDaoImpl.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class SqliteProjectDaoImpl implements ProjectDao {
77
async createProject(projectEntity: ProjectEntity): Promise<ProjectEntity> {
88
projectEntity.id = generateProjectId(projectEntity);
99
return new Promise((resolve, reject) => {
10-
const stmt = db.prepare('INSERT INTO projects (id, display_name, version, json, git_platform_name, git_platform_user_name, is_repository_public, repository_branch, repository_name, owner_email, repository_url, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
11-
stmt.run(projectEntity.id, projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.git_platform_name, projectEntity.git_platform_user_name, projectEntity.is_repository_public, projectEntity.repository_branch, projectEntity.repository_name, projectEntity.owner_email, projectEntity.repository_url, projectEntity.created_at, projectEntity.updated_at, (err: any) => {
10+
const stmt = db.prepare('INSERT INTO projects (id, display_name, version, json, git_platform_name, git_platform_user_name, is_repository_public, repository_branch, repository_name, owner_email, repository_url, metadata, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
11+
stmt.run(projectEntity.id, projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.git_platform_name, projectEntity.git_platform_user_name, projectEntity.is_repository_public, projectEntity.repository_branch, projectEntity.repository_name, projectEntity.owner_email, projectEntity.repository_url, projectEntity.metadata, projectEntity.created_at, projectEntity.updated_at, (err: any) => {
1212
if (err) {
1313
reject(err);
1414
} else {
@@ -63,7 +63,9 @@ export class SqliteProjectDaoImpl implements ProjectDao {
6363
repository_name: '',
6464
repository_branch: '',
6565
is_repository_public: false,
66-
repository_url: ''
66+
repository_url: '',
67+
metadata: '',
68+
old_versions: [],
6769
};
6870
resolve(projectEntity);
6971
}
@@ -76,11 +78,13 @@ export class SqliteProjectDaoImpl implements ProjectDao {
7678
SET display_name = ?,
7779
version = ?,
7880
json = ?,
81+
metadata = ?,
82+
old_versions = ?,
7983
updated_at = ?
8084
WHERE id = ?`;
8185
return new Promise<boolean>((resolve, reject) => {
8286
const stmt = db.prepare(query);
83-
stmt.run(projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.updated_at, id, (err: any) => {
87+
stmt.run(projectEntity.display_name, projectEntity.version, projectEntity.json, projectEntity.metadata, projectEntity.old_versions, projectEntity.updated_at, id, (err: any) => {
8488
if (err) {
8589
reject(err);
8690
} else {

core/api/v1/project.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ service ProjectService {
1010

1111
message GenerateCodeRequest {
1212
string projectName = 1;
13-
string projectJson = 2;
13+
string projectJSON = 2;
1414
string gitRepositoryName = 3;
1515
string gitPlatformName = 4;
1616
string gitPlatformURL = 5;

core/gen/api/v1/project.pb.go

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

0 commit comments

Comments
 (0)