From 6eb3bcca833b393ec2f4828a31f05e7744318e0d Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 23 Jul 2020 11:36:35 +0200
Subject: [PATCH] refactor(platform): remove baseBranch (#6828)

---
 lib/platform/azure/index.ts            |  5 +----
 lib/platform/bitbucket-server/index.ts |  2 --
 lib/platform/bitbucket-server/types.ts |  1 -
 lib/platform/bitbucket/index.ts        |  3 ---
 lib/platform/bitbucket/utils.ts        |  1 -
 lib/platform/gitea/index.ts            |  9 +++------
 lib/platform/github/index.ts           | 12 +++++-------
 lib/platform/github/types.ts           |  1 -
 lib/platform/gitlab/index.ts           |  6 +-----
 9 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts
index 2248bc4bda..1c500fc994 100644
--- a/lib/platform/azure/index.ts
+++ b/lib/platform/azure/index.ts
@@ -40,7 +40,6 @@ import { AzurePr } from './types';
 interface Config {
   repoForceRebase: boolean;
   mergeMethod: GitPullRequestMergeStrategy;
-  baseBranch: string;
   defaultBranch: string;
   owner: string;
   repoId: string;
@@ -118,7 +117,6 @@ export async function initRepo({
   logger.debug(`${repository} owner = ${config.owner}`);
   // Use default branch as PR target unless later overridden
   config.defaultBranch = repo.defaultBranch.replace('refs/heads/', '');
-  config.baseBranch = config.defaultBranch;
   logger.debug(`${repository} default branch = ${config.defaultBranch}`);
   config.mergeMethod = await azureHelper.getMergeMethod(repo.id, names.project);
   config.repoForceRebase = false;
@@ -173,8 +171,7 @@ export function getRepoForceRebase(): Promise<boolean> {
 
 // istanbul ignore next
 export async function setBaseBranch(branchName: string): Promise<string> {
-  logger.debug(`Setting baseBranch to ${branchName}`);
-  config.baseBranch = branchName;
+  logger.debug(`Setting base branch to ${branchName}`);
   const baseBranchSha = await git.setBranch(branchName);
   return baseBranchSha;
 }
diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts
index af0e4ba40f..813e9ee45b 100644
--- a/lib/platform/bitbucket-server/index.ts
+++ b/lib/platform/bitbucket-server/index.ts
@@ -201,7 +201,6 @@ export async function initRepo({
         `./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/branches/default`
       )
     ).body.displayId;
-    config.baseBranch = config.defaultBranch;
     config.mergeMethod = 'merge';
     const repoConfig: RepoConfig = {
       defaultBranch: config.defaultBranch,
@@ -240,7 +239,6 @@ export async function getRepoForceRebase(): Promise<boolean> {
 }
 
 export async function setBaseBranch(branchName: string): Promise<string> {
-  config.baseBranch = branchName;
   const baseBranchSha = await git.setBranch(branchName);
   return baseBranchSha;
 }
diff --git a/lib/platform/bitbucket-server/types.ts b/lib/platform/bitbucket-server/types.ts
index e319775cd4..9acf631ef9 100644
--- a/lib/platform/bitbucket-server/types.ts
+++ b/lib/platform/bitbucket-server/types.ts
@@ -1,7 +1,6 @@
 import { Pr } from '../common';
 
 export interface BbsConfig {
-  baseBranch: string;
   bbUseDefaultReviewers: boolean;
   defaultBranch: string;
   fileList: any[];
diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts
index fc548e9b46..7b6583568e 100644
--- a/lib/platform/bitbucket/index.ts
+++ b/lib/platform/bitbucket/index.ts
@@ -126,7 +126,6 @@ export async function initRepo({
     Object.assign(config, {
       owner: info.owner,
       defaultBranch: info.mainbranch,
-      baseBranch: info.mainbranch,
       mergeMethod: info.mergeMethod,
       has_issues: info.has_issues,
     });
@@ -175,8 +174,6 @@ export function getRepoForceRebase(): Promise<boolean> {
 }
 
 export async function setBaseBranch(branchName: string): Promise<string> {
-  logger.debug(`Setting baseBranch to ${branchName}`);
-  config.baseBranch = branchName;
   const baseBranchSha = await git.setBranch(branchName);
   return baseBranchSha;
 }
diff --git a/lib/platform/bitbucket/utils.ts b/lib/platform/bitbucket/utils.ts
index 4578ed5d6e..188bbbed0c 100644
--- a/lib/platform/bitbucket/utils.ts
+++ b/lib/platform/bitbucket/utils.ts
@@ -8,7 +8,6 @@ import { Pr } from '../common';
 const bitbucketHttp = new BitbucketHttp();
 
 export interface Config {
-  baseBranch: string;
   defaultBranch: string;
   has_issues: boolean;
   mergeMethod: string;
diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts
index ab0f130d08..b38845c870 100644
--- a/lib/platform/gitea/index.ts
+++ b/lib/platform/gitea/index.ts
@@ -47,7 +47,6 @@ interface GiteaRepoConfig {
   repository: string;
   localDir: string;
   defaultBranch: string;
-  baseBranch: string;
   mergeMethod: helper.PRMergeMethod;
 
   prList: Promise<Pr[]> | null;
@@ -280,8 +279,7 @@ const platform: Platform = {
 
     // Determine author email and branches
     config.defaultBranch = repo.default_branch;
-    config.baseBranch = config.defaultBranch;
-    logger.debug(`${repository} default branch = ${config.baseBranch}`);
+    logger.debug(`${repository} default branch = ${config.defaultBranch}`);
 
     // Optionally check if Renovate is disabled by attempting to fetch default configuration file
     if (optimizeForDisabled) {
@@ -421,9 +419,8 @@ const platform: Platform = {
     return BranchStatus.yellow;
   },
 
-  async setBaseBranch(baseBranch: string): Promise<string> {
-    config.baseBranch = baseBranch;
-    const baseBranchSha = await git.setBranch(baseBranch);
+  async setBaseBranch(branchName: string): Promise<string> {
+    const baseBranchSha = await git.setBranch(branchName);
     return baseBranchSha;
   },
 
diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts
index 6f42a5bfee..8d1b2c0be5 100644
--- a/lib/platform/github/index.ts
+++ b/lib/platform/github/index.ts
@@ -274,8 +274,7 @@ export async function initRepo({
     // Use default branch as PR target unless later overridden.
     config.defaultBranch = repo.defaultBranchRef.name;
     // Base branch may be configured but defaultBranch is always fixed
-    config.baseBranch = config.defaultBranch;
-    logger.debug(`${repository} default branch = ${config.baseBranch}`);
+    logger.debug(`${repository} default branch = ${config.defaultBranch}`);
     // GitHub allows administrators to block certain types of merge, so we need to check it
     if (repo.rebaseMergeAllowed) {
       config.mergeMethod = 'rebase';
@@ -361,14 +360,14 @@ export async function initRepo({
       );
       // Need to update base branch
       logger.debug(
-        { baseBranch: config.baseBranch, parentSha },
-        'Setting baseBranch ref in fork'
+        { defaultBranch: config.defaultBranch, parentSha },
+        'Setting defaultBranch ref in fork'
       );
       // This is a lovely "hack" by GitHub that lets us force update our fork's master
       // with the base commit from the parent repository
       try {
         await githubApi.patchJson(
-          `repos/${config.repository}/git/refs/heads/${config.baseBranch}`,
+          `repos/${config.repository}/git/refs/heads/${config.defaultBranch}`,
           {
             body: {
               sha: parentSha,
@@ -434,7 +433,7 @@ export async function getRepoForceRebase(): Promise<boolean> {
   if (config.repoForceRebase === undefined) {
     try {
       config.repoForceRebase = false;
-      const branchProtection = await getBranchProtection(config.baseBranch);
+      const branchProtection = await getBranchProtection(config.defaultBranch);
       logger.debug('Found branch protection');
       if (branchProtection.required_pull_request_reviews) {
         logger.debug(
@@ -477,7 +476,6 @@ export async function getRepoForceRebase(): Promise<boolean> {
 
 // istanbul ignore next
 export async function setBaseBranch(branchName: string): Promise<string> {
-  config.baseBranch = branchName;
   const baseBranchSha = await git.setBranch(branchName);
   return baseBranchSha;
 }
diff --git a/lib/platform/github/types.ts b/lib/platform/github/types.ts
index 49eb596fc3..5c96728dca 100644
--- a/lib/platform/github/types.ts
+++ b/lib/platform/github/types.ts
@@ -37,7 +37,6 @@ export interface LocalRepoConfig {
   prList: GhPr[] | null;
   issueList: any[] | null;
   mergeMethod: string;
-  baseBranch: string;
   defaultBranch: string;
   repositoryOwner: string;
   repository: string | null;
diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts
index 868db07ea5..937b6e96b1 100644
--- a/lib/platform/gitlab/index.ts
+++ b/lib/platform/gitlab/index.ts
@@ -60,7 +60,6 @@ let config: {
   repository: string;
   localDir: string;
   defaultBranch: string;
-  baseBranch: string;
   email: string;
   prList: any[];
   issueList: any[];
@@ -200,9 +199,8 @@ export async function initRepo({
       }
     }
     config.defaultBranch = res.body.default_branch;
-    config.baseBranch = config.defaultBranch;
     config.mergeMethod = res.body.merge_method || 'merge';
-    logger.debug(`${repository} default branch = ${config.baseBranch}`);
+    logger.debug(`${repository} default branch = ${config.defaultBranch}`);
     delete config.prList;
     logger.debug('Enabling Git FS');
     const opts = hostRules.find({
@@ -266,8 +264,6 @@ export function getRepoForceRebase(): Promise<boolean> {
 }
 
 export async function setBaseBranch(branchName: string): Promise<string> {
-  logger.debug(`Setting baseBranch to ${branchName}`);
-  config.baseBranch = branchName;
   const baseBranchSha = await git.setBranch(branchName);
   return baseBranchSha;
 }
-- 
GitLab