Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(github): use senderGithubLogin as backup for github notifications (#4292)

Will Hutchinson227d40ede87f
diff --git a/js/app/packages/entity/src/composed/list-entity/task.tsx b/js/app/packages/entity/src/composed/list-entity/task.tsx
index f9087b1991..075374bb84 100644
--- a/js/app/packages/entity/src/composed/list-entity/task.tsx
+++ b/js/app/packages/entity/src/composed/list-entity/task.tsx
@@ -2,7 +2,10 @@ import type { NotificationType } from '@core/types';
import { DisplayName } from '@entity/components/DisplayName';
import { Show } from 'solid-js';
import { Entity } from '../../entity';
-import { getActionVerb } from '../../extractors-notification/notification-description-helpers';
+import {
+ getActionVerb,
+ getGithubSenderLogin,
+} from '../../extractors-notification/notification-description-helpers';
import type { EntityData } from '../../types/entity';
import type { Notification } from '../../types/notification';
@@ -16,7 +19,14 @@ export function TaskNarrowBody(props: {
<Show when={props.notification}>
{(notif) => (
<span class="text-ink-extra-muted font-normal truncate">
- <Show when={notif().sender_id}>
+ <Show
+ when={notif().sender_id}
+ fallback={
+ <Show when={getGithubSenderLogin(notif())}>
+ {(login) => <>{login()} </>}
+ </Show>
+ }
+ >
{(senderId) => (
<>
<DisplayName id={senderId()} format="firstName" />{' '}
diff --git a/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts b/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts
index 86c2b7a8db..a3df26bb94 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts
+++ b/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts
@@ -16,6 +16,44 @@ export function getUniqueSenderIds(notifications: Notification[]): string[] {
return Array.from(senderIds);
}
+/**
+ * GitHub PR notifications are triggered by GitHub users who usually aren't Macro
+ * users, so `sender_id` is empty. Their GitHub login lives in the notification
+ * metadata instead. Pull it out so the description can name who acted.
+ * @internal
+ */
+export function getGithubSenderLogin(
+ notification: Notification
+): string | undefined {
+ const metadata = notification.notification_metadata;
+ const content = (metadata as { content?: unknown }).content;
+ if (
+ content &&
+ typeof content === 'object' &&
+ 'senderGithubLogin' in content
+ ) {
+ const login = (content as { senderGithubLogin?: string | null })
+ .senderGithubLogin;
+ return login ?? undefined;
+ }
+ return undefined;
+}
+
+/**
+ * Gets unique GitHub sender logins from a notification stack, preserving order.
+ * @internal
+ */
+export function getUniqueGithubLogins(notifications: Notification[]): string[] {
+ const logins = new Set<string>();
+ for (const notification of notifications) {
+ const login = getGithubSenderLogin(notification);
+ if (login) {
+ logins.add(login);
+ }
+ }
+ return Array.from(logins);
+}
+
/**
* Gets the action verb for a notification type
* @internal
diff --git a/js/app/packages/entity/src/extractors-notification/notification-description.tsx b/js/app/packages/entity/src/extractors-notification/notification-description.tsx
index e33f8bb9db..5627bb8b6c 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-description.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-description.tsx
@@ -1,11 +1,14 @@
import type { NotificationType } from '@core/types';
import { tryMacroId, useDisplayNameParts } from '@core/user';
import type { NotificationStack } from '@notifications';
+import { createMemo } from 'solid-js';
import type { Notification } from '../types/notification';
import {
getActionVerb,
+ getGithubSenderLogin,
getTypeNoun,
getTypePreposition,
+ getUniqueGithubLogins,
getUniqueSenderIds,
} from './notification-description-helpers';
@@ -43,79 +46,70 @@ export function NotificationDescription(props: NotificationDescriptionProps) {
return 1;
};
- const primarySenderId = () => {
- if (props.notification?.sender_id) {
- return props.notification.sender_id;
- }
- if (props.stack) {
- const senderIds = getUniqueSenderIds(props.stack.notifications);
- return senderIds[0];
- }
- return undefined;
- };
-
- const senderIds = () => {
- if (!props.stack) return [];
- return getUniqueSenderIds(props.stack.notifications);
- };
-
- const additionalSenderCount = () => {
- if (!props.stack) return 0;
- return Math.max(0, senderIds().length - 1);
- };
-
- const hasMultipleSenders = () => additionalSenderCount() > 0;
-
- const primarySenderNameParts = () =>
- useDisplayNameParts(tryMacroId(primarySenderId() ?? ''), {
+ const macroFirstName = (id: string) => {
+ const parts = useDisplayNameParts(tryMacroId(id), {
emailFallback: 'local-part',
});
-
- const primarySenderFirstName = () => {
- const firstName = primarySenderNameParts().firstName();
- return firstName || primarySenderNameParts().fullName();
+ return parts.firstName() || parts.fullName();
};
- const secondarySenderNameParts = () =>
- useDisplayNameParts(tryMacroId(senderIds()[1] ?? ''), {
- emailFallback: 'local-part',
- });
+ // Sender display labels for the notification/stack. Macro senders resolve to
+ // their display name; GitHub PR senders (who usually aren't Macro users and so
+ // have no `sender_id`) fall back to the GitHub login carried in the
+ // notification metadata.
+ // Memoized so the per-sender name resolution (which has side effects: it
+ // queues a fetch and registers a reactive effect) runs once per dependency
+ // change rather than on every call from the description() formatters.
+ const senderLabels = createMemo((): string[] => {
+ if (props.notification) {
+ if (props.notification.sender_id) {
+ return [macroFirstName(props.notification.sender_id)];
+ }
+ const login = getGithubSenderLogin(props.notification);
+ return login ? [login] : [];
+ }
+ if (props.stack) {
+ const macroIds = getUniqueSenderIds(props.stack.notifications);
+ if (macroIds.length > 0) {
+ return macroIds.map(macroFirstName);
+ }
+ return getUniqueGithubLogins(props.stack.notifications);
+ }
+ return [];
+ });
- const secondarySenderFirstName = () => {
- const firstName = secondarySenderNameParts().firstName();
- return firstName || secondarySenderNameParts().fullName();
- };
+ const primarySenderLabel = () => senderLabels()[0];
+ const secondarySenderLabel = () => senderLabels()[1];
+ const additionalSenderCount = () => Math.max(0, senderLabels().length - 1);
+ const hasMultipleSenders = () => additionalSenderCount() > 0;
const description = () => {
const type = notificationType();
- const senderId = primarySenderId();
+ const sender = primarySenderLabel();
if (!type) return '';
// Single notification: "Peter mentioned you"
if (isSingleNotification()) {
- if (senderId && type !== 'ai_response') {
- return `${primarySenderFirstName()} ${getActionVerb(type)}`;
+ if (sender && type !== 'ai_response') {
+ return `${sender} ${getActionVerb(type)}`;
}
return getActionVerb(type);
}
// Stack with multiple senders
if (hasMultipleSenders()) {
- if (senderId) {
- const senderCount = senderIds().length;
- if (senderCount === 2) {
- return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${primarySenderFirstName()} and ${secondarySenderFirstName()}`;
- }
- // Three or more senders: "13 messages from Peter and 5 others"
- return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${primarySenderFirstName()} and ${additionalSenderCount()} ${additionalSenderCount() === 1 ? 'other' : 'others'}`;
+ const senderCount = senderLabels().length;
+ if (senderCount === 2) {
+ return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${sender} and ${secondarySenderLabel()}`;
}
- return `${count()} ${getTypeNoun(type, count())}`;
+ // Three or more senders: "13 messages from Peter and 5 others"
+ return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${sender} and ${additionalSenderCount()} ${additionalSenderCount() === 1 ? 'other' : 'others'}`;
}
// Stack with single sender: "Peter: 13 messages"
- if (senderId) {
- return `${primarySenderFirstName()}: ${count()} ${getTypeNoun(type, count())}`;
+ if (sender) {
+ return `${sender}: ${count()} ${getTypeNoun(type, count())}`;
}
return `${count()} ${getTypeNoun(type, count())}`;
};
diff --git a/js/app/packages/entity/tests/notification-description.test.ts b/js/app/packages/entity/tests/notification-description.test.ts
index db0ec14b31..36f3c91f62 100644
--- a/js/app/packages/entity/tests/notification-description.test.ts
+++ b/js/app/packages/entity/tests/notification-description.test.ts
@@ -1,11 +1,21 @@
import { describe, expect, it } from 'vitest';
import {
getActionVerb,
+ getGithubSenderLogin,
getTypeNoun,
+ getUniqueGithubLogins,
getUniqueSenderIds,
} from '../src/extractors-notification/notification-description-helpers';
import type { Notification } from '../src/types/notification';
+const githubNotification = (login: string | null | undefined): Notification =>
+ ({
+ notification_metadata: {
+ tag: 'github_pr_comment',
+ content: { senderGithubLogin: login },
+ },
+ }) as unknown as Notification;
+
describe('notification-description helpers', () => {
describe('getUniqueSenderIds', () => {
it('extracts unique sender IDs from notifications', () => {
@@ -72,6 +82,51 @@ describe('notification-description helpers', () => {
});
});
+ describe('getGithubSenderLogin', () => {
+ it('extracts the GitHub login from PR notification metadata', () => {
+ expect(getGithubSenderLogin(githubNotification('octocat'))).toBe(
+ 'octocat'
+ );
+ });
+
+ it('returns undefined when the login is null', () => {
+ expect(getGithubSenderLogin(githubNotification(null))).toBeUndefined();
+ });
+
+ it('returns undefined for non-GitHub notifications', () => {
+ const notification = {
+ notification_metadata: { tag: 'channel_mention', content: {} },
+ } as unknown as Notification;
+ expect(getGithubSenderLogin(notification)).toBeUndefined();
+ });
+ });
+
+ describe('getUniqueGithubLogins', () => {
+ it('extracts unique GitHub logins preserving order', () => {
+ const notifications = [
+ githubNotification('peter'),
+ githubNotification('gabriel'),
+ githubNotification('peter'),
+ ];
+ expect(getUniqueGithubLogins(notifications)).toEqual([
+ 'peter',
+ 'gabriel',
+ ]);
+ });
+
+ it('skips notifications without a login', () => {
+ const notifications = [
+ githubNotification('peter'),
+ githubNotification(null),
+ githubNotification('gabriel'),
+ ];
+ expect(getUniqueGithubLogins(notifications)).toEqual([
+ 'peter',
+ 'gabriel',
+ ]);
+ });
+ });
+
describe('getActionVerb', () => {
it('returns correct verb for channel_mention', () => {
expect(getActionVerb('channel_mention')).toBe('mentioned you');