summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@igalia.com>2018-01-25 18:20:58 -0300
committerThibault Saunier <tsaunier@igalia.com>2018-01-28 13:02:55 -0300
commit89ff39bc54226bf6ad30c7a3919901dde96d4c23 (patch)
tree8b838923cafe2ebe5a99fa0ed857123251866533
parent8d06dfc8f36d70277b402653ba3e933619f34ff4 (diff)
bztogl: Use GitLab object from common.py
-rw-r--r--bztogl/bztogl.py104
-rwxr-xr-xbztogl/phabtogl.py5
2 files changed, 5 insertions, 104 deletions
diff --git a/bztogl/bztogl.py b/bztogl/bztogl.py
index 904e5a4..46053b5 100644
--- a/bztogl/bztogl.py
+++ b/bztogl/bztogl.py
@@ -22,6 +22,7 @@ import sys
22import urllib.parse 22import urllib.parse
23 23
24import bugzilla 24import bugzilla
25import gitlab
25 26
26from . import common, template, users 27from . import common, template, users
27 28
@@ -35,101 +36,6 @@ KEYWORD_MAP = {
35GIT_ORIGIN_PREFIX = 'https://git.gnome.org/browse/' 36GIT_ORIGIN_PREFIX = 'https://git.gnome.org/browse/'
36 37
37 38
38class GitLab:
39 GITLABURL = "https://gitlab-test.gnome.org/"
40
41 def __init__(self, token, product, target_project=None, automate=False):
42 self.gl = None
43 self.token = token
44 self.product = product
45 self.target_project = target_project
46 self.automate = automate
47
48 def connect(self):
49 print("Connecting to %s" % self.GITLABURL)
50 self.gl = gitlab.Gitlab(self.GITLABURL, self.token, api_version=4)
51 self.gl.auth()
52 # If not target project was given, set the project under the user
53 # namespace
54 if self.target_project is None:
55 self.target_project = self.gl.user.username + '/' + self.product
56 print("Using target project '{}' since --target-project was not \
57 provided".format(self.target_project))
58
59 def get_project(self):
60 return self.gl.projects.get(self.target_project)
61
62 def create_issue(self, id, summary, description, labels, creation_time):
63 return self.get_project().issues.create({
64 'title': summary,
65 'description': description,
66 'labels': labels,
67 'created_at': creation_time
68 })
69
70 def get_all_users(self):
71 return self.gl.users.list(all=True)
72
73 def find_user(self, user_id):
74 return self.gl.users.get(user_id)
75
76 def remove_project(self, project):
77 try:
78 project.delete()
79 except Exception as e:
80 raise Exception("Could not remove project: {}".format(project))
81
82 def get_import_status(self, project):
83 url = (self.GITLABURL +
84 "api/v4/projects/{}".format(project.id))
85 self.gl.session.headers = {"PRIVATE-TOKEN": self.token}
86 ret = self.gl.session.get(url)
87 if ret.status_code != 200:
88 raise Exception("Could not get import status: {}".format(ret.text))
89
90 ret_json = json.loads(ret.text)
91 return ret_json.get('import_status')
92
93 def import_project(self):
94 import_url = GIT_ORIGIN_PREFIX + self.product
95 print('Importing project from ' + import_url +
96 ' to ' + self.target_project)
97
98 try:
99 project = self.get_project()
100 except Exception as e:
101 project = None
102
103 if project is not None:
104 print('##############################################')
105 print('# WARNING #')
106 print('##############################################')
107 print('THIS WILL DELETE YOUR PROJECT IN GITLAB.')
108 print('ARE YOU SURE YOU WANT TO CONTINUE? Y/N')
109
110 if not self.automate:
111 answer = input('')
112 else:
113 answer = 'Y'
114 print('Y (automated)')
115
116 if answer == 'Y':
117 self.remove_project(project)
118 else:
119 print('Bugs will be added to the existing project')
120 return
121
122 project = self.gl.projects.create({'name': self.product,
123 'import_url': import_url,
124 'visibility': 'public'})
125
126 import_status = self.get_import_status(project)
127 while(import_status != 'finished'):
128 print('Importing project, status: ' + import_status)
129 time.sleep(1)
130 import_status = self.get_import_status(project)
131
132
133def processbug(bgo, target, user_cache, bzbug): 39def processbug(bgo, target, user_cache, bzbug):
134 print("Processing bug #%d: %s" % (bzbug.id, bzbug.summary)) 40 print("Processing bug #%d: %s" % (bzbug.id, bzbug.summary))
135 # bzbug.cc 41 # bzbug.cc
@@ -379,8 +285,8 @@ def check_if_target_project_exists(target):
379def main(): 285def main():
380 args = options() 286 args = options()
381 287
382 target = GitLab(args.token, args.product, args.target_project, 288 target = common.GitLab(args.token, args.product, args.target_project,
383 args.automate) 289 args.automate)
384 if args.production: 290 if args.production:
385 target.GITLABURL = "https://gitlab.gnome.org/" 291 target.GITLABURL = "https://gitlab.gnome.org/"
386 292
@@ -397,8 +303,8 @@ def main():
397 303
398 print("Connecting to bugzilla.gnome.org") 304 print("Connecting to bugzilla.gnome.org")
399 if args.bz_user and args.bz_password: 305 if args.bz_user and args.bz_password:
400 bgo = bugzilla.Bugzilla("https://bugzilla.gnome.org", args.bz_user, 306 bgo = bugzilla.Bugzilla("https://bugzilla.gnome.org",
401 args.bz_password) 307 args.bz_user, args.bz_password)
402 else: 308 else:
403 print("WARNING: Bugzilla credentials were not provided, BZ bugs won't " 309 print("WARNING: Bugzilla credentials were not provided, BZ bugs won't "
404 "be closed and subscribers won't notice the migration") 310 "be closed and subscribers won't notice the migration")
diff --git a/bztogl/phabtogl.py b/bztogl/phabtogl.py
index 112ff61..f54ed77 100755
--- a/bztogl/phabtogl.py
+++ b/bztogl/phabtogl.py
@@ -1,8 +1,3 @@
1#!/usr/bin/env python3
2
3"""
4"""
5
6import argparse 1import argparse
7import base64 2import base64
8import datetime 3import datetime