From a01b0b80ba2d041b3fc0cb065c381e0458537c46 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 27 Jul 2018 19:49:56 +0200
Subject: [PATCH] fix(gitlab): html formatting to fix details/summary

Fixes #2317
---
 lib/platform/gitlab/index.js                      | 15 ++++++++++++++-
 .../gitlab/__snapshots__/index.spec.js.snap       |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js
index d2db116c3b..6b94a9b825 100644
--- a/lib/platform/gitlab/index.js
+++ b/lib/platform/gitlab/index.js
@@ -1,8 +1,13 @@
 const is = require('@sindresorhus/is');
 const addrs = require('email-addresses');
+const showdown = require('showdown');
+
 const get = require('./gl-got-wrapper');
 const endpoints = require('../../util/endpoints');
 
+const converter = new showdown.Converter();
+converter.setFlavor('github');
+
 let config = {};
 
 module.exports = {
@@ -700,7 +705,15 @@ async function mergePr(iid) {
 
 function getPrBody(input) {
   // Convert to HTML using GitHub-flavoured markdown as it is more feature-rich than GitLab's flavour
-  return input.replace(/Pull Request/g, 'Merge Request').replace(/PR/g, 'MR');
+  return converter
+    .makeHtml(input)
+    .replace(/Pull Request/g, 'Merge Request')
+    .replace(/PR/g, 'MR')
+    .replace(
+      `<p><details><br />\n<summary>Release Notes</summary></p>`,
+      '\n<details>\n\n<summary>Release Notes</summary>\n\n'
+    )
+    .replace('<p></details></p>', '\n</details>\n');
   // TODO: set maximum length
 }
 
diff --git a/test/platform/gitlab/__snapshots__/index.spec.js.snap b/test/platform/gitlab/__snapshots__/index.spec.js.snap
index e448249ddd..972298c3ac 100644
--- a/test/platform/gitlab/__snapshots__/index.spec.js.snap
+++ b/test/platform/gitlab/__snapshots__/index.spec.js.snap
@@ -243,7 +243,7 @@ Object {
 }
 `;
 
-exports[`platform/gitlab getPrBody(input) returns updated pr body 1`] = `"https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)"`;
+exports[`platform/gitlab getPrBody(input) returns updated pr body 1`] = `"<p><a href=\\"https://github.com/foo/bar/issues/5\\">https://github.com/foo/bar/issues/5</a> plus also <a href=\\"https://github.com/foo/bar/issues/5\\">a link</a></p>"`;
 
 exports[`platform/gitlab getPrFiles() returns files 1`] = `
 Array [
-- 
GitLab