From 9bfa8e120bb88ba88e921907348fccefe762d7cd Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 5 Oct 2018 07:37:15 +0200
Subject: [PATCH] =?UTF-8?q?fix(pr):=20don=E2=80=99t=20truncate=20configura?=
 =?UTF-8?q?tion=20and=20footer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/platform/github/index.js | 43 +++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js
index 6ce7ef3633..8264c019d0 100644
--- a/lib/platform/github/index.js
+++ b/lib/platform/github/index.js
@@ -1314,20 +1314,41 @@ async function mergePr(prNo, branchName) {
   return true;
 }
 
+// istanbul ignore next
+function smartTruncate(input) {
+  if (input.length < 60000) {
+    return input;
+  }
+  const releaseNotesMatch = input.match(
+    /### Release Notes.*### Renovate configuration/ms
+  );
+  // istanbul ignore if
+  if (releaseNotesMatch) {
+    const divider = '</details>\n\n---\n\n### Renovate configuration';
+    const [releaseNotes] = releaseNotesMatch;
+    const nonReleaseNotesLength =
+      input.length - releaseNotes.length - divider.length;
+    const availableLength = 60000 - nonReleaseNotesLength;
+    return input.replace(
+      releaseNotes,
+      releaseNotes.slice(0, availableLength) + divider
+    );
+  }
+  return input.substring(0, 60000);
+}
+
 function getPrBody(input) {
   if (config.isGhe) {
-    return input.substring(0, 60000);
+    return smartTruncate(input);
   }
-  return (
-    input
-      // to be safe, replace all github.com links with renovatebot redirector
-      .replace(
-        /href="https?:\/\/github.com\//g,
-        'href="https://renovatebot.com/gh/'
-      )
-      .replace(/]\(https:\/\/github\.com\//g, '](https://renovatebot.com/gh/')
-      .substring(0, 60000)
-  );
+  const massagedInput = input
+    // to be safe, replace all github.com links with renovatebot redirector
+    .replace(
+      /href="https?:\/\/github.com\//g,
+      'href="https://renovatebot.com/gh/'
+    )
+    .replace(/]\(https:\/\/github\.com\//g, '](https://renovatebot.com/gh/');
+  return smartTruncate(massagedInput);
 }
 
 async function getVulnerabilityAlerts() {
-- 
GitLab