Skip to content

Commit 67ff3b3

Browse files
fix: issues in project's code generation
1 parent c140e42 commit 67ff3b3

File tree

9 files changed

+17
-12
lines changed

9 files changed

+17
-12
lines changed

app/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ RUN apk update && apk add git
1616
COPY --from=builder /app/dist /server/dist
1717
COPY --from=builder /app/node_modules /server/node_modules
1818
COPY --from=builder /app/protobufs /server/protobufs
19-
RUN mkdir "/server/workdir"
19+
RUN mkdir -p /compage/workdir
20+
RUN chmod -R 777 /compage/workdir
2021
ENV NODE_ENV=production
2122
EXPOSE 5000
2223
CMD [ "node", "dist/src/app.js" ]

app/src/integrations/git-platforms/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const createRepository = async (projectEntity: ProjectEntity) => {
2323
};
2424

2525
export const makeInitialCommit = async (projectEntity: ProjectEntity) => {
26-
const createdProjectPath = `/server/workdir/${projectEntity.id}`;
26+
const createdProjectPath = `/compage/workdir/workdir/${projectEntity.id}`;
2727
fs.mkdirSync(createdProjectPath, {recursive: true});
2828
fs.writeFileSync(`${createdProjectPath}/README.md`, `# ${projectEntity.repository_name}`);
2929
const gitPlatform: GitPlatformEntity = await gitPlatformService.getGitPlatform(projectEntity.owner_email, projectEntity.git_platform_name);

app/src/integrations/simple-git/existingProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const cloneExistingProjectFromGitServer = async (existingProjectGitServer
3030
};
3131

3232
export const pushToExistingProjectOnGitServer = async (existingProjectGitServerRequest: ExistingProjectGitServerRequest): Promise<string> => {
33-
const baseDir = existingProjectGitServerRequest.clonedProjectPath + '/' + existingProjectGitServerRequest.projectName;
33+
const baseDir = existingProjectGitServerRequest.clonedProjectPath + '/' + existingProjectGitServerRequest.repositoryName;
3434
const options: Partial<SimpleGitOptions> = {
3535
baseDir,
3636
binary: 'git',

app/src/integrations/simple-git/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface NewProjectGitServerRequest {
1818
export interface ExistingProjectGitServerRequest {
1919
projectName: string;
2020
projectVersion: string;
21+
repositoryName: string;
2122
gitProviderDetails: GitProviderDetails;
2223
clonedProjectPath: string;
2324
generatedProjectPath: string;

app/src/routes/codeOperations.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
8787
}
8888

8989
// create directory hierarchy here itself as creating it after receiving data will not be proper.
90-
const originalProjectPath = `${os.tmpdir()}/${projectEntity.display_name}`;
90+
const originalProjectPath = `/compage/workdir/${projectEntity.display_name}`;
9191
// this is a path where the project will be downloaded
9292
const downloadedProjectPath = `${originalProjectPath}_downloaded`;
9393
// this is a path where the project will be cloned
@@ -176,6 +176,7 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
176176
const existingProjectGitServerRequest: ExistingProjectGitServerRequest = {
177177
projectName: projectEntity.display_name,
178178
projectVersion: projectEntity.version,
179+
repositoryName: projectEntity.repository_name as string,
179180
gitProviderDetails: {
180181
repositoryBranch: projectEntity.repository_branch as string,
181182
repositoryName: projectEntity.repository_name as string,
@@ -192,16 +193,16 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r
192193

193194
let error: string = await cloneExistingProjectFromGitServer(existingProjectGitServerRequest);
194195
if (error.length > 0) {
195-
cleanup(downloadedProjectPath);
196+
// cleanup(downloadedProjectPath);
196197
// send status back to ui
197198
const clonedErrorMessage = `unable to generate code for ${projectEntity.display_name}[${projectEntity.id}] => ${error}.`;
198199
Logger.error(clonedErrorMessage);
199200
return resource.status(500).json(getGenerateCodeError(clonedErrorMessage));
200201
}
201-
202+
Logger.debug(`cloned ${clonedProjectPath} from github.`);
202203
error = await pushToExistingProjectOnGitServer(existingProjectGitServerRequest);
203204
if (error.length > 0) {
204-
cleanup(downloadedProjectPath);
205+
// cleanup(downloadedProjectPath);
205206
// send status back to ui
206207
const pushErrorMessage = `unable to generate code for ${projectEntity.display_name}[${projectEntity.id}] => ${error}.`;
207208
Logger.error(pushErrorMessage);

core/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
5555
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
5656
COPY --from=builder /app/core /
5757
COPY templates /app/templates
58+
RUN mkdir -p /compage/workdir
59+
RUN chmod -R 777 /compage/workdir
5860
# Application port (optional)
5961
EXPOSE 8080
6062
EXPOSE 50051

core/internal/utils/constants.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package utils
22

3-
// TmpPath Constant for referencing temporary directory to hold generated project.
4-
const TmpPath = "/tmp"
3+
// CodeGeneratorPath Constant for referencing temporary directory to hold generated project.
4+
const CodeGeneratorPath = "/compage/workdir"
55

66
// TemplateExtension template's extension.
77
const TemplateExtension = ".tmpl"

core/internal/utils/fileUtils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010

1111
// GetProjectDirectoryName returns tarFile parent path
1212
func GetProjectDirectoryName(name string) string {
13-
return TmpPath + "/" + name
13+
return CodeGeneratorPath + "/" + name
1414
}
1515

1616
// CreateDirectories creates the directory specified and all other directories in the path.
1717
func CreateDirectories(dirName string) error {
1818
return os.MkdirAll(dirName, os.ModePerm)
1919
}
2020

21-
// CopyFiles copies only files in the srcDirectory to destDirectory, doesn't do it recursively.
21+
// CopyFiles copies only file in the srcDirectory to destDirectory, doesn't do it recursively.
2222
func CopyFiles(destDirectory string, srcDirectory string) error {
2323
return CopyAllInSrcDirToDestDir(destDirectory, srcDirectory, false)
2424
}

core/internal/utils/projectPathUtils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
root = filepath.Join(filepath.Dir(b), "../..")
1313
)
1414

15-
// GetProjectRootPath returns root path of the language template passed.
15+
// GetProjectRootPath returns a root path of the language template passed.
1616
func GetProjectRootPath(templatesPath string) string {
1717
return root + "/" + templatesPath
1818
}

0 commit comments

Comments
 (0)