Skip to content

Commit

Permalink
chore: make GitHub bot optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Feb 8, 2025
1 parent 8115ce9 commit 797ca9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/services/github/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import { Octokit } from '@octokit/rest';
import { createAppAuth } from '@octokit/auth-app';
import config from '@/config-manager';

const privateKey = fs.readFileSync(config.github.app!.private_key_path, {
encoding: 'utf8'
});
let octokit: Octokit | undefined;

const octokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: config.github.app!.id,
privateKey: privateKey,
installationId: config.github.app!.installation_id,
},
})
if (config.github.app) {
const privateKey = fs.readFileSync(config.github.app.private_key_path, {
encoding: 'utf8'
});

octokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: config.github.app.id,
privateKey: privateKey,
installationId: config.github.app.installation_id,
},
});
}

export default octokit;
5 changes: 5 additions & 0 deletions src/services/github/process-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const CHECKED_FOR_EXISTING_REGEX = /- \[[xX]\] I have checked the repository for
const DETAILS_REGEX = /###.*?\n[\s\S]*?###(.*)?\n([\s\S]*?)### Any other details to share\? \(OPTIONAL\)/;

export default async function processIssue(request: express.Request, response: express.Response): Promise<void> {
if (!octokit) {
response.sendStatus(200);
return;
}

const payload = request.body as EventPayloadMap['issues'];

if (payload.action !== 'opened') {
Expand Down
5 changes: 5 additions & 0 deletions src/services/github/process-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const ISSUE_APPROVED_REGEX = /- \[[xX]\] What I'm implementing was an/;
const TESTED_CHANGES_REGEX = /- \[[xX]\] I have tested all of my changes\./;

export default async function processPullRequest(request: express.Request, response: express.Response): Promise<void> {
if (!octokit) {
response.sendStatus(200);
return;
}

const payload = request.body as EventPayloadMap['pull_request'];

if (payload.action !== 'opened') {
Expand Down

0 comments on commit 797ca9c

Please sign in to comment.