From 86aa24cbf9d003a3ddfb62eec54c56841359e12d Mon Sep 17 00:00:00 2001 From: "Gilad S." Date: Fri, 2 Aug 2024 16:46:23 +0000 Subject: [PATCH 1/5] feat(git changelog): resolve profile picture for GitHub emails --- .../src/vite/helpers.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts index 04d8ac30..0d5cb5d4 100644 --- a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts +++ b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts @@ -455,6 +455,18 @@ 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 +474,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` } From d76b1ceeb5644a89e0c93ca9237a00e7e1c62513 Mon Sep 17 00:00:00 2001 From: "Gilad S." Date: Fri, 2 Aug 2024 17:09:06 +0000 Subject: [PATCH 2/5] test(git changelog): `getAvatarFromGithubNoreplyAddress` --- .../src/vite/helpers.test.ts | 33 +++++++++++++++++++ .../src/vite/helpers.ts | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/vitepress-plugin-git-changelog/src/vite/helpers.test.ts b/packages/vitepress-plugin-git-changelog/src/vite/helpers.test.ts index adfa664e..fa3f2216 100644 --- a/packages/vitepress-plugin-git-changelog/src/vite/helpers.test.ts +++ b/packages/vitepress-plugin-git-changelog/src/vite/helpers.test.ts @@ -8,6 +8,7 @@ import { findMapAuthorByEmail, findMapAuthorByName, findMapAuthorLink, + getAvatarFromGithubNoreplyAddress, getCoAuthors, mergeRawCommits, newAvatarForAuthor, @@ -535,6 +536,38 @@ describe('newAvatarForAuthor', () => { 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 0d5cb5d4..f081069e 100644 --- a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts +++ b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts @@ -455,7 +455,7 @@ export function findMapAuthorI18n(mappedAuthor: Contributor): Record Date: Fri, 2 Aug 2024 17:15:32 +0000 Subject: [PATCH 3/5] feat(git changelog): hide "no changes" text option --- .../src/client/components/Changelog.vue | 2 +- packages/vitepress-plugin-git-changelog/src/client/types.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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') }}
Date: Fri, 2 Aug 2024 17:20:51 +0000 Subject: [PATCH 4/5] docs(git changelog): add link to comment for context --- packages/vitepress-plugin-git-changelog/src/vite/helpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts b/packages/vitepress-plugin-git-changelog/src/vite/helpers.ts index f081069e..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,7 @@ export function findMapAuthorI18n(mappedAuthor: Contributor): Record Date: Fri, 2 Aug 2024 21:09:52 +0000 Subject: [PATCH 5/5] docs(git changelog): `hideChangelogNoChangesText` option --- .../vitepress-plugin-git-changelog/configure-ui.md | 4 ++++ .../vitepress-plugin-git-changelog/configure-ui.md | 4 ++++ 2 files changed, 8 insertions(+) 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 */