Skip to content

Commit 774b152

Browse files
committed
refactor: various things
1 parent e20a7d2 commit 774b152

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/app.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Octokit } from 'octokit';
22
import { App } from 'octokit';
3-
import { logger, type Env } from './util.js';
3+
import { logger, type Env, type IssueCommentCreatedData, type IssueCommentEditedData } from './util.js';
44

55
async function isPRGreen(octokit: Octokit, owner: string, repo: string, pullNumber: number): Promise<boolean> {
66
// First, get the PR data to get the head SHA
@@ -73,12 +73,11 @@ export function getApp(env: Env) {
7373
logger.error({ err }, 'Webhook error');
7474
});
7575

76-
// TODO: Swap to create for prod
77-
app.webhooks.on('issue_comment.edited', async (data) => {
78-
logger.debug('in comment edit');
76+
const commentHandler = async (data: IssueCommentCreatedData | IssueCommentEditedData) => {
77+
logger.debug('in comment handler');
7978

80-
if (!data.payload.comment.body.startsWith('pack this')) {
81-
logger.debug(`Comment does not start with 'pack this': ${data.payload.comment.body}`);
79+
if (!data.payload.comment.body.startsWith('@discord-js-bot pack this')) {
80+
logger.debug({ body: data.payload.comment.body }, 'Comment does not start with "@discord-js-bot pack this"');
8281
return;
8382
}
8483

@@ -94,7 +93,7 @@ export function getApp(env: Env) {
9493

9594
const {
9695
data: { permission },
97-
} = await data.octokit.rest.repos.getCollaboratorPermissionLevel({
96+
} = await app.octokit.rest.repos.getCollaboratorPermissionLevel({
9897
owner: data.payload.repository.owner.login,
9998
repo: data.payload.repository.name,
10099
username: data.payload.comment.user.login,
@@ -107,7 +106,7 @@ export function getApp(env: Env) {
107106

108107
if (
109108
!(await isPRGreen(
110-
data.octokit,
109+
app.octokit,
111110
data.payload.repository.owner.login,
112111
data.payload.repository.name,
113112
data.payload.issue.number,
@@ -117,9 +116,10 @@ export function getApp(env: Env) {
117116
}
118117

119118
logger.debug('Beginning the pack process...');
119+
};
120120

121-
// TODO: Invoke workflow
122-
});
121+
app.webhooks.on('issue_comment.created', commentHandler);
122+
app.webhooks.on('issue_comment.edited', commentHandler);
123123

124124
return app;
125125
}

src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { HandlerFunction } from '@octokit/webhooks/types';
12
import { pino } from 'pino';
23

34
export interface Env {
@@ -7,3 +8,6 @@ export interface Env {
78
}
89

910
export const logger = pino({ level: 'debug' });
11+
12+
export type IssueCommentCreatedData = Parameters<HandlerFunction<'issue_comment.created'>>[0];
13+
export type IssueCommentEditedData = Parameters<HandlerFunction<'issue_comment.edited'>>[0];

wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "discordjs-packer-bot"
1+
name = "discordjs-bot"
22
main = "./src/index.ts"
33
compatibility_date="2025-07-19"
44

0 commit comments

Comments
 (0)