Skip to content

Commit a6fefcc

Browse files
PengyuChen01pengyu
authored andcommitted
fix (environment): linux eslint build format issue (#203)
Co-authored-by: pengyu <[email protected]>
1 parent 6805697 commit a6fefcc

File tree

8 files changed

+205
-128
lines changed

8 files changed

+205
-128
lines changed

backend/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function isProduction(): boolean {
5151
PromptToolModule,
5252
MailModule,
5353
TypeOrmModule.forFeature([User]),
54-
GitHubModule
54+
GitHubModule,
5555
],
5656
providers: [
5757
AppResolver,

backend/src/project/dto/project.input.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// DTOs for Project APIs
22
import { InputType, Field, ID, ObjectType } from '@nestjs/graphql';
3-
import { IsNotEmpty, IsString, IsUUID, IsOptional, IsBoolean } from 'class-validator';
3+
import {
4+
IsNotEmpty,
5+
IsString,
6+
IsUUID,
7+
IsOptional,
8+
IsBoolean,
9+
} from 'class-validator';
410
import { Project } from '../project.model';
511
import { FileUpload, GraphQLUpload } from 'graphql-upload-minimal';
612

backend/src/project/project.resolver.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,15 @@ export class ProjectsResolver {
166166
}
167167

168168
@Mutation(() => Project)
169-
async syncProjectToGitHub(@Args('projectId') projectId: string, @GetUserIdFromToken() userId: string,) {
169+
async syncProjectToGitHub(
170+
@Args('projectId') projectId: string,
171+
@GetUserIdFromToken() userId: string,
172+
) {
170173
// TODO: MAKE PUBLIC DYNAMIC
171-
return this.projectService.syncProjectToGitHub(userId, projectId, true /* isPublic? */);
174+
return this.projectService.syncProjectToGitHub(
175+
userId,
176+
projectId,
177+
true /* isPublic? */,
178+
);
172179
}
173180
}

backend/src/project/project.service.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -706,77 +706,82 @@ export class ProjectService {
706706
userId: string,
707707
projectId: string,
708708
): Promise<{ zipPath: string; fileName: string }> {
709-
710709
// Get the project
711710
const project = await this.getProjectById(projectId);
712-
711+
713712
// Check ownership or if project is public
714713
if (project.userId !== userId && !project.isPublic) {
715714
throw new ForbiddenException(
716715
'You do not have permission to download this project',
717716
);
718717
}
719-
718+
720719
// Ensure the project path exists
721720
const projectPath = getProjectPath(project.projectPath);
722721
this.logger.debug(`Project path: ${projectPath}`);
723-
722+
724723
if (!fs.existsSync(projectPath)) {
725724
throw new NotFoundException(
726725
`Project directory not found at ${projectPath}`,
727726
);
728727
}
729-
728+
730729
// Create a temporary directory for the zip file if it doesn't exist
731730
const tempDir = getTempDir();
732731
if (!fs.existsSync(tempDir)) {
733732
fs.mkdirSync(tempDir, { recursive: true });
734733
}
735-
734+
736735
// Generate a filename for the zip
737736
const fileName = `${project.projectName.replace(/[^a-z0-9]/gi, '_')}_${Date.now()}.zip`;
738737
const zipPath = path.join(tempDir, fileName);
739-
738+
740739
// Create a write stream for the zip file
741740
const output = fs.createWriteStream(zipPath);
742741
const archive = archiver('zip', {
743742
zlib: { level: 9 }, // Set the compression level
744743
});
745-
744+
746745
// Listen for errors
747746
output.on('error', (err) => {
748747
throw new InternalServerErrorException(
749748
`Error creating zip file: ${err.message}`,
750749
);
751750
});
752-
751+
753752
// Pipe the archive to the output file
754753
archive.pipe(output);
755754

756755
// Filter unwanted files/folders
757756
const ignored = ['node_modules', '.git', '.gitignore', '.env'];
758-
757+
759758
// Add the project directory to the archive
760-
archive.glob('**/*', {
761-
cwd: projectPath,
762-
ignore: ignored.map(pattern => `**/${pattern}/**`).concat(ignored),
763-
dot: true
764-
}, {});
765-
759+
archive.glob(
760+
'**/*',
761+
{
762+
cwd: projectPath,
763+
ignore: ignored.map((pattern) => `**/${pattern}/**`).concat(ignored),
764+
dot: true,
765+
},
766+
{},
767+
);
768+
766769
// Finalize the archive
767770
await archive.finalize();
768-
771+
769772
// Wait for the output stream to finish
770773
await new Promise<void>((resolve, reject) => {
771774
output.on('close', () => {
772-
this.logger.debug(`Created zip file: ${zipPath}, size: ${archive.pointer()} bytes`);
775+
this.logger.debug(
776+
`Created zip file: ${zipPath}, size: ${archive.pointer()} bytes`,
777+
);
773778
resolve();
774779
});
775780
output.on('error', (err) => {
776781
reject(err);
777782
});
778783
});
779-
784+
780785
return { zipPath, fileName };
781786
}
782787

@@ -788,18 +793,21 @@ export class ProjectService {
788793
async syncProjectToGitHub(
789794
userId: string,
790795
projectId: string,
791-
isPublic: boolean, // the user decides if the new repo is public or private
796+
isPublic: boolean, // the user decides if the new repo is public or private
792797
): Promise<Project> {
793-
794798
const user = await this.userService.getUser(userId);
795-
799+
796800
// 1) Find the project
797-
const project = await this.projectsRepository.findOne({ where: { id: projectId } });
801+
const project = await this.projectsRepository.findOne({
802+
where: { id: projectId },
803+
});
798804
if (!project) {
799805
throw new Error('Project not found');
800806
}
801-
802-
this.logger.log("check if the github project exist: " + project.isSyncedWithGitHub);
807+
808+
this.logger.log(
809+
'check if the github project exist: ' + project.isSyncedWithGitHub,
810+
);
803811
// 2) Check user’s GitHub installation
804812
if (!user.githubInstallationId) {
805813
throw new Error('GitHub App not installed for this user');
@@ -816,15 +824,15 @@ export class ProjectService {
816824
// Use project.projectName or generate a safe name
817825

818826
// TODO: WHEN REPO NAME EXIST
819-
const repoName = project.projectName
820-
.replace(/\s+/g, '-')
821-
.toLowerCase() // e.g. "my-project"
822-
+ '-' + "ChangeME"; // to make it unique if needed
827+
const repoName =
828+
project.projectName.replace(/\s+/g, '-').toLowerCase() + // e.g. "my-project"
829+
'-' +
830+
'ChangeME'; // to make it unique if needed
823831

824832
const { owner, repo, htmlUrl } = await this.gitHubService.createUserRepo(
825833
repoName,
826834
isPublic,
827-
userOAuthToken
835+
userOAuthToken,
828836
);
829837

830838
project.githubRepoName = repo;

backend/src/user/user.service.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
1+
import {
2+
BadRequestException,
3+
Injectable,
4+
NotFoundException,
5+
} from '@nestjs/common';
26
import { User } from './user.model';
37
import { Repository } from 'typeorm';
48
import { InjectRepository } from '@nestjs/typeorm';
@@ -63,24 +67,33 @@ export class UserService {
6367
return this.userRepository.save(user);
6468
}
6569

66-
async bindUserIdAndInstallId(userId: string, installationId: string, githubCode: string): Promise<boolean> {
70+
async bindUserIdAndInstallId(
71+
userId: string,
72+
installationId: string,
73+
githubCode: string,
74+
): Promise<boolean> {
6775
const user = await this.userRepository.findOne({ where: { id: userId } });
6876
if (!user) {
6977
throw new NotFoundException('User not found');
7078
}
7179

7280
if (user.githubInstallationId) {
73-
throw new BadRequestException('User already linked to a GitHub installation.');
81+
throw new BadRequestException(
82+
'User already linked to a GitHub installation.',
83+
);
7484
}
7585

7686
if (!githubCode) {
7787
throw new BadRequestException('Missing GitHub OAuth code');
7888
}
7989

80-
console.log(`Binding GitHub installation ID ${installationId} to user code ${githubCode}`);
90+
console.log(
91+
`Binding GitHub installation ID ${installationId} to user code ${githubCode}`,
92+
);
8193

8294
//First request to GitHub to exchange the code for an access token (Wont expire)
83-
const accessToken = await this.gitHubService.exchangeOAuthCodeForToken(githubCode);
95+
const accessToken =
96+
await this.gitHubService.exchangeOAuthCodeForToken(githubCode);
8497

8598
user.githubInstallationId = installationId;
8699
user.githubAccessToken = accessToken;
@@ -90,7 +103,7 @@ export class UserService {
90103
} catch (error) {
91104
console.error('Error saving user:', error);
92105
throw new Error('Failed to save user with installation ID');
93-
}
106+
}
94107

95108
return true;
96109
}

frontend/src/app/github/callback/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import GitHubCallback from '@/components/github-callback';
22

33
export default function GitHubCallbackPage() {
44
return <GitHubCallback />;
5-
}
5+
}

0 commit comments

Comments
 (0)