From 2146bafdbd727d673a05a8ab124e348d1f7e72bb Mon Sep 17 00:00:00 2001
From: rtaum <rtaum@users.noreply.github.com>
Date: Sat, 8 Dec 2018 12:42:56 +0100
Subject: [PATCH] feat: suppressNotifications (#2906)

Adds ability so suppress certain notifications/warnings/comments.

Closes #2794
---
 lib/config/definitions.js                     | 15 ++++++
 lib/workers/branch/index.js                   | 49 +++++++++++--------
 lib/workers/pr/index.js                       |  2 +-
 .../__snapshots__/flatten.spec.js.snap        |  8 +++
 website/docs/configuration-options.md         | 10 ++++
 5 files changed, 63 insertions(+), 21 deletions(-)

diff --git a/lib/config/definitions.js b/lib/config/definitions.js
index ef109b2932..c659489a99 100644
--- a/lib/config/definitions.js
+++ b/lib/config/definitions.js
@@ -1348,6 +1348,21 @@ const options = [
     allowString: true,
     mergeable: true,
   },
+  {
+    name: 'suppressNotifications',
+    description:
+      'Options to suppress various types of warnings and other notifications',
+    type: 'list',
+    default: [],
+    allowedValues: [
+      'prIgnoreNotification',
+      'prEditNotification',
+      'branchAutomergeFailure',
+      'lockFileErrors',
+    ],
+    cli: false,
+    env: false,
+  }
 ];
 
 function getOptions() {
diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js
index 032a169e89..265b773306 100644
--- a/lib/workers/branch/index.js
+++ b/lib/workers/branch/index.js
@@ -72,14 +72,16 @@ async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) {
         }
         content +=
           '\n\nIf this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.';
-        // istanbul ignore if
-        if (config.dryRun) {
-          logger.info(
-            'DRY-RUN: Would ensure closed PR comment in PR #' +
-              existingPr.number
-          );
-        } else {
-          await platform.ensureComment(existingPr.number, subject, content);
+        if (!config.suppressNotifications.includes('prIgnoreNotification')) {
+          // istanbul ignore if
+          if (config.dryRun) {
+            logger.info(
+              'DRY-RUN: Would ensure closed PR comment in PR #' +
+                existingPr.number
+            );
+          } else {
+            await platform.ensureComment(existingPr.number, subject, content);
+          }
         }
         if (branchExists) {
           // istanbul ignore if
@@ -142,11 +144,15 @@ async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) {
             content += ` If you wish to abandon your changes and have Renovate start over then you can add the label \`${
               config.rebaseLabel
             }\` to this PR and Renovate will reset/recreate it.`;
-            // istanbul ignore if
-            if (config.dryRun) {
-              logger.info('DRY-RUN: ensure comment in PR #' + branchPr.number);
-            } else {
-              await platform.ensureComment(branchPr.number, subject, content);
+            if (!config.suppressNotifications.includes('prEditNotification')) {
+              // istanbul ignore if
+              if (config.dryRun) {
+                logger.info(
+                  'DRY-RUN: ensure comment in PR #' + branchPr.number
+                );
+              } else {
+                await platform.ensureComment(branchPr.number, subject, content);
+              }
             }
             return 'pr-edited';
           }
@@ -358,13 +364,16 @@ async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) {
           content += `##### ${error.lockFile}\n\n`;
           content += `\`\`\`\n${error.stderr}\n\`\`\`\n\n`;
         });
-        // istanbul ignore if
-        if (config.dryRun) {
-          logger.info(
-            'DRY-RUN: Would ensure lock file error comment in PR #' + pr.number
-          );
-        } else {
-          await platform.ensureComment(pr.number, topic, content);
+        if (!config.suppressNotifications.includes('lockFileErrors')) {
+          // istanbul ignore if
+          if (config.dryRun) {
+            logger.info(
+              'DRY-RUN: Would ensure lock file error comment in PR #' +
+                pr.number
+            );
+          } else {
+            await platform.ensureComment(pr.number, topic, content);
+          }
         }
         const context = 'renovate/lock-files';
         const description = 'Lock file update failure';
diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js
index 7f7e3fd0d5..c7951dffd8 100644
--- a/lib/workers/pr/index.js
+++ b/lib/workers/pr/index.js
@@ -279,7 +279,7 @@ async function ensurePr(prConfig) {
       }
       return null;
     }
-    if (config.branchAutomergeFailureMessage) {
+    if (config.branchAutomergeFailureMessage && !config.suppressNotifications.includes('branchAutomergeFailure')) {
       const subject = 'Branch automerge failure';
       let content =
         'This PR was configured for branch automerge, however this is not possible so it has been raised as a PR instead.';
diff --git a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
index 67d800a83b..e7a6f598f1 100644
--- a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
+++ b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
@@ -81,6 +81,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -174,6 +175,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -266,6 +268,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -360,6 +363,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -452,6 +456,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -546,6 +551,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -639,6 +645,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
@@ -732,6 +739,7 @@ Array [
     "separateMinorPatch": false,
     "skipInstalls": null,
     "statusCheckVerify": false,
+    "suppressNotifications": Array [],
     "timezone": null,
     "unpublishSafe": false,
     "updateLockFiles": true,
diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md
index 2801d14c27..7ce1a7a39c 100644
--- a/website/docs/configuration-options.md
+++ b/website/docs/configuration-options.md
@@ -839,6 +839,16 @@ Language support is limited to those listed below:
 
 - **Node.js** - [Read our Node.js documentation](https://renovatebot.com/docs/node#configuring-support-policy)
 
+## suppressNotifications
+
+Use this field to suppress various types of warnings and other notifications from Renovate. Example:
+
+```json
+"suppressNotifications": ["prIgnoreNotification"]
+```
+
+The above config will suppress the comment which is added to a PR whenever you close a PR unmerged.
+
 ## terraform
 
 Currently Terraform support is limited to Terraform registry sources and github sources that include semver refs, e.g. like `github.com/hashicorp/example?ref=v1.0.0`.
-- 
GitLab