Commit 95c3d88c authored by Romain Bouvier's avatar Romain Bouvier
Browse files

Add a --migrate-components switch. Default: no

- This allow the migration of bugzilla components to a gitlab label.
- Only enable it when you want migrate components. Lots of Xfce does not
have relevant components.
parent 7a44074e
......@@ -56,7 +56,7 @@ COMPONENT_MAP = {
def processbug(bgo, bzurl, instance, resolution, target, user_cache,
milestone_cache, bzbug):
milestone_cache, bzbug, migrate_components):
print("Processing bug #%d: %s" % (bzbug.id, bzbug.summary))
# bzbug.cc
# bzbug.id
......@@ -221,17 +221,15 @@ def processbug(bgo, bzurl, instance, resolution, target, user_cache,
description = \
template.render_issue_description(bzurl, bzbug, desctext, user_cache)
# Add a "bugzilla" label on all imported bugs
labels = ['bugzilla']
# Only set "bugzilla' label when migrating. Labels present in bz are not revelant
# if bzbug.status == 'NEEDINFO':
# labels += [NEEDINFO_LABEL]
#
# if bzbug.component.lower() not in ('general', '.general', target.product):
# l = COMPONENT_MAP.get(bzbug.component, None)
# if l is not None:
# labels.append(l)
# else:
# labels.append('5. {}'.format(bzbug.component.title()))
if migrate_components:
if bzbug.component.lower() not in ('general', '.general', target.product):
labels.append('{}'.format(bzbug.component.title()))
#
# for kw in bzbug.keywords:
# if kw in KEYWORD_MAP:
......@@ -253,8 +251,11 @@ def processbug(bgo, bzurl, instance, resolution, target, user_cache,
#sudo=sudo)
# Assign bug to actual account if exists
print("bz issue assigned to {}".format(bzbug.assigned_to))
assignee = user_cache[bzbug.assigned_to]
print("Assign issue to {} if possible".format(assignee))
if assignee and assignee.id is not None:
print("Assign issue to {}".format(assignee))
issue.assignee_id = assignee.id
print("Migrating comments: ")
......@@ -297,10 +298,14 @@ def processbug(bgo, bzurl, instance, resolution, target, user_cache,
for cc_email in itertools.chain(bzbug.cc, [bzbug.creator]):
subscriber = user_cache[cc_email]
if subscriber and subscriber.id is not None:
print("issue cc to {}".format(subscriber))
try:
issue.subscribe(sudo=subscriber.username)
print("is subscribe ok ?")
except gitlab.GitlabSubscribeError as e:
if e.response_code in (201, 304):
print("Response code : {}".format(e.response_code))
print("Response : {}".format(e))
# 201 == workaround for python-gitlab bug
# https://github.com/python-gitlab/python-gitlab/pull/382
# 304 == already subscribed
......@@ -364,6 +369,8 @@ def options():
help="import for xfce.org rather than GNOME")
parser.add_argument('--resolved', action='store_true',
help="import resolved bugs (default: no)")
parser.add_argument('--migrate-components', action='store_true',
help="import bugzilla components (=gitlab label) (default: no)")
return parser.parse_args()
......@@ -429,6 +436,10 @@ def main():
if args.only_import:
return
migrate_components=None
if args.migrate_components:
migrate_components=True
print("Connecting to %s" % bzurl)
if args.bz_user and args.bz_password:
bgo = bugzilla.Bugzilla(bzurl, args.bz_user, args.bz_password)
......@@ -466,7 +477,7 @@ def main():
#sys.stdout.write(' SKIPPED!')
#continue
processbug(bgo, bzurl, instance, bzresolution, target, user_cache,
milestone_cache, bzbug)
milestone_cache, bzbug, migrate_components)
if os.path.exists('users_cache'):
print('IMPORTANT: Remove the file \'users_cache\' after use, it \
......
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