Skip to content

Commit 4f1cd5a

Browse files
authored
feat(hovercard): show PR co-authors as a facepile (#132275)
* feat(hovercard): show PR co-authors as a facepile GitHub link hovercards named only the PR author, so a co-authored PR looked like solo work. Co-authors now appear as overlapping faces after the author, with "+N" for anyone past the three the card fetches. Trailers carry their own identity: GitHub's noreply form is `<accountId>+<login>@users.noreply.github.com`, so one commits page yields both the login and the avatar URL with no lookup per person, and the avatar goes through the existing inlining rather than being hotlinked. That keeps this to a single extra request, and it works anonymously — a GraphQL commit-authors query would have resolved trailers too, but only with a token. Co-authors are decoration on an already-useful card, so a failed, rate-limited, or oversized commits page degrades to no faces instead of failing the preview. Issues skip the request entirely. * fix(hovercard): use the defined --muted token for the co-author overflow --text-muted is not an OpenClaw Control UI token, so base-theme-tokens flagged it as an undefined reference. The card's own author row already uses --muted. * fix(hovercard): guard the co-author commits fetch against redirects The commits request carried the operator's token but no redirect guard, so a rename or transfer could carry it into a repository the token can read and the viewer cannot, and co-author data derived from that private repository would reach the browser. The item fetch already had this guard inline. It is now a named local shared by every credentialed fetch here, and the redirect parser accepts the commits suffix so a legitimate rename still resolves to its repository for the visibility check instead of failing shape validation. Reported by ClawSweeper as P1 on 826f5e9. * fix(hovercard): count faceless co-authors in the overflow The overflow was derived from fetched co-authors rather than rendered faces. Avatar inlining is optional, so a co-author whose avatar failed produced no face and was not counted in "+N" either: five co-authors with one failed avatar rendered two faces and "+2", silently dropping a person. Reported by ClawSweeper as P2 on f7a028d. * fix(hovercard): give the co-author facepile an accessible name The faces are decorative images and the logins lived only in a title attribute, which assistive tech does not reliably announce, so the whole co-author signal was sighted-only. The group is now one labelled image carrying the same names, matching the role="img" pattern used elsewhere in the sidebar. Reported by ClawSweeper as P2 on 9026545.
1 parent 293c433 commit 4f1cd5a

8 files changed

Lines changed: 534 additions & 57 deletions

‎src/gateway/control-ui-contract.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ export const CONTROL_UI_SESSION_PULL_REQUESTS_CHANGED_EVENT =
1414
export const CONTROL_UI_SESSION_PULL_REQUESTS_MAX_KEYS = 200;
1515

1616
/** Public GitHub metadata rendered by Control UI link hover cards. */
17+
/**
18+
* One co-author resolved from a `Co-authored-by` trailer. Only trailers using
19+
* GitHub's `<id>+<login>@users.noreply.github.com` form resolve, because the id
20+
* yields both the login and the avatar without a per-person API lookup.
21+
*/
22+
type ControlUiGitHubPreviewCoAuthor = {
23+
login: string;
24+
avatarDataUrl?: string;
25+
};
26+
1727
export type ControlUiGitHubPreview = {
1828
additions?: number;
1929
avatarDataUrl?: string;
30+
/** Bounded to the faces the card renders; `coAuthorCount` carries the true total. */
31+
coAuthors?: ControlUiGitHubPreviewCoAuthor[];
32+
coAuthorCount?: number;
2033
changedFiles?: number;
2134
closedAt?: string;
2235
comments?: number;

‎src/gateway/control-ui-github-preview.test.ts‎

Lines changed: 171 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
parseControlUiGitHubPreviewTarget,
1414
} from "./control-ui-github-preview.js";
1515

16-
function githubJson(body: Record<string, unknown>, status = 200): Response {
16+
// List endpoints such as /pulls/{n}/commits return arrays, not objects.
17+
function githubJson(body: unknown, status = 200): Response {
1718
return new Response(JSON.stringify(body), {
1819
status,
1920
headers: { "Content-Type": "application/json" },
@@ -134,14 +135,18 @@ describe("loadControlUiGitHubPreview", () => {
134135
});
135136

136137
it("normalizes public metadata and embeds a bounded GitHub avatar", async () => {
137-
const fetchMock = vi
138-
.fn<typeof fetch>()
139-
.mockResolvedValueOnce(githubJson(previewPayload()))
140-
.mockResolvedValueOnce(
141-
new Response(new Uint8Array([137, 80, 78, 71]), {
138+
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input) => {
139+
const url = requestUrl(input);
140+
if (url.includes("/commits")) {
141+
return githubJson([]);
142+
}
143+
if (url.includes("avatars.githubusercontent.com")) {
144+
return new Response(new Uint8Array([137, 80, 78, 71]), {
142145
headers: { "Content-Type": "image/png" },
143-
}),
144-
);
146+
});
147+
}
148+
return githubJson(previewPayload());
149+
});
145150
const target = { kind: "pull" as const, number: 99816, owner: "openclaw", repo: "openclaw" };
146151

147152
const first = await loadControlUiGitHubPreview(target, fetchMock);
@@ -160,11 +165,16 @@ describe("loadControlUiGitHubPreview", () => {
160165
repo: "openclaw",
161166
});
162167
expect(second).toEqual(first);
163-
expect(fetchMock).toHaveBeenCalledTimes(2);
168+
// Item, avatar, and the single commits page that carries co-author trailers.
169+
expect(fetchMock).toHaveBeenCalledTimes(3);
164170
expect(fetchMock.mock.calls[0]?.[0]).toBe(
165171
"https://api.github.com/repos/openclaw/openclaw/pulls/99816",
166172
);
167-
const avatarRequest = fetchMock.mock.calls[1]?.[0];
173+
const avatarRequest = fetchMock.mock.calls
174+
.map(([input]) => input)
175+
.find((input) => {
176+
return input instanceof URL && input.href.includes("avatars.githubusercontent.com");
177+
});
168178
expect(avatarRequest).toBeInstanceOf(URL);
169179
expect(avatarRequest instanceof URL ? avatarRequest.href : "").toContain(
170180
"avatars.githubusercontent.com/u/58493",
@@ -174,6 +184,98 @@ describe("loadControlUiGitHubPreview", () => {
174184
expect(avatarRequest instanceof URL ? avatarRequest.searchParams.get("s") : null).toBe("64");
175185
});
176186

187+
it("resolves co-authors from noreply trailers without a lookup per person", async () => {
188+
const commits = [
189+
{
190+
commit: {
191+
message: "feat: one\n\nCo-authored-by: Ada King <[email protected]>",
192+
},
193+
},
194+
// Repeat plus a different case: the same person must fold into one face.
195+
{ commit: { message: "fix: two\n\nCo-authored-by: ada <[email protected]>" } },
196+
{
197+
commit: { message: "fix: three\n\nCo-authored-by: Mira <[email protected]>" },
198+
},
199+
// The PR author is not their own co-author.
200+
{
201+
commit: {
202+
message:
203+
"fix: four\n\nCo-authored-by: steipete <[email protected]>",
204+
},
205+
},
206+
// A plain address carries no account id, so it cannot resolve to a face.
207+
{ commit: { message: "fix: five\n\nCo-authored-by: Someone <[email protected]>" } },
208+
];
209+
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input) => {
210+
const url = requestUrl(input);
211+
if (url.includes("/commits")) {
212+
return githubJson(commits);
213+
}
214+
if (url.includes("avatars.githubusercontent.com")) {
215+
return new Response(new Uint8Array([137, 80, 78, 71]), {
216+
headers: { "Content-Type": "image/png" },
217+
});
218+
}
219+
return githubJson(previewPayload());
220+
});
221+
222+
const preview = await loadControlUiGitHubPreview(
223+
{ kind: "pull", number: 88101, owner: "openclaw", repo: "openclaw" },
224+
fetchMock,
225+
);
226+
227+
expect(preview.coAuthorCount).toBe(2);
228+
expect(preview.coAuthors).toEqual([
229+
{ login: "ada", avatarDataUrl: "data:image/png;base64,iVBORw==" },
230+
{ login: "mira", avatarDataUrl: "data:image/png;base64,iVBORw==" },
231+
]);
232+
// The account id in the trailer is the avatar, so no per-person API lookup.
233+
const avatarUrls = fetchMock.mock.calls
234+
.map(([input]) => requestUrl(input))
235+
.filter((url) => url.includes("avatars.githubusercontent.com"));
236+
expect(avatarUrls).toEqual([
237+
"https://avatars.githubusercontent.com/u/58493?s=64",
238+
// Co-author avatars go through the same bounded ?s=64 normalization.
239+
"https://avatars.githubusercontent.com/u/20?s=64",
240+
"https://avatars.githubusercontent.com/u/7?s=64",
241+
]);
242+
});
243+
244+
it("keeps the card when the commits page fails and omits co-authors for issues", async () => {
245+
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input) => {
246+
const url = requestUrl(input);
247+
if (url.includes("/commits")) {
248+
return githubJson({ message: "rate limited" }, 403);
249+
}
250+
if (url.includes("avatars.githubusercontent.com")) {
251+
return new Response(new Uint8Array([137, 80, 78, 71]), {
252+
headers: { "Content-Type": "image/png" },
253+
});
254+
}
255+
return githubJson(previewPayload());
256+
});
257+
258+
const pull = await loadControlUiGitHubPreview(
259+
{ kind: "pull", number: 88102, owner: "openclaw", repo: "openclaw" },
260+
fetchMock,
261+
);
262+
263+
expect(pull.login).toBe("steipete");
264+
expect(pull.coAuthors).toBeUndefined();
265+
expect(pull.coAuthorCount).toBeUndefined();
266+
267+
fetchMock.mockClear();
268+
await loadControlUiGitHubPreview(
269+
{ kind: "issue", number: 88103, owner: "openclaw", repo: "openclaw" },
270+
fetchMock,
271+
);
272+
273+
// Issues have no commits, so they must not spend the extra request at all.
274+
expect(
275+
fetchMock.mock.calls.filter(([input]) => requestUrl(input).includes("/commits")),
276+
).toHaveLength(0);
277+
});
278+
177279
it("does not reuse cached previews after the GitHub credential scope changes", async () => {
178280
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input, init) => {
179281
const url = requestUrl(input);
@@ -327,24 +429,25 @@ describe("loadControlUiGitHubPreview", () => {
327429

328430
it("retries stale optional authentication anonymously for public previews", async () => {
329431
vi.stubEnv("GH_TOKEN", "stale-github-token");
330-
const fetchMock = vi
331-
.fn<typeof fetch>()
332-
.mockResolvedValueOnce(githubJson({ message: "Bad credentials" }, 401))
333-
.mockResolvedValueOnce(
334-
githubJson(
335-
previewPayload({
336-
user: { login: "octocat" },
337-
}),
338-
),
339-
);
432+
let itemCalls = 0;
433+
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input) => {
434+
const url = requestUrl(input);
435+
if (url.includes("/commits")) {
436+
return githubJson([]);
437+
}
438+
itemCalls += 1;
439+
return itemCalls === 1
440+
? githubJson({ message: "Bad credentials" }, 401)
441+
: githubJson(previewPayload({ user: { login: "octocat" } }));
442+
});
340443

341444
const preview = await loadControlUiGitHubPreview(
342445
{ kind: "pull", number: 70012, owner: "openclaw", repo: "openclaw" },
343446
fetchMock,
344447
);
345448

346449
expect(preview.login).toBe("octocat");
347-
expect(fetchMock).toHaveBeenCalledTimes(2);
450+
expect(itemCalls).toBe(2);
348451
expect(fetchMock.mock.calls[0]?.[1]?.headers).toHaveProperty(
349452
"Authorization",
350453
"Bearer stale-github-token",
@@ -417,6 +520,53 @@ describe("loadControlUiGitHubPreview", () => {
417520
expect(redirectResponse.bodyUsed).toBe(true);
418521
});
419522

523+
it("re-checks visibility when the commits request is redirected into another repository", async () => {
524+
vi.stubEnv("GH_TOKEN", "github-test-token");
525+
const visibilityChecks: string[] = [];
526+
const fetchMock = vi.fn<typeof fetch>().mockImplementation(async (input) => {
527+
const url = requestUrl(input);
528+
if (url.endsWith("/repos/openclaw/openclaw")) {
529+
visibilityChecks.push(url);
530+
return githubJson({ private: false });
531+
}
532+
if (url.endsWith("/repos/openclaw/secret")) {
533+
visibilityChecks.push(url);
534+
// The token can read it; the Control UI viewer must not.
535+
return githubJson({ private: true });
536+
}
537+
if (url.includes("/commits")) {
538+
return new Response("moved", {
539+
status: 301,
540+
headers: {
541+
Location: "https://api.github.com/repos/openclaw/secret/pulls/88201/commits",
542+
},
543+
});
544+
}
545+
if (url.includes("avatars.githubusercontent.com")) {
546+
return new Response(new Uint8Array([137, 80, 78, 71]), {
547+
headers: { "Content-Type": "image/png" },
548+
});
549+
}
550+
return githubJson(previewPayload());
551+
});
552+
553+
const preview = await loadControlUiGitHubPreview(
554+
{ kind: "pull", number: 88201, owner: "openclaw", repo: "openclaw" },
555+
fetchMock,
556+
);
557+
558+
// The card still renders; only the co-author decoration is withheld.
559+
expect(preview.login).toBe("steipete");
560+
expect(preview.coAuthors).toBeUndefined();
561+
// The redirect target was visibility-checked, and its commits were never fetched.
562+
expect(visibilityChecks).toContain("https://api.github.com/repos/openclaw/secret");
563+
expect(
564+
fetchMock.mock.calls.filter(([input]) =>
565+
requestUrl(input).startsWith("https://api.github.com/repos/openclaw/secret/pulls"),
566+
),
567+
).toHaveLength(0);
568+
});
569+
420570
it("stops private and missing repositories before fetching item metadata", async () => {
421571
vi.stubEnv("GH_TOKEN", "github-test-token");
422572
const fetchMock = vi

0 commit comments

Comments
 (0)