From e905222e59e12413f6a4e4b7cc58eec51eab696c Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 21:01:36 -0300 Subject: [PATCH 1/7] fix(emoji): Use colorful version of warning emoji --- lib/util/emoji.spec.ts | 33 ++++++++++++++++++++++++--------- lib/util/emoji.ts | 9 ++++++++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/util/emoji.spec.ts b/lib/util/emoji.spec.ts index 97e9c9309bc1eb..c9d8e099a87223 100644 --- a/lib/util/emoji.spec.ts +++ b/lib/util/emoji.spec.ts @@ -21,6 +21,11 @@ describe('util/emoji', () => { expect(emojify(':foo: :bar: :bee:')).toBe(':foo: :bar: ๐Ÿ'); }); + it('convert warning shortcode to emoji', () => { + const warning = emojify(':warning:'); + expect(warning).toBe('โš ๏ธ'); + }); + it('does not encode when config option is disabled', () => { setEmojiConfig({ unicodeEmoji: false }); expect(emojify('Let it :bee:')).toBe('Let it :bee:'); @@ -54,20 +59,30 @@ describe('util/emoji', () => { expect(unemojify(unsupported)).toBe('๏ฟฝ'); }); }); - }); - describe('problem characters', () => { - it.each(['๐Ÿš€', '๐Ÿ’Ž', '๐Ÿงน', '๐Ÿ“ฆ'])('converts %s forth and back', (char) => { + it('converts warning emoji to shortcode', () => { setEmojiConfig({ unicodeEmoji: false }); - const codified = unemojify(char); - expect(codified).not.toEqual(char); - - setEmojiConfig({ unicodeEmoji: true }); - const emojified = emojify(codified); - expect(emojified).toEqual(char); + const emoji = 'โš ๏ธ'; + const result = unemojify(emoji); + expect(result).toBe(':warning:'); }); }); + describe('problem characters', () => { + it.each(['๐Ÿš€', '๐Ÿ’Ž', '๐Ÿงน', '๐Ÿ“ฆ', 'โš ๏ธ'])( + 'converts %s forth and back', + (char) => { + setEmojiConfig({ unicodeEmoji: false }); + const codified = unemojify(char); + expect(codified).not.toEqual(char); + + setEmojiConfig({ unicodeEmoji: true }); + const emojified = emojify(codified); + expect(emojified).toEqual(char); + }, + ); + }); + describe('stripEmojis', () => { const makeEmoji = (hexCode: string): string => fromCodepointToUnicode(fromHexcodeToCodepoint(hexCode)); diff --git a/lib/util/emoji.ts b/lib/util/emoji.ts index 219392ab98b77d..cf6790ca6453fb 100644 --- a/lib/util/emoji.ts +++ b/lib/util/emoji.ts @@ -24,9 +24,15 @@ const EmojiShortcodesSchema = Json.pipe( z.record(z.string(), z.union([z.string(), z.array(z.string())])), ); +const patchedEmojis: z.infer = { + '26A0-FE0F': 'warning', // Colorful warning (โš ๏ธ) instead of black and white (โš ) +}; + function lazyInitMappings(): void { if (!mappingsInitialized) { - const result = EmojiShortcodesSchema.safeParse( + const result = EmojiShortcodesSchema.transform((data) => + Object.assign(data, patchedEmojis), + ).safeParse( dataFiles.get('node_modules/emojibase-data/en/shortcodes/github.json')!, ); // istanbul ignore if: not easily testable @@ -37,6 +43,7 @@ function lazyInitMappings(): void { for (const [hex, val] of Object.entries(result.data)) { const shortCodes = is.array(val) ? val : [val]; shortCodesByHex.set(hex, `:${shortCodes[0]}:`); + shortCodesByHex.set(stripHexCode(hex), `:${shortCodes[0]}:`); shortCodes.forEach((shortCode) => { hexCodesByShort.set(`:${shortCode}:`, hex); }); From f9ad4d0dff01124a7404733b92813eac5fd98c49 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 21:07:10 -0300 Subject: [PATCH 2/7] Update test name --- lib/util/emoji.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/emoji.spec.ts b/lib/util/emoji.spec.ts index c9d8e099a87223..9dc475a838ae05 100644 --- a/lib/util/emoji.spec.ts +++ b/lib/util/emoji.spec.ts @@ -68,7 +68,7 @@ describe('util/emoji', () => { }); }); - describe('problem characters', () => { + describe('problematic characters', () => { it.each(['๐Ÿš€', '๐Ÿ’Ž', '๐Ÿงน', '๐Ÿ“ฆ', 'โš ๏ธ'])( 'converts %s forth and back', (char) => { From a82eab107c7c849d9a3e38bc81dad63578c2a8a9 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 21:15:44 -0300 Subject: [PATCH 3/7] Fix snapshots --- lib/workers/repository/errors-warnings.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/workers/repository/errors-warnings.spec.ts b/lib/workers/repository/errors-warnings.spec.ts index e93d5564400098..4fee6525739f7e 100644 --- a/lib/workers/repository/errors-warnings.spec.ts +++ b/lib/workers/repository/errors-warnings.spec.ts @@ -85,7 +85,7 @@ describe('workers/repository/errors-warnings', () => { " --- - > โš  **Warning** + > โš ๏ธ **Warning** > > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. @@ -133,7 +133,7 @@ describe('workers/repository/errors-warnings', () => { " --- - > โš  **Warning** + > โš ๏ธ **Warning** > > Some dependencies could not be looked up. Check the warning logs for more information. @@ -197,7 +197,7 @@ describe('workers/repository/errors-warnings', () => { " --- - > โš  **Warning** + > โš ๏ธ **Warning** > > Renovate failed to look up the following dependencies: \`dependency-1\`, \`dependency-2\`. > @@ -305,7 +305,7 @@ describe('workers/repository/errors-warnings', () => { " --- > - > โš  **Warning** + > โš ๏ธ **Warning** > > Please correct - or verify that you can safely ignore - these dependency lookup failures before you merge this PR. > From 02946ffee065e950620e2acf9b2e60d7fab07a46 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 21:21:13 -0300 Subject: [PATCH 4/7] Fix massage --- lib/modules/platform/github/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 9357a3adc93844..03d0560048811f 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1949,7 +1949,7 @@ export function massageMarkdown(input: string): string { .replace(regEx(/]\(https:\/\/github\.com\//g), '](https://togithub.com/') .replace(regEx(/]: https:\/\/github\.com\//g), ']: https://togithub.com/') .replace('> โ„น **Note**\n> \n', '> [!NOTE]\n') - .replace('> โš  **Warning**\n> \n', '> [!WARNING]\n') + .replace('> โš ๏ธ **Warning**\n> \n', '> [!WARNING]\n') .replace('> โ— **Important**\n> \n', '> [!IMPORTANT]\n'); return smartTruncate(massagedInput, GitHubMaxPrBodyLen); } From 12369741f7aefcde45842e93edf203669b81f0f4 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 6 May 2024 21:23:01 -0300 Subject: [PATCH 5/7] Preserve both --- lib/modules/platform/github/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 03d0560048811f..a0873b7d0c09b6 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1949,6 +1949,7 @@ export function massageMarkdown(input: string): string { .replace(regEx(/]\(https:\/\/github\.com\//g), '](https://togithub.com/') .replace(regEx(/]: https:\/\/github\.com\//g), ']: https://togithub.com/') .replace('> โ„น **Note**\n> \n', '> [!NOTE]\n') + .replace('> โš  **Warning**\n> \n', '> [!WARNING]\n') .replace('> โš ๏ธ **Warning**\n> \n', '> [!WARNING]\n') .replace('> โ— **Important**\n> \n', '> [!IMPORTANT]\n'); return smartTruncate(massagedInput, GitHubMaxPrBodyLen); From f4882f454f9d7b1d149d3b564b0822708719eabb Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 7 May 2024 09:10:29 -0300 Subject: [PATCH 6/7] More refactoring --- lib/util/emoji.ts | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/util/emoji.ts b/lib/util/emoji.ts index cf6790ca6453fb..e258e7ef594a43 100644 --- a/lib/util/emoji.ts +++ b/lib/util/emoji.ts @@ -1,4 +1,3 @@ -import is from '@sindresorhus/is'; import mathiasBynensEmojiRegex from 'emoji-regex'; import { fromCodepointToUnicode, @@ -12,6 +11,7 @@ import type { RenovateConfig } from '../config/types'; import dataFiles from '../data-files.generated'; import { logger } from '../logger'; import { regEx } from './regex'; +import { Result } from './result'; import { Json } from './schema-utils'; let unicodeEmoji = true; @@ -21,34 +21,45 @@ const shortCodesByHex = new Map(); const hexCodesByShort = new Map(); const EmojiShortcodesSchema = Json.pipe( - z.record(z.string(), z.union([z.string(), z.array(z.string())])), + z.record( + z.string(), + z.union([z.string().transform((val) => [val]), z.array(z.string())]), + ), ); +type EmojiShortcodeMapping = z.infer; -const patchedEmojis: z.infer = { - '26A0-FE0F': 'warning', // Colorful warning (โš ๏ธ) instead of black and white (โš ) +const patchedEmojis: EmojiShortcodeMapping = { + '26A0-FE0F': ['warning'], // Colorful warning (โš ๏ธ) instead of black and white (โš ) }; +function initMapping(mapping: EmojiShortcodeMapping): void { + for (const [hex, shortcodes] of Object.entries(mapping)) { + const mainShortcode = `:${shortcodes[0]}:`; + + shortCodesByHex.set(hex, mainShortcode); + shortCodesByHex.set(stripHexCode(hex), mainShortcode); + + for (const shortcode of shortcodes) { + hexCodesByShort.set(`:${shortcode}:`, hex); + } + } +} + function lazyInitMappings(): void { if (!mappingsInitialized) { - const result = EmojiShortcodesSchema.transform((data) => - Object.assign(data, patchedEmojis), - ).safeParse( - dataFiles.get('node_modules/emojibase-data/en/shortcodes/github.json')!, + const githubShortcodes = dataFiles.get( + 'node_modules/emojibase-data/en/shortcodes/github.json', ); - // istanbul ignore if: not easily testable - if (!result.success) { - logger.warn({ error: result.error }, 'Unable to parse emoji shortcodes'); - return; - } - for (const [hex, val] of Object.entries(result.data)) { - const shortCodes = is.array(val) ? val : [val]; - shortCodesByHex.set(hex, `:${shortCodes[0]}:`); - shortCodesByHex.set(stripHexCode(hex), `:${shortCodes[0]}:`); - shortCodes.forEach((shortCode) => { - hexCodesByShort.set(`:${shortCode}:`, hex); + + Result.parse(githubShortcodes, EmojiShortcodesSchema) + .onValue((data) => { + initMapping(data); + initMapping(patchedEmojis); + mappingsInitialized = true; + }) + .onError((error) => /* istanbul ignore */ { + logger.warn({ error }, 'Unable to parse emoji shortcodes'); }); - } - mappingsInitialized = true; } } From 3c2ee340f0fa42dc95377961a43e07108a7bee96 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 7 May 2024 09:20:20 -0300 Subject: [PATCH 7/7] Fix coverage --- lib/util/emoji.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/util/emoji.ts b/lib/util/emoji.ts index e258e7ef594a43..a5e03a86409cac 100644 --- a/lib/util/emoji.ts +++ b/lib/util/emoji.ts @@ -57,9 +57,12 @@ function lazyInitMappings(): void { initMapping(patchedEmojis); mappingsInitialized = true; }) - .onError((error) => /* istanbul ignore */ { - logger.warn({ error }, 'Unable to parse emoji shortcodes'); - }); + .onError( + /* istanbul ignore next */ + (error) => { + logger.warn({ error }, 'Unable to parse emoji shortcodes'); + }, + ); } }