From 27fa05071818610b00d03bdb9dc97f72e1bee31f Mon Sep 17 00:00:00 2001
From: Daniel Stone <daniels@collabora.com>
Date: Sun, 6 May 2018 13:26:41 +0100
Subject: [PATCH] Pass source/destination URLs from program into common

Don't encode knowledge of GNOME servers into the common script, but only
from the shell.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 bztogl/bztogl.py | 22 +++++++++++++---------
 bztogl/common.py | 21 ++++++++++-----------
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/bztogl/bztogl.py b/bztogl/bztogl.py
index 9e3ba94..3002a56 100644
--- a/bztogl/bztogl.py
+++ b/bztogl/bztogl.py
@@ -32,6 +32,7 @@ KEYWORD_MAP = {
     "newcomers": "4. Newcomers",
     "security": "1. Security"
 }
+
 COMPONENT_MAP = {
     'Accessibility': '8. Accessibility',
     'Backend: Broadway': 'Broadway',
@@ -86,8 +87,8 @@ def processbug(bgo, target, user_cache, milestone_cache, bzbug):
         return index
 
     def gitlab_upload_file(target, filename, f):
-        url = (target.GITLABURL +
-               "api/v3/projects/{}/uploads".format(target.get_project().id))
+        url = "{}api/v3/projects/{}/uploads".format(target.gl_url,
+                                                    target.get_project().id)
         target.gl.session.headers = {"PRIVATE-TOKEN": target.token}
         ret = target.gl.session.post(url, files={
             'file': (urllib.parse.quote(filename), f)
@@ -342,10 +343,14 @@ def check_if_target_project_exists(target):
 def main():
     args = options()
 
-    target = common.GitLab(args.token, args.product, args.target_project,
-                           args.automate)
     if args.production:
-        target.GITLABURL = "https://gitlab.gnome.org/"
+        glurl = "https://gitlab.gnome.org/"
+    else:
+        glurl = "https://gitlab-test.gnome.org/"
+    bzurl = "https://bugzilla.gnome.org/"
+    giturl = "https://git.gnome.org/browse/"
+    target = common.GitLab(glurl, giturl, args.token, args.product,
+                           args.target_project, args.automate)
 
     target.connect()
 
@@ -358,14 +363,13 @@ def main():
     if args.only_import:
         return
 
-    print("Connecting to bugzilla.gnome.org")
+    print("Connecting to %s" % bzurl)
     if args.bz_user and args.bz_password:
-        bgo = bugzilla.Bugzilla("https://bugzilla.gnome.org",
-                                args.bz_user, args.bz_password)
+        bgo = bugzilla.Bugzilla(bzurl, args.bz_user, args.bz_password)
     else:
         print("WARNING: Bugzilla credentials were not provided, BZ bugs won't "
               "be closed and subscribers won't notice the migration")
-        bgo = bugzilla.Bugzilla("https://bugzilla.gnome.org", tokenfile=None)
+        bgo = bugzilla.Bugzilla(bzurl, tokenfile=None)
 
     query = bgo.build_query(product=args.product, component=args.component)
     if args.component:
diff --git a/bztogl/common.py b/bztogl/common.py
index 42d69c0..623742e 100644
--- a/bztogl/common.py
+++ b/bztogl/common.py
@@ -6,11 +6,11 @@ import gitlab
 
 
 class GitLab:
-    GITLABURL = "https://gitlab-test.gnome.org/"
-    GIT_ORIGIN_PREFIX = 'https://git.gnome.org/browse/'
-
-    def __init__(self, token, product, target_project=None, automate=False):
+    def __init__(self, gitlab_url, git_url, token, product,
+                 target_project=None, automate=False):
         self.gl = None
+        self.gl_url = gitlab_url
+        self.git_url = git_url
         self.token = token
         self.product = product
         self.target_project = target_project
@@ -18,8 +18,8 @@ class GitLab:
         self.all_users = None
 
     def connect(self):
-        print("Connecting to %s" % self.GITLABURL)
-        self.gl = gitlab.Gitlab(self.GITLABURL, self.token, api_version=4)
+        print("Connecting to %s" % self.gl_url)
+        self.gl = gitlab.Gitlab(self.gl_url, self.token, api_version=4)
         self.gl.auth()
         # If not target project was given, set the project under the user
         # namespace
@@ -68,8 +68,7 @@ class GitLab:
             raise Exception("Could not remove project: {}".format(project))
 
     def get_import_status(self, project):
-        url = (self.GITLABURL +
-               "api/v4/projects/{}".format(project.id))
+        url = ("{}api/v4/projects/{}".format(self.gl_url, project.id))
         self.gl.session.headers = {"PRIVATE-TOKEN": self.token}
         ret = self.gl.session.get(url)
         if ret.status_code != 200:
@@ -79,7 +78,7 @@ class GitLab:
         return ret_json.get('import_status')
 
     def import_project(self):
-        import_url = self.GIT_ORIGIN_PREFIX + self.product
+        import_url = self.git_url + self.product
         print('Importing project from ' + import_url +
               ' to ' + self.target_project)
 
@@ -118,8 +117,8 @@ class GitLab:
             import_status = self.get_import_status(project)
 
     def upload_file(self, filename, f):
-        url = (self.GITLABURL +
-               "api/v3/projects/{}/uploads".format(self.get_project().id))
+        url = "{}api/v3/projects/{}/uploads".format(self.gl_url,
+                                                    self.get_project().id)
         self.gl.session.headers = {"PRIVATE-TOKEN": self.token}
         ret = self.gl.session.post(url, files={
             'file': (urllib.parse.quote(filename), f)
-- 
GitLab