Skip to content

Commit 207c36b

Browse files
Copilotalexr00
andcommitted
Fix avatar display on GitHub Enterprise by passing email to avatar fallback
- Modified parseAccount to pass author.email to getAvatarWithEnterpriseFallback - Added comprehensive tests for getAvatarWithEnterpriseFallback function - Tests verify Gravatar fallback works when avatarUrl is empty on Enterprise Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 6fd5fc3 commit 207c36b

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/github/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export function parseAccount(
653653

654654
// In some places, Copilot comes in as a user, and in others as a bot
655655

656-
const finalAvatarUrl = githubRepository ? getAvatarWithEnterpriseFallback(avatarUrl, undefined, githubRepository.remote.isEnterprise) : avatarUrl;
656+
const finalAvatarUrl = githubRepository ? getAvatarWithEnterpriseFallback(avatarUrl, author.email ?? undefined, githubRepository.remote.isEnterprise) : avatarUrl;
657657

658658
return {
659659
login: author.login,

src/test/github/utils.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { default as assert } from 'assert';
7-
import { getPRFetchQuery, sanitizeIssueTitle } from '../../github/utils';
7+
import { getPRFetchQuery, sanitizeIssueTitle, getAvatarWithEnterpriseFallback } from '../../github/utils';
88

99
describe('utils', () => {
1010

@@ -41,4 +41,44 @@ describe('utils', () => {
4141
});
4242
});
4343
});
44+
45+
describe('getAvatarWithEnterpriseFallback', () => {
46+
it('returns avatarUrl for non-enterprise when provided', () => {
47+
const avatarUrl = 'https://avatars.githubusercontent.com/u/12345';
48+
const result = getAvatarWithEnterpriseFallback(avatarUrl, undefined, false);
49+
assert.strictEqual(result, avatarUrl);
50+
});
51+
52+
it('returns avatarUrl for enterprise when avatarUrl is provided', () => {
53+
const avatarUrl = 'https://enterprise.github.com/avatars/u/12345';
54+
const result = getAvatarWithEnterpriseFallback(avatarUrl, 'user@example.com', true);
55+
assert.strictEqual(result, avatarUrl);
56+
});
57+
58+
it('returns Gravatar URL for enterprise when avatarUrl is empty and email is provided', () => {
59+
const email = 'user@example.com';
60+
const result = getAvatarWithEnterpriseFallback('', email, true);
61+
assert.ok(result);
62+
assert.ok(result!.startsWith('https://www.gravatar.com/avatar/'));
63+
assert.ok(result!.includes('s=200')); // default size
64+
assert.ok(result!.includes('d=retro')); // default style
65+
});
66+
67+
it('returns undefined for enterprise when both avatarUrl and email are empty', () => {
68+
const result = getAvatarWithEnterpriseFallback('', undefined, true);
69+
assert.strictEqual(result, undefined);
70+
});
71+
72+
it('returns avatarUrl for enterprise when avatarUrl has only whitespace', () => {
73+
const result = getAvatarWithEnterpriseFallback(' ', 'user@example.com', true);
74+
assert.strictEqual(result, undefined);
75+
});
76+
77+
it('generates consistent Gravatar hash for same email', () => {
78+
const email = 'test@example.com';
79+
const result1 = getAvatarWithEnterpriseFallback('', email, true);
80+
const result2 = getAvatarWithEnterpriseFallback('', email, true);
81+
assert.strictEqual(result1, result2);
82+
});
83+
});
4484
});

0 commit comments

Comments
 (0)