Skip to content

Commit acc75b6

Browse files
authored
feat(backend, Frontend) download project and GitHub fork (#198)
1 parent b5522d2 commit acc75b6

26 files changed

+1309
-10
lines changed

backend/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ [email protected]
3232
MAIL_PORT=587
3333
MAIL_DOMAIN=your_net
3434

35+
# github app
36+
GITHUB_APP_ENABLED=true
37+
GITHUB_APP_ID="GITHUB_APP_ID"
38+
GITHUB_PRIVATE_KEY_PATH="YOUR_PATH"
39+
GITHUB_CLIENT_ID="GITHUB_CLIENT_ID"
40+
GITHUB_CLIENT_SECRET="GITHUB_CLIENT_SECRET"
41+
GITHUB_WEBHOOK_SECRET="GITHUB_WEBHOOK_SECRET"
42+
CALLBACK="CALLBACK"

backend/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@
4141
"@nestjs/jwt": "^10.2.0",
4242
"@nestjs/platform-express": "^10.0.0",
4343
"@nestjs/typeorm": "^10.0.2",
44+
"@octokit/auth-app": "^7.1.5",
45+
"@octokit/webhooks": "^13.7.5",
4446
"@types/bcrypt": "^5.0.2",
4547
"@types/fs-extra": "^11.0.4",
4648
"@types/normalize-path": "^3.0.2",
4749
"@types/toposort": "^2.0.7",
50+
"archiver": "^7.0.1",
4851
"axios": "^1.7.7",
4952
"bcrypt": "^5.1.1",
5053
"class-transformer": "^0.5.1",
@@ -62,10 +65,12 @@
6265
"markdown-to-txt": "^2.0.1",
6366
"nodemailer": "^6.10.0",
6467
"normalize-path": "^3.0.0",
68+
"octokit": "^4.1.2",
6569
"openai": "^4.77.0",
6670
"p-queue-es5": "^6.0.2",
6771
"reflect-metadata": "^0.2.2",
6872
"rxjs": "^7.8.1",
73+
"simple-git": "^3.27.0",
6974
"sqlite3": "^5.1.7",
7075
"subscriptions-transport-ws": "^0.11.0",
7176
"toposort": "^2.0.2",

backend/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
1616
import { LoggingInterceptor } from 'src/interceptor/LoggingInterceptor';
1717
import { PromptToolModule } from './prompt-tool/prompt-tool.module';
1818
import { MailModule } from './mail/mail.module';
19+
import { GitHubModule } from './github/github.module';
1920

2021
// TODO(Sma1lboy): move to a separate file
2122
function isProduction(): boolean {
@@ -50,6 +51,7 @@ function isProduction(): boolean {
5051
PromptToolModule,
5152
MailModule,
5253
TypeOrmModule.forFeature([User]),
54+
GitHubModule
5355
],
5456
providers: [
5557
AppResolver,

backend/src/chat/chat.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { UserService } from 'src/user/user.service';
1111
import { PubSub } from 'graphql-subscriptions';
1212
import { JwtCacheModule } from 'src/jwt-cache/jwt-cache.module';
1313
import { UploadModule } from 'src/upload/upload.module';
14+
import { GitHubModule } from 'src/github/github.module';
1415

1516
@Module({
1617
imports: [
1718
TypeOrmModule.forFeature([Chat, User]),
1819
AuthModule,
1920
JwtCacheModule,
2021
UploadModule,
22+
GitHubModule,
2123
],
2224
controllers: [ChatController],
2325
providers: [
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// src/github/github-webhook.controller.ts
2+
3+
import { Body, Controller, Post, Req, Res } from '@nestjs/common';
4+
import { Request, Response } from 'express';
5+
import { createNodeMiddleware } from '@octokit/webhooks';
6+
import { GitHubAppService } from './githubApp.service';
7+
import { GetUserIdFromToken } from 'src/decorator/get-auth-token.decorator';
8+
import { UserService } from 'src/user/user.service';
9+
10+
@Controller('github')
11+
export class GitHuController {
12+
private readonly webhookMiddleware;
13+
14+
constructor(private readonly gitHubAppService: GitHubAppService, private readonly userService: UserService) {
15+
// Get the App instance from the service
16+
const app = this.gitHubAppService.getApp();
17+
18+
// Create the Express-style middleware from @octokit/webhooks
19+
this.webhookMiddleware = createNodeMiddleware(app.webhooks, {
20+
path: '/github/webhook',
21+
});
22+
}
23+
24+
@Post('webhook')
25+
async handleWebhook(@Req() req: Request, @Res() res: Response) {
26+
console.log('📩 Received POST /github/webhook');
27+
28+
return this.webhookMiddleware(req, res, (error?: any) => {
29+
if (error) {
30+
console.error('Webhook middleware error:', error);
31+
return res.status(500).send('Internal Server Error');
32+
} else {
33+
console.log('Middleware processed request');
34+
return res.sendStatus(200);
35+
}
36+
});
37+
}
38+
39+
@Post('storeInstallation')
40+
async storeInstallation(
41+
@Body() body: { installationId: string, githubCode: string },
42+
@GetUserIdFromToken() userId: string,
43+
) {
44+
await this.userService.bindUserIdAndInstallId(userId, body.installationId, body.githubCode);
45+
return { success: true };
46+
}
47+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { forwardRef, Module } from '@nestjs/common';
2+
import { TypeOrmModule } from '@nestjs/typeorm';
3+
import { AuthModule } from '../auth/auth.module';
4+
import { ProjectGuard } from '../guard/project.guard';
5+
import { ChatService } from 'src/chat/chat.service';
6+
import { User } from 'src/user/user.model';
7+
import { Chat } from 'src/chat/chat.model';
8+
import { AppConfigModule } from 'src/config/config.module';
9+
import { UploadModule } from 'src/upload/upload.module';
10+
import { GitHubAppService } from './githubApp.service';
11+
import { GitHubService } from './github.service';
12+
import { Project } from 'src/project/project.model';
13+
import { ProjectPackages } from 'src/project/project-packages.model';
14+
import { GitHuController } from './github.controller';
15+
import { ProjectService } from 'src/project/project.service';
16+
import { ConfigModule, ConfigService } from '@nestjs/config';
17+
import { UserModule } from 'src/user/user.module';
18+
19+
@Module({
20+
imports: [
21+
TypeOrmModule.forFeature([Project, Chat, User, ProjectPackages]),
22+
AuthModule,
23+
AppConfigModule,
24+
UploadModule,
25+
ConfigModule,
26+
forwardRef(() => UserModule),
27+
],
28+
controllers: [GitHuController],
29+
providers: [ProjectService, ProjectGuard, GitHubAppService, GitHubService, ConfigService, ChatService],
30+
exports: [GitHubService],
31+
})
32+
export class GitHubModule {}

0 commit comments

Comments
 (0)