From 008f781d42c5f2a4438ac840d0eb986d051aa6af Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 22 Jul 2020 11:13:48 +0200
Subject: [PATCH] refactor: mandatory branchName in setBaseBranch

---
 lib/platform/azure/index.ts                    |  7 ++-----
 lib/platform/bitbucket-server/index.spec.ts    |  1 -
 lib/platform/bitbucket-server/index.ts         |  4 +---
 lib/platform/bitbucket/index.spec.ts           |  1 -
 lib/platform/bitbucket/index.ts                |  6 +-----
 lib/platform/common.ts                         |  2 +-
 lib/platform/gitea/index.spec.ts               |  4 ++--
 lib/platform/gitea/index.ts                    |  4 +---
 lib/platform/github/index.ts                   |  4 +---
 .../gitlab/__snapshots__/index.spec.ts.snap    | 16 ----------------
 lib/platform/gitlab/index.spec.ts              | 18 +-----------------
 lib/platform/gitlab/index.ts                   |  4 +---
 12 files changed, 11 insertions(+), 60 deletions(-)

diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts
index e3648c1f98..edeedc15f9 100644
--- a/lib/platform/azure/index.ts
+++ b/lib/platform/azure/index.ts
@@ -182,11 +182,8 @@ export function getRepoForceRebase(): Promise<boolean> {
   return Promise.resolve(config.repoForceRebase === true);
 }
 
-// Search
-
-export /* istanbul ignore next */ async function setBaseBranch(
-  branchName = config.baseBranch
-): Promise<string> {
+// istanbul ignore next
+export async function setBaseBranch(branchName: string): Promise<string> {
   logger.debug(`Setting baseBranch to ${branchName}`);
   config.baseBranch = branchName;
   delete config.baseCommitSHA;
diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts
index 69452e1ec5..d2af78c6b4 100644
--- a/lib/platform/bitbucket-server/index.spec.ts
+++ b/lib/platform/bitbucket-server/index.spec.ts
@@ -396,7 +396,6 @@ describe(getName(__filename), () => {
           expect.assertions(1);
           await initRepo();
           await bitbucket.setBaseBranch('branch');
-          await bitbucket.setBaseBranch();
           expect(httpMock.getTrace()).toMatchSnapshot();
         });
       });
diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts
index 3b11ef91da..21242e32bb 100644
--- a/lib/platform/bitbucket-server/index.ts
+++ b/lib/platform/bitbucket-server/index.ts
@@ -239,9 +239,7 @@ export async function getRepoForceRebase(): Promise<boolean> {
   );
 }
 
-export async function setBaseBranch(
-  branchName: string = config.defaultBranch
-): Promise<string> {
+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/index.spec.ts b/lib/platform/bitbucket/index.spec.ts
index 6e44674dc3..c13f29300e 100644
--- a/lib/platform/bitbucket/index.spec.ts
+++ b/lib/platform/bitbucket/index.spec.ts
@@ -189,7 +189,6 @@ describe('platform/bitbucket', () => {
     it('updates file list', async () => {
       await initRepoMock();
       await bitbucket.setBaseBranch('branch');
-      await bitbucket.setBaseBranch();
       expect(httpMock.getTrace()).toMatchSnapshot();
     });
   });
diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts
index 28c5d8215b..cfd1f782d9 100644
--- a/lib/platform/bitbucket/index.ts
+++ b/lib/platform/bitbucket/index.ts
@@ -175,11 +175,7 @@ export function getRepoForceRebase(): Promise<boolean> {
   return Promise.resolve(false);
 }
 
-// Search
-
-export async function setBaseBranch(
-  branchName = config.baseBranch
-): Promise<string> {
+export async function setBaseBranch(branchName: string): Promise<string> {
   logger.debug(`Setting baseBranch to ${branchName}`);
   config.baseBranch = branchName;
   delete config.baseCommitSHA;
diff --git a/lib/platform/common.ts b/lib/platform/common.ts
index a5fccf2168..cc556f694c 100644
--- a/lib/platform/common.ts
+++ b/lib/platform/common.ts
@@ -154,7 +154,7 @@ export interface Platform {
   ): Promise<void>;
   deleteBranch(branchName: string, closePr?: boolean): Promise<void>;
   ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>;
-  setBaseBranch(baseBranch?: string): Promise<string>;
+  setBaseBranch(branchName: string): Promise<string>;
   getPr(number: number): Promise<Pr>;
   findPr(findPRConfig: FindPRConfig): Promise<Pr>;
   refreshPr?(number: number): Promise<void>;
diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts
index e075a87fb2..43211bfa26 100644
--- a/lib/platform/gitea/index.spec.ts
+++ b/lib/platform/gitea/index.spec.ts
@@ -386,9 +386,9 @@ describe('platform/gitea', () => {
       expect(logger.warn).toHaveBeenCalledTimes(1);
     });
 
-    it('should set default base branch', async () => {
+    it('should set base branch', async () => {
       await initFakeRepo();
-      await gitea.setBaseBranch();
+      await gitea.setBaseBranch('master');
 
       expect(gitvcs.setBranch).toHaveBeenCalledTimes(1);
       expect(gitvcs.setBranch).toHaveBeenCalledWith(mockRepo.default_branch);
diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts
index 919776efff..76b5c5da98 100644
--- a/lib/platform/gitea/index.ts
+++ b/lib/platform/gitea/index.ts
@@ -447,9 +447,7 @@ const platform: Platform = {
     return BranchStatus.yellow;
   },
 
-  async setBaseBranch(
-    baseBranch: string = config.defaultBranch
-  ): Promise<string> {
+  async setBaseBranch(baseBranch: string): Promise<string> {
     config.baseBranch = baseBranch;
     const baseBranchSha = await git.setBranch(baseBranch);
     return baseBranchSha;
diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts
index 47df331dbd..4d47be3981 100644
--- a/lib/platform/github/index.ts
+++ b/lib/platform/github/index.ts
@@ -500,9 +500,7 @@ export async function getRepoForceRebase(): Promise<boolean> {
 }
 
 // istanbul ignore next
-export async function setBaseBranch(
-  branchName = config.baseBranch
-): Promise<string> {
+export async function setBaseBranch(branchName: string): Promise<string> {
   config.baseBranch = branchName;
   config.baseCommitSHA = null;
   const baseBranchSha = await git.setBranch(branchName);
diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
index 2ece084bd0..0de65bebf7 100644
--- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
@@ -1690,22 +1690,6 @@ Array [
 ]
 `;
 
-exports[`platform/gitlab setBaseBranch(branchName) uses default base branch 1`] = `
-Array [
-  Object {
-    "headers": Object {
-      "accept": "application/json",
-      "accept-encoding": "gzip, deflate",
-      "host": "gitlab.com",
-      "private-token": "abc123",
-      "user-agent": "https://github.com/renovatebot/renovate",
-    },
-    "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/some%2Frepo",
-  },
-]
-`;
-
 exports[`platform/gitlab setBranchStatus sets branch status green 1`] = `
 Array [
   Object {
diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts
index 444bee0e92..bacbb9eace 100644
--- a/lib/platform/gitlab/index.spec.ts
+++ b/lib/platform/gitlab/index.spec.ts
@@ -347,23 +347,7 @@ describe('platform/gitlab', () => {
         localDir: '',
         optimizeForDisabled: false,
       });
-      await gitlab.setBaseBranch();
-      expect(httpMock.getTrace()).toMatchSnapshot();
-    });
-    it('uses default base branch', async () => {
-      httpMock
-        .scope(gitlabApiHost)
-        .get(`/api/v4/projects/some%2Frepo`)
-        .reply(200, {
-          default_branch: 'master',
-          http_url_to_repo: `https://gitlab.com/some/repo.git`,
-        });
-      await gitlab.initRepo({
-        repository: 'some/repo',
-        localDir: '',
-        optimizeForDisabled: false,
-      });
-      await gitlab.setBaseBranch();
+      await gitlab.setBaseBranch('master');
       expect(httpMock.getTrace()).toMatchSnapshot();
     });
   });
diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts
index b0ee49e0f5..1a413b4233 100644
--- a/lib/platform/gitlab/index.ts
+++ b/lib/platform/gitlab/index.ts
@@ -265,9 +265,7 @@ export function getRepoForceRebase(): Promise<boolean> {
   return Promise.resolve(config?.mergeMethod !== 'merge');
 }
 
-export async function setBaseBranch(
-  branchName = config.baseBranch
-): Promise<string> {
+export async function setBaseBranch(branchName: string): Promise<string> {
   logger.debug(`Setting baseBranch to ${branchName}`);
   config.baseBranch = branchName;
   const baseBranchSha = await git.setBranch(branchName);
-- 
GitLab