Skip to content

Commit a7ae0a7

Browse files
authored
fix: ignore comments from vercel[bot] instead of vercel (#212)
1 parent 70a5b32 commit a7ae0a7

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

apps/roomote/src/app/api/webhooks/github/handlers/__tests__/utils.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ vi.mock('@/lib', () => ({
1616
describe('GitHub Webhook Utils', () => {
1717
let verifySignature: typeof import('../utils').verifySignature;
1818
let createAndEnqueueJob: typeof import('../utils').createAndEnqueueJob;
19+
let isRoomoteMention: typeof import('../utils').isRoomoteMention;
1920
let mockDb: { insert: ReturnType<typeof vi.fn> };
2021
let mockEnqueue: ReturnType<typeof vi.fn>;
2122

@@ -30,6 +31,7 @@ describe('GitHub Webhook Utils', () => {
3031
const utilsModule = await import('../utils');
3132
verifySignature = utilsModule.verifySignature;
3233
createAndEnqueueJob = utilsModule.createAndEnqueueJob;
34+
isRoomoteMention = utilsModule.isRoomoteMention;
3335
});
3436

3537
afterEach(() => {
@@ -256,6 +258,105 @@ describe('GitHub Webhook Utils', () => {
256258
});
257259
});
258260

261+
describe('isRoomoteMention', () => {
262+
const createMockComment = (body: string, login: string) => ({
263+
id: 123,
264+
body,
265+
html_url: 'https://github.com/test/repo/issues/1#issuecomment-123',
266+
user: { login },
267+
});
268+
269+
it('should return true for valid roomote mention from regular user', () => {
270+
const comment = createMockComment(
271+
'Hey @roomote, can you help with this?',
272+
'testuser',
273+
);
274+
expect(isRoomoteMention(comment)).toBe(true);
275+
});
276+
277+
it('should return false when no roomote mention', () => {
278+
const comment = createMockComment(
279+
'This is a regular comment without mention',
280+
'testuser',
281+
);
282+
expect(isRoomoteMention(comment)).toBe(false);
283+
});
284+
285+
it('should return false when comment is from roomote user', () => {
286+
const comment = createMockComment(
287+
'Thanks for mentioning @roomote!',
288+
'roomote',
289+
);
290+
expect(isRoomoteMention(comment)).toBe(false);
291+
});
292+
293+
it('should return false when comment is from vercel[bot]', () => {
294+
const comment = createMockComment(
295+
'Deployment successful! @roomote',
296+
'vercel[bot]',
297+
);
298+
expect(isRoomoteMention(comment)).toBe(false);
299+
});
300+
301+
it('should return true when comment is from vercel (not vercel[bot])', () => {
302+
const comment = createMockComment(
303+
'Hey @roomote, check this out',
304+
'vercel',
305+
);
306+
expect(isRoomoteMention(comment)).toBe(true);
307+
});
308+
309+
it('should handle roomote mention in middle of text', () => {
310+
const comment = createMockComment(
311+
'I think @roomote should look at this issue',
312+
'developer',
313+
);
314+
expect(isRoomoteMention(comment)).toBe(true);
315+
});
316+
317+
it('should handle multiple mentions including roomote', () => {
318+
const comment = createMockComment(
319+
'@user1 @roomote @user2 please review',
320+
'reviewer',
321+
);
322+
expect(isRoomoteMention(comment)).toBe(true);
323+
});
324+
325+
it('should be case sensitive for roomote mention', () => {
326+
const comment = createMockComment(
327+
'Hey @Roomote, can you help?',
328+
'testuser',
329+
);
330+
expect(isRoomoteMention(comment)).toBe(false);
331+
});
332+
333+
it('should handle roomote as part of larger word', () => {
334+
const comment = createMockComment(
335+
'The roomotebot is not working',
336+
'testuser',
337+
);
338+
expect(isRoomoteMention(comment)).toBe(false);
339+
});
340+
341+
it('should return true for other bot users (only roomote and vercel[bot] are ignored)', () => {
342+
const comment = createMockComment(
343+
'Hey @roomote, check this',
344+
'github-actions[bot]',
345+
);
346+
expect(isRoomoteMention(comment)).toBe(true);
347+
});
348+
349+
it('should handle empty comment body', () => {
350+
const comment = createMockComment('', 'testuser');
351+
expect(isRoomoteMention(comment)).toBe(false);
352+
});
353+
354+
it('should handle comment with only @roomote', () => {
355+
const comment = createMockComment('@roomote', 'testuser');
356+
expect(isRoomoteMention(comment)).toBe(true);
357+
});
358+
});
359+
259360
describe('integration tests', () => {
260361
it('should work together in a realistic scenario', async () => {
261362
// Test job creation in a realistic webhook scenario.

apps/roomote/src/app/api/webhooks/github/handlers/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ export async function fetchGitHubAPI(url: string, options: RequestInit = {}) {
6161

6262
export const isRoomoteMention = (comment: GithubComment) =>
6363
comment.body.includes('@roomote') &&
64-
!['roomote', 'vercel'].includes(comment.user.login);
64+
!['roomote', 'vercel[bot]'].includes(comment.user.login);

0 commit comments

Comments
 (0)