From dbe9fd9dec1191be20d315f0a42f96d771c5e9a6 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 13 Mar 2018 07:44:50 +0100
Subject: [PATCH] fix: compile handlebars multiple times to catch nested
 templates

Closes #1652
---
 lib/workers/repository/updates/branchify.js | 3 +++
 lib/workers/repository/updates/generate.js  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/lib/workers/repository/updates/branchify.js b/lib/workers/repository/updates/branchify.js
index 8806e1d5c3..36acdbbe69 100644
--- a/lib/workers/repository/updates/branchify.js
+++ b/lib/workers/repository/updates/branchify.js
@@ -36,6 +36,9 @@ function branchifyUpgrades(config) {
         logger.debug('Using regular branchName template');
         upgrade.branchName = handlebars.compile(upgrade.branchName)(upgrade);
       }
+      // Compile extra times in case of nested handlebars templates
+      upgrade.branchName = handlebars.compile(upgrade.branchName)(upgrade);
+      upgrade.branchName = handlebars.compile(upgrade.branchName)(upgrade);
       branchUpgrades[upgrade.branchName] =
         branchUpgrades[upgrade.branchName] || [];
       branchUpgrades[upgrade.branchName] = [upgrade].concat(
diff --git a/lib/workers/repository/updates/generate.js b/lib/workers/repository/updates/generate.js
index 80e01a6c0e..d07b1bc354 100644
--- a/lib/workers/repository/updates/generate.js
+++ b/lib/workers/repository/updates/generate.js
@@ -49,6 +49,9 @@ function generateBranchConfig(branchUpgrades) {
       upgrade.baseBranches && upgrade.baseBranches.length > 1
         ? ' ({{baseBranch}})'
         : '';
+    // Compile a few times to allow for nested handlebars templates
+    upgrade.prTitle = handlebars.compile(upgrade.prTitle)(upgrade);
+    upgrade.prTitle = handlebars.compile(upgrade.prTitle)(upgrade);
     upgrade.prTitle = handlebars.compile(upgrade.prTitle)(upgrade);
     if (upgrade.semanticCommits) {
       logger.debug('Upgrade has semantic commits enabled');
-- 
GitLab