From 109b2614d28e0e2a248d73cdbccacf37069a766d Mon Sep 17 00:00:00 2001
From: Angel Aviel Domaoan <13580338+tenshiAMD@users.noreply.github.com>
Date: Sat, 24 Sep 2022 01:17:50 +0800
Subject: [PATCH] fix: set alt value for contributor image with no complete
name (#335)
---
src/generate/__tests__/fixtures/contributors.json | 5 +++++
src/generate/__tests__/format-contributor.js | 10 ++++++++++
src/generate/format-contributor.js | 4 +++-
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/generate/__tests__/fixtures/contributors.json b/src/generate/__tests__/fixtures/contributors.json
index 7872bd3..7ede43c 100644
--- a/src/generate/__tests__/fixtures/contributors.json
+++ b/src/generate/__tests__/fixtures/contributors.json
@@ -25,6 +25,11 @@
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
"contributions": ["translation"]
},
+ "nocompletename": {
+ "login": "nocompletename",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
+ "contributions": ["translation"]
+ },
"nologin_badrole": {
"name": "Wildly Misconfigured",
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
diff --git a/src/generate/__tests__/format-contributor.js b/src/generate/__tests__/format-contributor.js
index 9dd4b63..c158cb3 100644
--- a/src/generate/__tests__/format-contributor.js
+++ b/src/generate/__tests__/format-contributor.js
@@ -77,3 +77,13 @@ test('format contributor with no GitHub account', () => {
expect(formatContributor(options, contributor)).toBe(expected)
})
+
+test('format contributor with no complete name', () => {
+ const contributor = contributors.nocompletename
+ const {options} = fixtures()
+
+ const expected =
+ '
nocompletename
🌍'
+
+ expect(formatContributor(options, contributor)).toBe(expected)
+})
diff --git a/src/generate/format-contributor.js b/src/generate/format-contributor.js
index 7966a93..9f489f4 100644
--- a/src/generate/format-contributor.js
+++ b/src/generate/format-contributor.js
@@ -17,7 +17,9 @@ const contributorTemplate = _.template(
const defaultImageSize = 100
function defaultTemplate(templateData) {
- const name = escapeName(templateData.contributor.name)
+ const rawName =
+ templateData.contributor.name || templateData.contributor.login
+ const name = escapeName(rawName)
const avatar = avatarTemplate(
_.assign(templateData, {
name,