Skip to content

Commit 09cab6b

Browse files
Copilotalexr00
andauthored
Fix notification marking for merged PRs with bot comments (#8281)
* Initial plan * Initial plan for notification marking issue Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add support for merged events and bot filtering in notifications - Add EventType.Merged as a meaningful event in _getMeaningfulEventTime - Filter out bot accounts (AccountType.Bot) from meaningful events - Filter out users with [bot] suffix or vs-code-engineering username - This fixes the issue where merged PRs by the current user don't get marked as done Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add bot filtering for merge events - Check login patterns for merge events to filter out bots - MergedEvent.user is IActor (not IAccount), so we only check name patterns Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * 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> * Move automated users to configuration constant - Extract 'vs-code-engineering' to AUTOMATED_USERS constant - Improve maintainability by making it easy to add/remove automated users - Add documentation for the constant Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Ignore mege --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 1737796 commit 09cab6b

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/notifications/notificationsManager.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { NOTIFICATION_SETTING, NotificationVariants, PR_SETTINGS_NAMESPACE } fro
1313
import { EventType, TimelineEvent } from '../common/timelineEvent';
1414
import { toNotificationUri } from '../common/uri';
1515
import { CredentialStore } from '../github/credentials';
16-
import { NotificationSubjectType } from '../github/interface';
16+
import { AccountType, NotificationSubjectType } from '../github/interface';
1717
import { IssueModel } from '../github/issueModel';
1818
import { issueMarkdown } from '../github/markdownUtils';
1919
import { PullRequestModel } from '../github/pullRequestModel';
@@ -35,6 +35,9 @@ export enum NotificationsSortMethod {
3535
export class NotificationsManager extends Disposable implements vscode.TreeDataProvider<NotificationTreeDataItem> {
3636
private static ID = 'NotificationsManager';
3737

38+
// List of automated users that should be ignored when determining meaningful events
39+
private static readonly AUTOMATED_USERS = ['vs-code-engineering'];
40+
3841
private _onDidChangeTreeData: vscode.EventEmitter<NotificationTreeDataItem | undefined | void> = this._register(new vscode.EventEmitter<NotificationTreeDataItem | undefined | void>());
3942
readonly onDidChangeTreeData: vscode.Event<NotificationTreeDataItem | undefined | void> = this._onDidChangeTreeData.event;
4043

@@ -323,6 +326,22 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
323326
}
324327
}
325328

329+
private _isBot(user: { login: string, accountType?: AccountType }): boolean {
330+
// Check if accountType indicates this is a bot
331+
if (user.accountType === AccountType.Bot) {
332+
return true;
333+
}
334+
// Check for common bot naming patterns
335+
if (user.login.endsWith('[bot]')) {
336+
return true;
337+
}
338+
// Check for specific automated users
339+
if (NotificationsManager.AUTOMATED_USERS.includes(user.login)) {
340+
return true;
341+
}
342+
return false;
343+
}
344+
326345
private _getMeaningfulEventTime(event: TimelineEvent, currentUser: string, isCurrentUser: boolean): Date | undefined {
327346
const userCheck = (testUser?: string) => {
328347
if (isCurrentUser) {
@@ -333,17 +352,17 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
333352
};
334353

335354
if (event.event === EventType.Committed) {
336-
if (userCheck(event.author.login)) {
355+
if (!this._isBot(event.author) && userCheck(event.author.login)) {
337356
return new Date(event.committedDate);
338357
}
339358
} else if (event.event === EventType.Commented) {
340-
if (userCheck(event.user?.login)) {
359+
if (event.user && !this._isBot(event.user) && userCheck(event.user.login)) {
341360
return new Date(event.createdAt);
342361
}
343362
} else if (event.event === EventType.Reviewed) {
344363
// We only count empty reviews as meaningful if the user is the current user
345364
if (isCurrentUser || (event.comments.length > 0 || event.body.length > 0)) {
346-
if (userCheck(event.user?.login)) {
365+
if (event.user && !this._isBot(event.user) && userCheck(event.user.login)) {
347366
return new Date(event.submittedAt);
348367
}
349368
}

0 commit comments

Comments
 (0)