Skip to content

Commit 05dce55

Browse files
Copilotalexr00
andcommitted
Extract isBot helper as private method for reusability
- Move isBot logic to a private method _isBot - Simplify merge event handling to use _isBot - Improve code organization and testability Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 55385ef commit 05dce55

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/notifications/notificationsManager.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
323323
}
324324
}
325325

326+
private _isBot(user: { login: string, accountType?: AccountType }): boolean {
327+
// Check if accountType indicates this is a bot
328+
if (user.accountType === AccountType.Bot) {
329+
return true;
330+
}
331+
// Check for common bot naming patterns
332+
if (user.login.endsWith('[bot]') || user.login === 'vs-code-engineering') {
333+
return true;
334+
}
335+
return false;
336+
}
337+
326338
private _getMeaningfulEventTime(event: TimelineEvent, currentUser: string, isCurrentUser: boolean): Date | undefined {
327339
const userCheck = (testUser?: string) => {
328340
if (isCurrentUser) {
@@ -332,40 +344,25 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
332344
}
333345
};
334346

335-
// Helper to check if a user is a bot
336-
const isBot = (user: { login: string, accountType?: AccountType }): boolean => {
337-
// Check if accountType indicates this is a bot
338-
if (user.accountType === AccountType.Bot) {
339-
return true;
340-
}
341-
// Check for common bot naming patterns
342-
if (user.login.endsWith('[bot]') || user.login === 'vs-code-engineering') {
343-
return true;
344-
}
345-
return false;
346-
};
347-
348347
if (event.event === EventType.Committed) {
349-
if (!isBot(event.author) && userCheck(event.author.login)) {
348+
if (!this._isBot(event.author) && userCheck(event.author.login)) {
350349
return new Date(event.committedDate);
351350
}
352351
} else if (event.event === EventType.Commented) {
353-
if (event.user && !isBot(event.user) && userCheck(event.user.login)) {
352+
if (event.user && !this._isBot(event.user) && userCheck(event.user.login)) {
354353
return new Date(event.createdAt);
355354
}
356355
} else if (event.event === EventType.Reviewed) {
357356
// We only count empty reviews as meaningful if the user is the current user
358357
if (isCurrentUser || (event.comments.length > 0 || event.body.length > 0)) {
359-
if (event.user && !isBot(event.user) && userCheck(event.user.login)) {
358+
if (event.user && !this._isBot(event.user) && userCheck(event.user.login)) {
360359
return new Date(event.submittedAt);
361360
}
362361
}
363362
} else if (event.event === EventType.Merged) {
364363
// Merging a PR is a meaningful event
365-
// Note: MergedEvent.user is IActor (not IAccount), so we check login patterns
366-
const login = event.user.login;
367-
const isBotByName = login.endsWith('[bot]') || login === 'vs-code-engineering';
368-
if (!isBotByName && userCheck(login)) {
364+
// Note: MergedEvent.user is IActor (not IAccount), so accountType is undefined
365+
if (!this._isBot(event.user) && userCheck(event.user.login)) {
369366
return new Date(event.createdAt);
370367
}
371368
}

0 commit comments

Comments
 (0)