diff --git a/docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui.md b/docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui.md index 40d3c6e7..87833138 100644 --- a/docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui.md +++ b/docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui.md @@ -145,6 +145,10 @@ export interface Options { * Whether to hide the changelog h2 header */ hideChangelogHeader?: boolean + /** + * Whether to hide the changelog "No changes" text when there are no changes + */ + hideChangelogNoChangesText?: boolean /** * Whether to hide the contributors h2 header */ diff --git a/docs/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui.md b/docs/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui.md index 7ec034b0..93e700b4 100644 --- a/docs/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui.md +++ b/docs/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui.md @@ -145,6 +145,10 @@ export interface Options { * Whether to hide the changelog h2 header */ hideChangelogHeader?: boolean + /** + * Whether to hide the changelog "No changes" text when there are no changes + */ + hideChangelogNoChangesText?: boolean /** * Whether to hide the contributors h2 header */ diff --git a/packages/vitepress-plugin-git-changelog/src/client/components/Changelog.vue b/packages/vitepress-plugin-git-changelog/src/client/components/Changelog.vue index 22d98da3..aefcc2d8 100644 --- a/packages/vitepress-plugin-git-changelog/src/client/components/Changelog.vue +++ b/packages/vitepress-plugin-git-changelog/src/client/components/Changelog.vue @@ -67,7 +67,7 @@ onMounted(() => { {{ t('changelog.title') }} -
+
{{ t('noLogs', { omitEmpty: true }) || t('changelog.noData') }}
{ expect(avatar).toEqual('https://gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?d=retro') }) + + it('should return the commit author avatar for GitHub noreply email without user ID', async () => { + const avatar = await newAvatarForAuthor(undefined, 'user@users.noreply.github.com') + + expect(avatar).toEqual('https://avatars.githubusercontent.com/user?size=80') + }) + + it('should return the commit author avatar for GitHub noreply email with user ID', async () => { + const avatar = await newAvatarForAuthor(undefined, '123456+user@users.noreply.github.com') + + expect(avatar).toEqual('https://avatars.githubusercontent.com/u/123456?size=80') + }) +}) + +describe('getAvatarFromGithubNoreplyAddress', () => { + it('should return undefined for email it cannot handle', async () => { + const avatar = await getAvatarFromGithubNoreplyAddress('user@example.com') + + expect(avatar).toEqual(undefined) + }) + + it('should return the commit author avatar for GitHub noreply email without user ID', async () => { + const avatar = await getAvatarFromGithubNoreplyAddress('user@users.noreply.github.com') + + expect(avatar).toEqual('https://avatars.githubusercontent.com/user?size=80') + }) + + it('should return the commit author avatar for GitHub noreply email with user ID', async () => { + const avatar = await getAvatarFromGithubNoreplyAddress('123456+user@users.noreply.github.com') + + expect(avatar).toEqual('https://avatars.githubusercontent.com/u/123456?size=80') + }) }) describe('parseCommits', () => { diff --git a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts index 04d8ac30..64213ea2 100644 --- a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts +++ b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts @@ -455,6 +455,19 @@ export function findMapAuthorI18n(mappedAuthor: Contributor): Record\d+)\+)?(?[a-zA-Z\d-]{1,39})@users.noreply.github.com$/) + if (!match || !match.groups) + return undefined + + const { userName, userId } = match.groups + return `https://avatars.githubusercontent.com/${userId ? `u/${userId}` : userName}?size=${size}` +} + export async function newAvatarForAuthor(mappedAuthor: Contributor | undefined, email: string): Promise { if (mappedAuthor) { if (mappedAuthor.avatar) @@ -462,5 +475,10 @@ export async function newAvatarForAuthor(mappedAuthor: Contributor | undefined, if (mappedAuthor.username) return `https://github.com/${mappedAuthor.username}.png` } + + const githubProfilePicture = getAvatarFromGithubNoreplyAddress(email) + if (githubProfilePicture != null) + return githubProfilePicture + return `https://gravatar.com/avatar/${await digestStringAsSHA256(email)}?d=retro` }