From e5e1a181ffd52a4fdc81d503caa9c2c6e7910e72 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sun, 7 Jun 2020 13:26:08 +0200
Subject: [PATCH] =?UTF-8?q?refactor(bitbucket):=20don=E2=80=99t=20use=20en?=
 =?UTF-8?q?dpoint=20in=20initRepo=20(#6457)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 lib/platform/bitbucket/index.ts | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts
index 0b89dc1b6c..61552d83da 100644
--- a/lib/platform/bitbucket/index.ts
+++ b/lib/platform/bitbucket/index.ts
@@ -41,6 +41,8 @@ const BITBUCKET_PROD_ENDPOINT = 'https://api.bitbucket.org/';
 
 let config: utils.Config = {} as any;
 
+let endpoint_ = BITBUCKET_PROD_ENDPOINT;
+
 export function initPlatform({
   endpoint,
   username,
@@ -55,7 +57,9 @@ export function initPlatform({
     logger.warn(
       `Init: Bitbucket Cloud endpoint should generally be ${BITBUCKET_PROD_ENDPOINT} but is being configured to a different value. Did you mean to use Bitbucket Server?`
     );
+    endpoint_ = endpoint;
   }
+  setBaseUrl(endpoint_);
   // TODO: Add a connection check that endpoint/username/password combination are valid
   const platformConfig: PlatformConfig = {
     endpoint: endpoint || BITBUCKET_PROD_ENDPOINT,
@@ -83,14 +87,12 @@ export async function initRepo({
   localDir,
   optimizeForDisabled,
   bbUseDefaultReviewers,
-  endpoint = BITBUCKET_PROD_ENDPOINT,
 }: RepoParams): Promise<RepoConfig> {
   logger.debug(`initRepo("${repository}")`);
   const opts = hostRules.find({
     hostType: PLATFORM_TYPE_BITBUCKET,
-    url: endpoint,
+    url: endpoint_,
   });
-  setBaseUrl(endpoint);
   config = {
     repository,
     username: opts.username,
@@ -139,7 +141,7 @@ export async function initRepo({
     throw err;
   }
 
-  const { hostname } = URL.parse(endpoint);
+  const { hostname } = URL.parse(endpoint_);
 
   // Converts API hostnames to their respective HTTP git hosts:
   // `api.bitbucket.org`  to `bitbucket.org`
-- 
GitLab