Skip to content

Commit dfea588

Browse files
ZHallen122Sma1lboyautofix-ci[bot]
authored
feat(backend): Allow Disable github App in .env (#201)
Co-authored-by: Sma1lboy <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 21b54ef commit dfea588

File tree

5 files changed

+14292
-17664
lines changed

5 files changed

+14292
-17664
lines changed

backend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ MAIL_PORT=587
3333
MAIL_DOMAIN=your_net
3434

3535
# github app
36-
GITHUB_APP_ENABLED=true
36+
GITHUB_ENABLED=true # set false to disable GitHub
3737
GITHUB_APP_ID="GITHUB_APP_ID"
3838
GITHUB_PRIVATE_KEY_PATH="YOUR_PATH"
3939
GITHUB_CLIENT_ID="GITHUB_CLIENT_ID"

backend/src/github/github.controller.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// src/github/github-webhook.controller.ts
22

3-
import { Body, Controller, Post, Req, Res } from '@nestjs/common';
3+
import { Body, Controller, Logger, Post, Req, Res } from '@nestjs/common';
44
import { Request, Response } from 'express';
55
import { createNodeMiddleware } from '@octokit/webhooks';
66
import { GitHubAppService } from './githubApp.service';
77
import { GetUserIdFromToken } from 'src/decorator/get-auth-token.decorator';
88
import { UserService } from 'src/user/user.service';
9+
import { ConfigService } from '@nestjs/config';
910

1011
@Controller('github')
1112
export class GitHuController {
13+
private readonly logger = new Logger('GitHuController');
14+
1215
private readonly webhookMiddleware;
1316

1417
constructor(
1518
private readonly gitHubAppService: GitHubAppService,
1619
private readonly userService: UserService,
20+
private configService: ConfigService,
1721
) {
22+
const githubEnabled = this.configService.get<string>('GITHUB_ENABLED');
23+
if (githubEnabled !== 'true') {
24+
this.logger.warn('GitHub Controller integration is disabled');
25+
return;
26+
}
27+
1828
// Get the App instance from the service
1929
const app = this.gitHubAppService.getApp();
2030

backend/src/github/github.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export class GitHubService {
2323
@InjectRepository(Project)
2424
private projectsRepository: Repository<Project>,
2525
) {
26+
const githubEnabled = this.configService.get<string>('GITHUB_ENABLED');
27+
if (githubEnabled !== 'true') {
28+
this.logger.warn('GitHub service integration is disabled');
29+
return;
30+
}
31+
2632
this.appId = this.configService.get<string>('GITHUB_APP_ID');
2733

2834
const privateKeyPath = this.configService.get<string>(

backend/src/github/githubApp.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class GitHubAppService {
2525
@InjectRepository(Project)
2626
private readonly projectRepo: Repository<Project>,
2727
) {
28+
const githubEnabled = this.configService.get<string>('GITHUB_ENABLED');
29+
if (githubEnabled !== 'true') {
30+
this.logger.warn('GitHub APP Service integration is disabled');
31+
return;
32+
}
2833
// Load from environment or config
2934
const appId = this.configService.get('GITHUB_APP_ID');
3035
const privateKeyPath = this.configService.get('GITHUB_PRIVATE_KEY_PATH');

0 commit comments

Comments
 (0)