ソースを参照

Uses GitHub Avatar for GH 'noreply' email address

Partial fix for #281- covers the `*@users.noreply.github.com` case.

The `users.noreply.github.com` domain comes from users
making use GitHub's 'email privacy' feature.
Since the noreply address doesn't accept email, a user can't link
their preferred Gravatar to this type of email address.

The upside is that this address is easily parsable into:
* (optional) Github User ID
* Github User Name

We can use either to create the associated avatar link
without actually having to do an additonal request
against Github's user search API.
main
Brian Bolte 5年前
committed by Eric Amodio
コミット
1657829069
1個のファイルの変更11行の追加1行の削除
  1. +11
    -1
      src/avatars.ts

+ 11
- 1
src/avatars.ts ファイルの表示

@ -15,6 +15,14 @@ export function clearGravatarCache() {
gravatarCache.clear();
}
function getAvatarFromGithubNoreplyAddress(email: string | undefined, size: number = 16): Uri | undefined {
if (!email) return undefined;
const match = email.match(/^(?:(?<userId>\d+)\+)?(?<userName>[a-zA-Z\d-]{1,39})@users.noreply.github.com$/);
if (!match || !match.groups) return undefined;
const { userName, userId } = match.groups;
return Uri.parse(`https://avatars.githubusercontent.com/${userId ? `u/${userId}` : userName}?size=${size}`);
}
export function getGravatarUri(email: string | undefined, fallback: GravatarDefaultStyle, size: number = 16): Uri {
const hash =
email != null && email.length !== 0 ? Strings.md5(email.trim().toLowerCase(), 'hex') : missingGravatarHash;
@ -23,7 +31,9 @@ export function getGravatarUri(email: string | undefined, fallback: GravatarDefa
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${hash}.jpg?s=${size}&d=${fallback}`);
gravatar =
getAvatarFromGithubNoreplyAddress(email, size) ||
Uri.parse(`https://www.gravatar.com/avatar/${hash}.jpg?s=${size}&d=${fallback}`);
gravatarCache.set(key, gravatar);
return gravatar;

読み込み中…
キャンセル
保存