Skip to content

Commit 2957a71

Browse files
authored
Fix user avatar display in comment widget for GitHub Enterprise (#8551)
* Initial plan * Changes before error encountered Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Initial plan for fixing avatar display in comment widget for GitHub Enterprise Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix avatar display in comment widget for GitHub Enterprise Apply isGitHubDotComAvatar check to comment widget code to prevent broken avatar display for GitHub Enterprise users. For enterprise avatars (non-githubusercontent.com URLs), skip fetching the avatar and show no icon instead of a broken image. Fixes: - setReplyAuthor() in utils.ts (reply area avatar) - TemporaryComment constructor in prComment.ts - GHPRComment constructor in prComment.ts Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add parens * Merge branch 'main' into copilot/fix-avatar-in-comment-widget
1 parent 3755bdd commit 2957a71

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/github/prComment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class TemporaryComment extends CommentBase {
175175
this.mode = vscode.CommentMode.Preview;
176176
this.originalAuthor = {
177177
name: currentUser.specialDisplayName ?? currentUser.login,
178-
iconPath: currentUser.avatarUrl ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
178+
iconPath: (currentUser.avatarUrl && DataUri.isGitHubDotComAvatar(currentUser.avatarUrl)) ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
179179
};
180180
this.label = isDraft ? vscode.l10n.t('Pending') : undefined;
181181
this.state = isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
@@ -238,12 +238,12 @@ export class GHPRComment extends CommentBase {
238238
this.rawComment = comment;
239239
this.originalAuthor = {
240240
name: comment.user?.specialDisplayName ?? comment.user!.login,
241-
iconPath: comment.user && comment.user.avatarUrl ? vscode.Uri.parse(comment.user.avatarUrl) : undefined,
241+
iconPath: (comment.user && comment.user.avatarUrl && DataUri.isGitHubDotComAvatar(comment.user.avatarUrl)) ? vscode.Uri.parse(comment.user.avatarUrl) : undefined,
242242
};
243243
const url = vscode.Uri.parse(comment.url);
244244
this.githubRepository = githubRepositories?.find(repo => repo.remote.host === url.authority);
245245

246-
const avatarUrisPromise = comment.user ? DataUri.avatarCirclesAsImageDataUris(context, [comment.user], 28, 28) : Promise.resolve([]);
246+
const avatarUrisPromise = (comment.user && DataUri.isGitHubDotComAvatar(comment.user.avatarUrl)) ? DataUri.avatarCirclesAsImageDataUris(context, [comment.user], 28, 28) : Promise.resolve([]);
247247
this.doSetBody(comment.body, !comment.user).then(async () => { // only refresh if there's no user. If there's a user, we'll refresh in the then.
248248
const avatarUris = await avatarUrisPromise;
249249
if (avatarUris.length > 0) {

src/github/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export function threadRange(startLine: number, endLine: number, endCharacter?: n
104104
export async function setReplyAuthor(thread: vscode.CommentThread | vscode.CommentThread2, currentUser: IAccount, context: vscode.ExtensionContext) {
105105
if (currentUser.avatarUrl) {
106106
const thread2 = thread as vscode.CommentThread2;
107+
if (!DataUri.isGitHubDotComAvatar(currentUser.avatarUrl)) {
108+
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: undefined };
109+
return;
110+
}
107111
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: vscode.Uri.parse(currentUser.avatarUrl) };
108112
const uri = await DataUri.avatarCirclesAsImageDataUris(context, [currentUser], 28, 28);
109113
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: uri[0] };

0 commit comments

Comments
 (0)