From 8fc50ca86f3de5b29a99d1ac0263d3030a46e085 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 14 Mar 2024 06:53:06 +0100
Subject: [PATCH] fix(templates): compile groupSlug (#27927)

---
 lib/workers/repository/updates/branch-name.spec.ts | 5 +++--
 lib/workers/repository/updates/branch-name.ts      | 7 ++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/workers/repository/updates/branch-name.spec.ts b/lib/workers/repository/updates/branch-name.spec.ts
index c78652419c..62da7332c9 100644
--- a/lib/workers/repository/updates/branch-name.spec.ts
+++ b/lib/workers/repository/updates/branch-name.spec.ts
@@ -31,14 +31,15 @@ describe('workers/repository/updates/branch-name', () => {
     it('uses groupSlug if defined', () => {
       const upgrade: RenovateConfig = {
         groupName: 'some group name',
-        groupSlug: 'some group slug',
+        groupSlug: 'some group {{parentDir}}',
+        parentDir: 'abc',
         group: {
           branchName: '{{groupSlug}}-{{branchTopic}}',
           branchTopic: 'grouptopic',
         },
       };
       generateBranchName(upgrade);
-      expect(upgrade.branchName).toBe('some-group-slug-grouptopic');
+      expect(upgrade.branchName).toBe('some-group-abc-grouptopic');
     });
 
     it('separates major with groups', () => {
diff --git a/lib/workers/repository/updates/branch-name.ts b/lib/workers/repository/updates/branch-name.ts
index 9036a161c0..7200b12ecf 100644
--- a/lib/workers/repository/updates/branch-name.ts
+++ b/lib/workers/repository/updates/branch-name.ts
@@ -54,7 +54,12 @@ export function generateBranchName(update: RenovateConfig): void {
     logger.trace(
       `Dependency ${update.depName!} is part of group ${update.groupName}`,
     );
-    update.groupSlug = slugify(update.groupSlug ?? update.groupName, {
+    if (update.groupSlug) {
+      update.groupSlug = template.compile(update.groupSlug, update);
+    } else {
+      update.groupSlug = update.groupName;
+    }
+    update.groupSlug = slugify(update.groupSlug, {
       lower: true,
     });
     if (update.updateType === 'major' && update.separateMajorMinor) {
-- 
GitLab