From e62aa89a6c56c100da25ff221430dd2b2d8f69e6 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 12 Mar 2018 13:35:15 +0100
Subject: [PATCH] feat: customisable prFooter (#1648)

---
 lib/config/definitions.js                     |  8 ++++
 lib/config/templates/default/pr-body.hbs      |  4 --
 .../templates/docker-digest/pr-body.hbs       |  4 --
 lib/config/templates/docker-group/pr-body.hbs |  4 --
 .../templates/docker-pin-group/pr-body.hbs    |  4 --
 lib/config/templates/docker-pin/pr-body.hbs   |  4 --
 lib/config/templates/docker/pr-body.hbs       |  4 --
 lib/config/templates/group/pr-body.hbs        |  4 --
 .../lock-file-maintenance/pr-body.hbs         |  4 --
 lib/config/templates/node/pr-body.hbs         |  4 --
 lib/workers/global/index.js                   |  2 +-
 lib/workers/pr/index.js                       | 10 ++++-
 lib/workers/repository/onboarding/pr/index.js |  9 +++-
 test/config/__snapshots__/index.spec.js.snap  |  6 +--
 .../__snapshots__/resolve.spec.js.snap        | 30 +++----------
 .../pr/__snapshots__/index.spec.js.snap       | 43 +++----------------
 test/workers/pr/index.spec.js                 |  6 +--
 17 files changed, 39 insertions(+), 111 deletions(-)

diff --git a/lib/config/definitions.js b/lib/config/definitions.js
index 4f04dd8966..b66fb0b600 100644
--- a/lib/config/definitions.js
+++ b/lib/config/definitions.js
@@ -671,6 +671,14 @@ const options = [
     default: template('prBody'),
     cli: false,
   },
+  {
+    name: 'prFooter',
+    description: 'Pull Request footer template',
+    type: 'string',
+    default:
+      'This PR has been generated by [Renovate Bot](https://renovateapp.com).',
+    stage: 'global',
+  },
   // Yarn Lock Maintenance
   {
     name: 'lockFileMaintenance',
diff --git a/lib/config/templates/default/pr-body.hbs b/lib/config/templates/default/pr-body.hbs
index 868c52ee76..9bddc2860a 100644
--- a/lib/config/templates/default/pr-body.hbs
+++ b/lib/config/templates/default/pr-body.hbs
@@ -73,7 +73,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/docker-digest/pr-body.hbs b/lib/config/templates/docker-digest/pr-body.hbs
index 2f3680f0aa..97e06b1d98 100644
--- a/lib/config/templates/docker-digest/pr-body.hbs
+++ b/lib/config/templates/docker-digest/pr-body.hbs
@@ -29,7 +29,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/docker-group/pr-body.hbs b/lib/config/templates/docker-group/pr-body.hbs
index af214cc4cc..cd8c65e328 100644
--- a/lib/config/templates/docker-group/pr-body.hbs
+++ b/lib/config/templates/docker-group/pr-body.hbs
@@ -33,7 +33,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/docker-pin-group/pr-body.hbs b/lib/config/templates/docker-pin-group/pr-body.hbs
index e428e749b1..77f360c419 100644
--- a/lib/config/templates/docker-pin-group/pr-body.hbs
+++ b/lib/config/templates/docker-pin-group/pr-body.hbs
@@ -35,7 +35,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/docker-pin/pr-body.hbs b/lib/config/templates/docker-pin/pr-body.hbs
index 13260a6885..65b635dd11 100644
--- a/lib/config/templates/docker-pin/pr-body.hbs
+++ b/lib/config/templates/docker-pin/pr-body.hbs
@@ -32,7 +32,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/docker/pr-body.hbs b/lib/config/templates/docker/pr-body.hbs
index 9af8a0c28b..97dd5a82d3 100644
--- a/lib/config/templates/docker/pr-body.hbs
+++ b/lib/config/templates/docker/pr-body.hbs
@@ -29,7 +29,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/group/pr-body.hbs b/lib/config/templates/group/pr-body.hbs
index f84a88fc2d..7bf9ebfe3e 100644
--- a/lib/config/templates/group/pr-body.hbs
+++ b/lib/config/templates/group/pr-body.hbs
@@ -83,7 +83,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/lock-file-maintenance/pr-body.hbs b/lib/config/templates/lock-file-maintenance/pr-body.hbs
index 920bd373c7..8f46bf3029 100644
--- a/lib/config/templates/lock-file-maintenance/pr-body.hbs
+++ b/lib/config/templates/lock-file-maintenance/pr-body.hbs
@@ -29,7 +29,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/config/templates/node/pr-body.hbs b/lib/config/templates/node/pr-body.hbs
index a709d396ca..16190a8ae3 100644
--- a/lib/config/templates/node/pr-body.hbs
+++ b/lib/config/templates/node/pr-body.hbs
@@ -29,7 +29,3 @@ Please make sure the following warnings are safe to ignore:
 -   `{{warning.depName}}`: {{warning.message}}
 {{/each}}
 {{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).
diff --git a/lib/workers/global/index.js b/lib/workers/global/index.js
index 99ff09c213..4c4fcdaeae 100644
--- a/lib/workers/global/index.js
+++ b/lib/workers/global/index.js
@@ -26,7 +26,7 @@ async function start() {
       );
     }
     // Move global variables that we need to use later
-    const importGlobals = ['exposeEnv', 'prBanner'];
+    const importGlobals = ['exposeEnv', 'prBanner', 'prFooter'];
     config.global = {};
     importGlobals.forEach(key => {
       config.global[key] = config[key];
diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js
index bdfcd9cb58..33bc4afefc 100644
--- a/lib/workers/pr/index.js
+++ b/lib/workers/pr/index.js
@@ -190,9 +190,15 @@ async function ensurePr(prConfig) {
 
   let prBody = handlebars.compile(config.prBody)(config);
   // istanbul ignore if
-  if (config.global && config.global.prBanner) {
-    prBody = config.global.prBanner + '\n\n' + prBody;
+  if (config.global) {
+    if (config.global.prBanner) {
+      prBody = config.global.prBanner + '\n\n' + prBody;
+    }
+    if (config.global.prFooter) {
+      prBody = prBody + '\n---\n\n' + config.global.prFooter;
+    }
   }
+  prBody = prBody.trim();
   if (config.isGitHub && !config.privateRepo) {
     // Put a zero width space after every # followed by a digit
     prBody = prBody.replace(/#(\d)/gi, '#&#8203;$1');
diff --git a/lib/workers/repository/onboarding/pr/index.js b/lib/workers/repository/onboarding/pr/index.js
index 80b9707324..35840a29db 100644
--- a/lib/workers/repository/onboarding/pr/index.js
+++ b/lib/workers/repository/onboarding/pr/index.js
@@ -43,8 +43,13 @@ async function ensureOnboardingPr(config) {
   prBody = prBody.replace('{{BASEBRANCH}}\n', getBaseBranchDesc(config));
   prBody = prBody.replace('{{PRLIST}}\n', getPrList(config));
   // istanbul ignore if
-  if (config.global && config.global.prBanner) {
-    prBody = config.global.prBanner + '\n\n' + prBody;
+  if (config.global) {
+    if (config.global.prBanner) {
+      prBody = config.global.prBanner + '\n\n' + prBody;
+    }
+    if (config.global.prFooter) {
+      prBody = prBody + '\n---\n\n' + config.global.prFooter + '\n';
+    }
   }
   logger.trace('prBody:\n' + prBody);
 
diff --git a/test/config/__snapshots__/index.spec.js.snap b/test/config/__snapshots__/index.spec.js.snap
index 0cb3db6a0d..4985f2587c 100644
--- a/test/config/__snapshots__/index.spec.js.snap
+++ b/test/config/__snapshots__/index.spec.js.snap
@@ -36,11 +36,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
   "prTitle": "Lock file maintenance",
   "recreateClosed": true,
   "schedule": Array [
diff --git a/test/manager/__snapshots__/resolve.spec.js.snap b/test/manager/__snapshots__/resolve.spec.js.snap
index 81567610c4..e7598cdcc7 100644
--- a/test/manager/__snapshots__/resolve.spec.js.snap
+++ b/test/manager/__snapshots__/resolve.spec.js.snap
@@ -91,11 +91,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
       "prTitle": "Update Dockerfile {{{depName}}} image {{{currentTag}}} digest ({{{newDigestShort}}})",
     },
     "enabled": true,
@@ -134,11 +130,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
       "prTitle": "Update Docker {{{groupName}}} digests",
     },
     "major": Object {
@@ -185,11 +177,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
         "prTitle": "Pin Docker digests",
       },
       "groupName": "Pin Docker Digests",
@@ -226,11 +214,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
       "prTitle": "Pin Dockerfile {{{depName}}}:{{{currentTag}}} image digest",
     },
     "prBody": "This Pull Request updates Docker base image \`{{{depName}}}\` from tag \`{{{currentTag}}}\` to new tag \`{{{newTag}}}\`. For details on Renovate's Docker support, please visit https://renovateapp.com/docs/language-support/docker
@@ -263,11 +247,7 @@ Please make sure the following warnings are safe to ignore:
 {{#each warnings as |warning|}}
 -   \`{{warning.depName}}\`: {{warning.message}}
 {{/each}}
-{{/if}}
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+{{/if}}",
     "prTitle": "Update {{{depName}}} Dockerfile tag to {{#if isMajor}}v{{{newVersionMajor}}}{{else}}v{{{newTag}}}{{/if}}",
   },
   Object {
diff --git a/test/workers/pr/__snapshots__/index.spec.js.snap b/test/workers/pr/__snapshots__/index.spec.js.snap
index 844397ef0c..e48bde230c 100644
--- a/test/workers/pr/__snapshots__/index.spec.js.snap
+++ b/test/workers/pr/__snapshots__/index.spec.js.snap
@@ -36,8 +36,7 @@ Array [
 <ul>
 <li><a href=\\"https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz\\"><code>abcdefg</code></a> foo <a href=\\"https://github.com/renovateapp/dummy/issues/3\\">#3</a></li>
 </ul>
-<hr />
-<p>This MR has been generated by <a href=\\"https://renovateapp.com\\">Renovate Bot</a>.</p>",
+<p></details></p>",
   Array [],
   false,
   false,
@@ -59,13 +58,7 @@ Array [
 #### v1.1.0
 -   [\`abcdefg\`](https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz) foo [#3](https://github.com/renovateapp/dummy/issues/3)
 
-</details>
-
-
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+</details>",
   Array [],
   false,
   false,
@@ -87,13 +80,7 @@ Array [
 #### v1.1.0
 -   [\`abcdefg\`](https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz) foo #&#8203;3
 
-</details>
-
-
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+</details>",
   Array [],
   false,
   false,
@@ -113,13 +100,7 @@ Object {
 #### v1.1.0
 -   [\`abcdefg\`](https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz) foo [#3](https://github.com/renovateapp/dummy/issues/3)
 
-</details>
-
-
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+</details>",
   "displayNumber": "Existing PR",
   "title": "Update dependency dummy to v1.1.0",
 }
@@ -138,13 +119,7 @@ Object {
 #### v1.1.0
 -   [\`abcdefg\`](https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz) foo [#3](https://github.com/renovateapp/dummy/issues/3)
 
-</details>
-
-
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+</details>",
   "displayNumber": "Existing PR",
   "title": "wrong",
 }
@@ -167,13 +142,7 @@ Array [
 #### v1.1.0
 -   [\`abcdefg\`](https://github.com/renovateapp/dummy/commit/abcdefghijklmnopqrstuvwxyz) foo [#3](https://github.com/renovateapp/dummy/issues/3)
 
-
-
-
-
----
-
-This PR has been generated by [Renovate Bot](https://renovateapp.com).",
+",
   Array [],
   false,
   false,
diff --git a/test/workers/pr/index.spec.js b/test/workers/pr/index.spec.js
index 8464342e1f..7cc6320285 100644
--- a/test/workers/pr/index.spec.js
+++ b/test/workers/pr/index.spec.js
@@ -133,9 +133,9 @@ describe('workers/pr', () => {
       const pr = await prWorker.ensurePr(config);
       expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
       expect(platform.createPr.mock.calls[0]).toMatchSnapshot();
-      expect(platform.createPr.mock.calls[0][2].indexOf('<p>This MR')).not.toBe(
-        -1
-      );
+      expect(
+        platform.createPr.mock.calls[0][2].indexOf('<p>This Merge Request')
+      ).not.toBe(-1);
     });
     it('should strip HTML PR for vsts', async () => {
       platform.getBranchStatus.mockReturnValueOnce('success');
-- 
GitLab