From 7651d2e4203311e8bafad13b5caeea82ce38623c Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 1 Sep 2020 14:28:18 +0200
Subject: [PATCH] feat: additionalBranchPrefix

---
 docs/usage/configuration-options.md              | 16 +++++++++++-----
 docs/usage/configuration-templates.md            |  6 +++---
 lib/config/__snapshots__/migration.spec.ts.snap  |  1 +
 lib/config/definitions.ts                        |  6 +++---
 lib/config/migration.spec.ts                     |  1 +
 lib/config/migration.ts                          |  4 ++++
 lib/config/validation.ts                         |  2 +-
 lib/datasource/docker/index.ts                   |  2 +-
 lib/manager/buildkite/index.ts                   |  2 +-
 lib/manager/cargo/index.ts                       |  2 +-
 lib/manager/homebrew/index.ts                    |  2 +-
 lib/util/template/index.ts                       |  2 +-
 .../init/__snapshots__/config.spec.ts.snap       | 10 +++++-----
 lib/workers/repository/updates/flatten.ts        |  2 +-
 14 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md
index 908a918dac..f425d4266b 100644
--- a/docs/usage/configuration-options.md
+++ b/docs/usage/configuration-options.md
@@ -25,6 +25,16 @@ Also, be sure to check out Renovate's [shareable config presets](/config-presets
 
 If you have any questions about the below config options, or would like to get help/feedback about a config, please post it as an issue in [renovatebot/config-help](https://github.com/renovatebot/config-help) where we will do our best to answer your question.
 
+## additionalBranchPrefix
+
+This value defaults to an empty string, and is typically not necessary. Some managers populate this field for historical reasons, for example we use `docker-` for Docker branches, so they may look like `renovate/docker-ubuntu-16.x`. You normally don't need to configure this, but one example where it can be useful is combining with `parentDir` in monorepos to split PRs based on where the package definition is located, e.g.
+
+```json
+{
+  "additionalBranchPrefix": "{{parentDir}}-"
+}
+```
+
 ## additionalReviewers
 
 In contrast to `reviewers`, this option adds to the existing reviewer list, rather than replacing it. This makes it suitable for augmenting a preset or base list without displacing the original, for example when adding focused reviewers for a specific package group.
@@ -164,7 +174,7 @@ Note that this setting does not change the default _onboarding_ branch name, i.e
 
 ## branchTopic
 
-This field is combined with `branchPrefix` and `managerBranchPrefix` to form the full `branchName`. `branchName` uniqueness is important for dependency update grouping or non-grouping so be cautious about ever editing this field manually. This is an advance field and it's recommend you seek a config review before applying it.
+This field is combined with `branchPrefix` and `additionalBranchPrefix` to form the full `branchName`. `branchName` uniqueness is important for dependency update grouping or non-grouping so be cautious about ever editing this field manually. This is an advance field and it's recommend you seek a config review before applying it.
 
 ## bumpVersion
 
@@ -734,10 +744,6 @@ To reduce "noise" in the repository, it defaults its schedule to `"before 5am on
 
 Add to this object if you wish to define rules that apply only to major updates.
 
-## managerBranchPrefix
-
-This value defaults to an empty string, because historically no prefix was necessary for when Renovate was JS-only. Now - for example - we use `docker-` for Docker branches, so they may look like `renovate/docker-ubuntu-16.x`. You normally don't need to configure this.
-
 ## minor
 
 Add to this object if you wish to define rules that apply only to minor updates.
diff --git a/docs/usage/configuration-templates.md b/docs/usage/configuration-templates.md
index a320d101b5..09068e4ff7 100644
--- a/docs/usage/configuration-templates.md
+++ b/docs/usage/configuration-templates.md
@@ -11,13 +11,13 @@ This document describes how you can edit the branch names, commit messages, or P
 
 The branch name is very important for Renovate because it helps determine "grouping" of updates, and also makes it efficient when an existing PR needs to be updated with a newer version. Also, if you change branchPrefix and have some upgrades "ignored" (closed without merging) then you may see duplicate PRs opened with your new branch name.
 
-`branchName` has a default value of `{{{branchPrefix}}}{{{managerBranchPrefix}}}{{{branchTopic}}}`.
+`branchName` has a default value of `{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}`.
 
-The most common type of branch name you will see looks like this: `renovate/react-16.x`. In this example, the `branchPrefix` is the default `renovate/`, `managerBranchPrefix` is empty, and `branchTopic` is `react-16.x`.
+The most common type of branch name you will see looks like this: `renovate/react-16.x`. In this example, the `branchPrefix` is the default `renovate/`, `additionalBranchPrefix` is empty, and `branchTopic` is `react-16.x`.
 
 Most people can leave `branchPrefix` as `renovate/` however if you prefer to have no forward slashes then you might pick `renovate-` instead. Please note that the onboarding PR is fixed to use `renovate/configure` however.
 
-`managerBranchPrefix` is optional and by default is empty for all JavaScript dependencies. We use `docker-` for all Docker updates, so you might see branches like `renovate/docker-ubuntu-16.x`.
+`additionalBranchPrefix` is optional and by default is empty for all JavaScript dependencies. We use `docker-` for all Docker updates, so you might see branches like `renovate/docker-ubuntu-16.x`.
 
 `branchTopic` depends on the package manager and upgrade type, so you will see a lot of variety. It is also the one you might be most likely to want to change, but be careful and consider posting your config to https://github.com/renovateapp/config-help first.
 
diff --git a/lib/config/__snapshots__/migration.spec.ts.snap b/lib/config/__snapshots__/migration.spec.ts.snap
index 1f7c3e6333..3442949a7c 100644
--- a/lib/config/__snapshots__/migration.spec.ts.snap
+++ b/lib/config/__snapshots__/migration.spec.ts.snap
@@ -8,6 +8,7 @@ Object {
 
 exports[`config/migration migrateConfig(config, parentConfig) it migrates config 1`] = `
 Object {
+  "additionalBranchPrefix": "foo",
   "autodiscover": true,
   "automerge": false,
   "automergeType": "branch",
diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts
index 3e7fd0858b..c4985c62fc 100644
--- a/lib/config/definitions.ts
+++ b/lib/config/definitions.ts
@@ -1218,12 +1218,12 @@ const options: RenovateOptions[] = [
     name: 'branchName',
     description: 'Branch name template',
     type: 'string',
-    default: '{{{branchPrefix}}}{{{managerBranchPrefix}}}{{{branchTopic}}}',
+    default: '{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}',
     cli: false,
   },
   {
-    name: 'managerBranchPrefix',
-    description: 'Branch manager prefix',
+    name: 'additionalBranchPrefix',
+    description: 'Additional string value to be appended to branchPrefix',
     type: 'string',
     default: '',
     cli: false,
diff --git a/lib/config/migration.spec.ts b/lib/config/migration.spec.ts
index 0d2c8f55df..86dae20755 100644
--- a/lib/config/migration.spec.ts
+++ b/lib/config/migration.spec.ts
@@ -43,6 +43,7 @@ describe('config/migration', () => {
         upgradeInRange: true,
         automergeType: 'branch-push',
         baseBranch: 'next',
+        managerBranchPrefix: 'foo',
         renovateFork: true,
         ignoreNodeModules: true,
         node: {
diff --git a/lib/config/migration.ts b/lib/config/migration.ts
index ee9be62973..f71bd3e367 100644
--- a/lib/config/migration.ts
+++ b/lib/config/migration.ts
@@ -190,6 +190,10 @@ export function migrateConfig(
         } else if (val === false) {
           migratedConfig.trustLevel = 'low';
         }
+      } else if (key === 'managerBranchPrefix') {
+        isMigrated = true;
+        delete migratedConfig.managerBranchPrefix;
+        migratedConfig.additionalBranchPrefix = val;
       } else if (key === 'upgradeInRange') {
         isMigrated = true;
         delete migratedConfig.upgradeInRange;
diff --git a/lib/config/validation.ts b/lib/config/validation.ts
index 12429e340d..c16210281d 100644
--- a/lib/config/validation.ts
+++ b/lib/config/validation.ts
@@ -32,7 +32,7 @@ export async function validateConfig(
 
   function getDeprecationMessage(option: string): string {
     const deprecatedOptions = {
-      branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, managerBranchPrefix, or branchTopic instead`,
+      branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, additionalBranchPrefix, or branchTopic instead`,
       commitMessage: `Direct editing of commitMessage is now deprecated. Please edit commitMessage's subcomponents instead.`,
       prTitle: `Direct editing of prTitle is now deprecated. Please edit commitMessage subcomponents instead as they will be passed through to prTitle.`,
     };
diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts
index a1ffbd65b1..1bf5f5b037 100644
--- a/lib/datasource/docker/index.ts
+++ b/lib/datasource/docker/index.ts
@@ -21,7 +21,7 @@ export const defaultRegistryUrls = ['https://index.docker.io'];
 export const registryStrategy = 'first';
 
 export const defaultConfig = {
-  managerBranchPrefix: 'docker-',
+  additionalBranchPrefix: 'docker-',
   commitMessageTopic: '{{{depName}}} Docker tag',
   major: { enabled: false },
   commitMessageExtra:
diff --git a/lib/manager/buildkite/index.ts b/lib/manager/buildkite/index.ts
index b11a9d6f82..a97b1018ed 100644
--- a/lib/manager/buildkite/index.ts
+++ b/lib/manager/buildkite/index.ts
@@ -7,5 +7,5 @@ export const defaultConfig = {
   commitMessageTopic: 'buildkite plugin {{depName}}',
   commitMessageExtra:
     'to {{#if isMajor}}v{{{newMajor}}}{{else}}{{{newValue}}}{{/if}}',
-  managerBranchPrefix: 'buildkite-',
+  additionalBranchPrefix: 'buildkite-',
 };
diff --git a/lib/manager/cargo/index.ts b/lib/manager/cargo/index.ts
index 43e59812b4..6f19e76b2c 100644
--- a/lib/manager/cargo/index.ts
+++ b/lib/manager/cargo/index.ts
@@ -11,7 +11,7 @@ export { extractPackageFile, updateArtifacts, language };
 
 export const defaultConfig = {
   commitMessageTopic: 'Rust crate {{depName}}',
-  managerBranchPrefix: 'rust-',
+  additionalBranchPrefix: 'rust-',
   fileMatch: ['(^|/)Cargo.toml$'],
   versioning: cargoVersioning.id,
   rangeStrategy: 'bump',
diff --git a/lib/manager/homebrew/index.ts b/lib/manager/homebrew/index.ts
index 9e04159829..62bb3b08a5 100644
--- a/lib/manager/homebrew/index.ts
+++ b/lib/manager/homebrew/index.ts
@@ -3,6 +3,6 @@ export { updateDependency } from './update';
 
 export const defaultConfig = {
   commitMessageTopic: 'Homebrew Formula {{depName}}',
-  managerBranchPrefix: 'homebrew-',
+  additionalBranchPrefix: 'homebrew-',
   fileMatch: ['^Formula/[^/]+[.]rb$'],
 };
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index 502a863997..2160a8f2ca 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -23,7 +23,7 @@ export const exposedConfigOptions = [
   'group',
   'groupSlug',
   'groupName',
-  'managerBranchPrefix',
+  'additionalBranchPrefix',
   'prBodyColumns',
   'prBodyDefinitions',
   'prBodyNotes',
diff --git a/lib/workers/repository/init/__snapshots__/config.spec.ts.snap b/lib/workers/repository/init/__snapshots__/config.spec.ts.snap
index 3b4c400fcd..679719c9c7 100644
--- a/lib/workers/repository/init/__snapshots__/config.spec.ts.snap
+++ b/lib/workers/repository/init/__snapshots__/config.spec.ts.snap
@@ -18,6 +18,7 @@ exports[`workers/repository/init/config detectRepoFileConfig() uses package.json
 
 exports[`workers/repository/init/config mergeRenovateConfig() continues if no errors 1`] = `
 Object {
+  "additionalBranchPrefix": "",
   "additionalReviewers": Array [],
   "aliases": Object {},
   "allowedPostUpgradeCommands": Array [],
@@ -52,17 +53,17 @@ Object {
   },
   "bbUseDefaultReviewers": true,
   "binarySource": "auto",
-  "branchName": "{{{branchPrefix}}}{{{managerBranchPrefix}}}{{{branchTopic}}}",
+  "branchName": "{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}",
   "branchPrefix": "renovate/",
   "branchTopic": "{{{depNameSanitized}}}-{{{newMajor}}}{{#if isPatch}}.{{{newMinor}}}{{/if}}.x{{#if isLockfileUpdate}}-lockfile{{/if}}",
   "buildkite": Object {
+    "additionalBranchPrefix": "buildkite-",
     "commitMessageExtra": "to {{#if isMajor}}v{{{newMajor}}}{{else}}{{{newValue}}}{{/if}}",
     "commitMessageTopic": "buildkite plugin {{depName}}",
     "fileMatch": Array [
       "buildkite\\\\.ya?ml",
       "\\\\.buildkite/.+\\\\.ya?ml$",
     ],
-    "managerBranchPrefix": "buildkite-",
   },
   "bumpVersion": null,
   "bundler": Object {
@@ -73,11 +74,11 @@ Object {
   },
   "cacheDir": null,
   "cargo": Object {
+    "additionalBranchPrefix": "rust-",
     "commitMessageTopic": "Rust crate {{depName}}",
     "fileMatch": Array [
       "(^|/)Cargo.toml$",
     ],
-    "managerBranchPrefix": "rust-",
     "rangeStrategy": "bump",
     "versioning": "cargo",
   },
@@ -257,11 +258,11 @@ Object {
     ],
   },
   "homebrew": Object {
+    "additionalBranchPrefix": "homebrew-",
     "commitMessageTopic": "Homebrew Formula {{depName}}",
     "fileMatch": Array [
       "^Formula/[^/]+[.]rb$",
     ],
-    "managerBranchPrefix": "homebrew-",
   },
   "hostRules": Array [
     Object {
@@ -333,7 +334,6 @@ Object {
   "logFileLevel": "debug",
   "logLevel": "info",
   "major": Object {},
-  "managerBranchPrefix": "",
   "maven": Object {
     "fileMatch": Array [
       "\\\\.pom\\\\.xml$",
diff --git a/lib/workers/repository/updates/flatten.ts b/lib/workers/repository/updates/flatten.ts
index 603703329c..d129fb87d5 100644
--- a/lib/workers/repository/updates/flatten.ts
+++ b/lib/workers/repository/updates/flatten.ts
@@ -101,7 +101,7 @@ export async function flattenUpdates(
               updateConfig.depName.match(/(^|\/)node$/) &&
               updateConfig.depName !== 'calico/node'
             ) {
-              updateConfig.managerBranchPrefix = '';
+              updateConfig.additionalBranchPrefix = '';
               updateConfig.depNameSanitized = 'node';
             }
             generateBranchName(updateConfig);
-- 
GitLab