Commit 27fa0507 authored by Daniel Stone's avatar Daniel Stone
Browse files

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: default avatarDaniel Stone <daniels@collabora.com>
parent 6aa87d1a
......@@ -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:
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment