Skip to content

Commit 579d1ed

Browse files
Copilotalexr00
andcommitted
Extract avatar URL check into utility function
Add DataUri.isGitHubDotComAvatar() utility to check if an avatar URL is from GitHub.com. Use this utility in all tree view nodes instead of inline .includes() checks. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 2672593 commit 579d1ed

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/common/uri.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ export namespace DataUri {
290290
return asImageDataURI(contents);
291291
}
292292

293+
/**
294+
* Checks if an avatar URL is from GitHub.com (as opposed to GitHub Enterprise).
295+
* GitHub.com avatar URLs contain 'githubusercontent.com', while enterprise avatar URLs do not.
296+
* @param avatarUrl The avatar URL to check
297+
* @returns true if the avatar is from GitHub.com, false otherwise
298+
*/
299+
export function isGitHubDotComAvatar(avatarUrl: string | undefined): boolean {
300+
return avatarUrl?.includes('githubusercontent.com') ?? false;
301+
}
302+
293303
export async function avatarCirclesAsImageDataUris(context: vscode.ExtensionContext, users: (IAccount | ITeam)[], height: number, width: number, localOnly?: boolean): Promise<(vscode.Uri | undefined)[]> {
294304
let cacheLogOrder: string[];
295305
const cacheLog = cacheLogUri(context);

src/issues/issuesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class IssuesTreeData
102102

103103
if (avatarUser) {
104104
// For enterprise, use placeholder icon instead of trying to fetch avatar
105-
if (!avatarUser.avatarUrl?.includes('githubusercontent.com')) {
105+
if (!DataUri.isGitHubDotComAvatar(avatarUser.avatarUrl)) {
106106
treeItem.iconPath = new vscode.ThemeIcon('github');
107107
} else {
108108
treeItem.iconPath = (await DataUri.avatarCirclesAsImageDataUris(this.context, [avatarUser], 16, 16))[0] ??

src/view/treeNodes/commitNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class CommitNode extends TreeNode implements vscode.TreeItem {
4141
async getTreeItem(): Promise<vscode.TreeItem> {
4242
if (this.commit.author) {
4343
// For enterprise, use placeholder icon instead of trying to fetch avatar
44-
if (!this.commit.author.avatar_url?.includes('githubusercontent.com')) {
44+
if (!DataUri.isGitHubDotComAvatar(this.commit.author.avatar_url)) {
4545
this.iconPath = new vscode.ThemeIcon('github');
4646
} else {
4747
const author: IAccount = { id: this.commit.author.node_id, login: this.commit.author.login, url: this.commit.author.url, avatarUrl: this.commit.author.avatar_url, accountType: this.commit.author.type as AccountType };

src/view/treeNodes/pullRequestNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class PRNode extends TreeNode implements vscode.CommentingRangeProvider2
272272

273273
private async _getAuthorIcon(): Promise<vscode.Uri | vscode.ThemeIcon> {
274274
// For enterprise, use placeholder icon instead of trying to fetch avatar
275-
if (!this.pullRequestModel.author.avatarUrl?.includes('githubusercontent.com')) {
275+
if (!DataUri.isGitHubDotComAvatar(this.pullRequestModel.author.avatarUrl)) {
276276
return new vscode.ThemeIcon('github');
277277
}
278278
return (await DataUri.avatarCirclesAsImageDataUris(this._folderReposManager.context, [this.pullRequestModel.author], 16, 16))[0]

src/view/treeNodes/repositoryChangesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
112112
override async getTreeItem(): Promise<vscode.TreeItem> {
113113
this.setLabel();
114114
// For enterprise, use placeholder icon instead of trying to fetch avatar
115-
if (!this.pullRequestModel.author.avatarUrl?.includes('githubusercontent.com')) {
115+
if (!DataUri.isGitHubDotComAvatar(this.pullRequestModel.author.avatarUrl)) {
116116
this.iconPath = new vscode.ThemeIcon('github');
117117
} else {
118118
this.iconPath = (await DataUri.avatarCirclesAsImageDataUris(this._pullRequestManager.context, [this.pullRequestModel.author], 16, 16))[0];

0 commit comments

Comments
 (0)