From 6ec865be62fa9597e9027eec69a6cddd5def70e5 Mon Sep 17 00:00:00 2001
From: Adam Setch <adam.setch@outlook.com>
Date: Tue, 25 Apr 2023 11:08:13 -0400
Subject: [PATCH] feat: add prTitleStrict config option to bypass prTitle
 manipulation (#21454)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
---
 docs/usage/configuration-options.md           |  8 +++
 lib/config/options/index.ts                   |  9 +++
 .../repository/updates/generate.spec.ts       | 55 +++++++++++++++++++
 lib/workers/repository/updates/generate.ts    | 30 +++++-----
 lib/workers/types.ts                          |  1 +
 5 files changed, 89 insertions(+), 14 deletions(-)

diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md
index 05b089229a..b573644343 100644
--- a/docs/usage/configuration-options.md
+++ b/docs/usage/configuration-options.md
@@ -2736,6 +2736,14 @@ Here's an example of how you would define PR priority so that devDependencies ar
 
 The PR title is important for some of Renovate's matching algorithms (e.g. determining whether to recreate a PR or not) so ideally don't modify it much.
 
+## prTitleStrict
+
+There are certain scenarios where the default behavior appends extra context to the PR title.
+
+These scenarios include if a `baseBranch` or if there is a grouped update and either `separateMajorMinor` or `separateMinorPatch` is true.
+
+Using this option allows you to skip these default behaviors and use other templating methods to control the format of the PR title.
+
 ## printConfig
 
 This option is useful for troubleshooting, particularly if using presets.
diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts
index 698a170568..76a7881dd4 100644
--- a/lib/config/options/index.ts
+++ b/lib/config/options/index.ts
@@ -1855,6 +1855,15 @@ const options: RenovateOptions[] = [
     default: null,
     cli: false,
   },
+  {
+    name: 'prTitleStrict',
+    description:
+      'Whether to bypass appending extra context to the Pull Request title.',
+    type: 'boolean',
+    experimental: true,
+    default: false,
+    cli: false,
+  },
   {
     name: 'prHeader',
     description: 'Text added here will be placed first in the PR body.',
diff --git a/lib/workers/repository/updates/generate.spec.ts b/lib/workers/repository/updates/generate.spec.ts
index 040726a903..c44d2e74ee 100644
--- a/lib/workers/repository/updates/generate.spec.ts
+++ b/lib/workers/repository/updates/generate.spec.ts
@@ -357,6 +357,61 @@ describe('workers/repository/updates/generate', () => {
       expect(res.recreateClosed).toBeTrue();
     });
 
+    it('skips appending baseBranch and updateType to prTitle when prTitleStrict is true', () => {
+      const branch = [
+        {
+          manager: 'some-manager',
+          depName: 'depB',
+          groupName: 'some-group',
+          branchName: 'some-branch',
+          commitMessage:
+            '{{{groupName}}} {{{commitMessageExtra}}} {{{commitMessageSuffix}}}',
+          commitMessageExtra:
+            'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{prettyNewVersion}}{{/if}}',
+          foo: 1,
+          newValue: '5.1.2',
+          newVersion: '5.1.2',
+          group: {
+            foo: 2,
+          },
+          releaseTimestamp: '2017-02-07T20:01:41+00:00',
+          updateType: 'minor',
+          separateMinorPatch: true,
+          prTitleStrict: true,
+        },
+        {
+          manager: 'some-manager',
+          depName: 'depA',
+          groupName: 'some-group',
+          branchName: 'some-branch',
+          commitMessage:
+            '{{{groupName}}} {{{commitMessageExtra}}} {{{commitMessageSuffix}}}',
+          commitMessageExtra:
+            'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{prettyNewVersion}}{{/if}}',
+          foo: 1,
+          newValue: '1.1.0',
+          newVersion: '1.1.0',
+          group: {
+            foo: 2,
+          },
+          releaseTimestamp: '2017-02-08T20:01:41+00:00',
+          updateType: 'minor',
+          separateMinorPatch: true,
+          prTitleStrict: true,
+        },
+      ] satisfies BranchUpgradeConfig[];
+      const res = generateBranchConfig(branch);
+      expect(res).toMatchObject({
+        foo: 2,
+        isGroup: true,
+        recreateClosed: true,
+        prTitle: 'some-group',
+        commitMessage: 'some-group',
+        groupName: 'some-group',
+        releaseTimestamp: '2017-02-08T20:01:41+00:00',
+      });
+    });
+
     it('groups multiple upgrades different version', () => {
       const branch = [
         {
diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts
index 5a3ff3e05b..3dd6b92261 100644
--- a/lib/workers/repository/updates/generate.ts
+++ b/lib/workers/repository/updates/generate.ts
@@ -255,20 +255,22 @@ export function generateBranchConfig(
     } else {
       [upgrade.prTitle] = upgrade.commitMessage.split(newlineRegex);
     }
-    upgrade.prTitle += upgrade.hasBaseBranches ? ' ({{baseBranch}})' : '';
-    if (upgrade.isGroup) {
-      upgrade.prTitle +=
-        upgrade.updateType === 'major' && upgrade.separateMajorMinor
-          ? ' (major)'
-          : '';
-      upgrade.prTitle +=
-        upgrade.updateType === 'minor' && upgrade.separateMinorPatch
-          ? ' (minor)'
-          : '';
-      upgrade.prTitle +=
-        upgrade.updateType === 'patch' && upgrade.separateMinorPatch
-          ? ' (patch)'
-          : '';
+    if (!upgrade.prTitleStrict) {
+      upgrade.prTitle += upgrade.hasBaseBranches ? ' ({{baseBranch}})' : '';
+      if (upgrade.isGroup) {
+        upgrade.prTitle +=
+          upgrade.updateType === 'major' && upgrade.separateMajorMinor
+            ? ' (major)'
+            : '';
+        upgrade.prTitle +=
+          upgrade.updateType === 'minor' && upgrade.separateMinorPatch
+            ? ' (minor)'
+            : '';
+        upgrade.prTitle +=
+          upgrade.updateType === 'patch' && upgrade.separateMinorPatch
+            ? ' (patch)'
+            : '';
+      }
     }
     // Compile again to allow for nested templates
     upgrade.prTitle = template.compile(upgrade.prTitle, upgrade);
diff --git a/lib/workers/types.ts b/lib/workers/types.ts
index 7b53bcddb2..8357d49264 100644
--- a/lib/workers/types.ts
+++ b/lib/workers/types.ts
@@ -56,6 +56,7 @@ export interface BranchUpgradeConfig
   prBodyTemplate?: string;
   prPriority?: number;
   prTitle?: string;
+  prTitleStrict?: boolean;
   prettyNewMajor?: string;
   prettyNewVersion?: string;
   releases?: ReleaseWithNotes[];
-- 
GitLab