diff --git a/lib/util/emoji.spec.ts b/lib/util/emoji.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..b07114595662db327a716a96e955a6fd046ec741 --- /dev/null +++ b/lib/util/emoji.spec.ts @@ -0,0 +1,22 @@ +import { getName } from '../../test/util'; +import { setEmojiConfig, unemojify } from './emoji'; + +describe(getName(__filename), () => { + it('strips emojis when the config has been set accordingly', () => { + const emoji = '🚀💎'; + const otherText = 'regular text'; + const text = `${emoji} ${otherText}`; + setEmojiConfig({ unicodeEmoji: false }); + const result = unemojify(text); + expect(result).not.toContain(emoji); + }); + + it('does not strip emojis when the config demands it', () => { + const emoji = '🚀💎'; + const otherText = 'regular text'; + const text = `${emoji} ${otherText}`; + setEmojiConfig({ unicodeEmoji: true }); + const result = unemojify(text); + expect(result).toEqual(text); + }); +}); diff --git a/lib/util/emoji.ts b/lib/util/emoji.ts index 98bb11857557282d7dac59a6bee48c9d2a6d81c2..fbcad748d64f37923da4e1b4464c634044276a81 100644 --- a/lib/util/emoji.ts +++ b/lib/util/emoji.ts @@ -10,3 +10,7 @@ export function setEmojiConfig(_config: RenovateConfig): void { export function emojify(text: string): string { return unicodeEmoji ? emoji.emojify(text) : text; } + +export function unemojify(text: string): string { + return unicodeEmoji ? text : emoji.unemojify(text); +} diff --git a/lib/workers/pr/body/changelogs.ts b/lib/workers/pr/body/changelogs.ts index 0dfce4ab8bd3fadba50fe5b3d75dee3f80c59a7b..a0e62d6910b346b315c9c58711629adee7fcbb28 100644 --- a/lib/workers/pr/body/changelogs.ts +++ b/lib/workers/pr/body/changelogs.ts @@ -1,3 +1,4 @@ +import { unemojify } from '../../../util/emoji'; import { sanitizeMarkdown } from '../../../util/markdown'; import * as template from '../../../util/template'; import type { BranchConfig } from '../../types'; @@ -13,5 +14,7 @@ export function getChangelogs(config: BranchConfig): string { '\n\n---\n\n' + template.compile(releaseNotesHbs, config, false) + '\n\n'; releaseNotes = releaseNotes.replace(/### \[`vv/g, '### [`v'); releaseNotes = sanitizeMarkdown(releaseNotes); + releaseNotes = unemojify(releaseNotes); + return releaseNotes; }