From 34d64832576daf48a04fe34a6f460f15a681c06c Mon Sep 17 00:00:00 2001
From: Luca Becker <luca.becker@me.com>
Date: Wed, 14 Apr 2021 11:03:08 +0200
Subject: [PATCH] feat(release-notes): running unemojify on release notes
 (#9535)

---
 lib/util/emoji.spec.ts            | 22 ++++++++++++++++++++++
 lib/util/emoji.ts                 |  4 ++++
 lib/workers/pr/body/changelogs.ts |  3 +++
 3 files changed, 29 insertions(+)
 create mode 100644 lib/util/emoji.spec.ts

diff --git a/lib/util/emoji.spec.ts b/lib/util/emoji.spec.ts
new file mode 100644
index 0000000000..b071145956
--- /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 98bb118575..fbcad748d6 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 0dfce4ab8b..a0e62d6910 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;
 }
-- 
GitLab