From c53cd4e67414c9e1a991370d088330055e4d91c4 Mon Sep 17 00:00:00 2001
From: mohd hassaan <sr.hassan23@gmail.com>
Date: Sun, 28 Apr 2019 12:34:50 +0530
Subject: [PATCH] feat: Add "rebase all" functionality in master issue (#3597)

---
 lib/workers/branch/index.js             | 2 +-
 lib/workers/repository/master-issue.js  | 8 ++++++++
 lib/workers/repository/process/index.js | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js
index b1c8b98ab4..bae3b1d9a4 100644
--- a/lib/workers/branch/index.js
+++ b/lib/workers/branch/index.js
@@ -199,7 +199,7 @@ async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) {
       return 'pending';
     }
     // istanbul ignore if
-    if (masterIssueCheck === 'rebase') {
+    if (masterIssueCheck === 'rebase' || config.masterIssueRebaseAllOpen) {
       logger.info('Manual rebase requested via master issue');
       delete config.parentBranch;
     } else {
diff --git a/lib/workers/repository/master-issue.js b/lib/workers/repository/master-issue.js
index e887b8a846..39b04c70ef 100644
--- a/lib/workers/repository/master-issue.js
+++ b/lib/workers/repository/master-issue.js
@@ -121,6 +121,13 @@ async function ensureMasterIssue(config, branches) {
       const pr = await platform.getBranchPr(branch.branchName);
       issueBody += getListItem(branch, 'rebase', pr);
     }
+    if (inProgress.length > 2) {
+      issueBody += ' - [ ] ';
+      issueBody += '<!-- rebase-all-open-prs -->';
+      issueBody +=
+        '**Check this option to rebase all the above open PRs at once**';
+      issueBody += '\n';
+    }
     issueBody += '\n';
   }
   const alreadyExisted = branches.filter(
@@ -140,5 +147,6 @@ async function ensureMasterIssue(config, branches) {
     }
     issueBody += '\n';
   }
+
   await platform.ensureIssue(config.masterIssueTitle, issueBody);
 }
diff --git a/lib/workers/repository/process/index.js b/lib/workers/repository/process/index.js
index 06caf933ca..5e8f38a8a9 100644
--- a/lib/workers/repository/process/index.js
+++ b/lib/workers/repository/process/index.js
@@ -23,6 +23,11 @@ async function processRepo(config) {
           const [, type, branchName] = check.match(new RegExp(checkMatch));
           config.masterIssueChecks[branchName] = type;
         });
+      }
+      const checkAllMatch = ' - \\[x\\] <!-- rebase-all-open-prs -->';
+      const checkedRebaseAll = issue.body.match(new RegExp(checkAllMatch));
+      if (checkedRebaseAll) {
+        config.masterIssueRebaseAllOpen = true;
         /* eslint-enable no-param-reassign */
       }
     }
-- 
GitLab