Commit 2eb7568a authored by Daniel Stone's avatar Daniel Stone
Browse files

Add support for freedesktop.org services

parent 3275233b
......@@ -55,7 +55,8 @@ COMPONENT_MAP = {
}
def processbug(bgo, target, user_cache, milestone_cache, bzbug):
def processbug(bgo, bzurl, instance, resolution, target, user_cache,
milestone_cache, bzbug):
print("Processing bug #%d: %s" % (bzbug.id, bzbug.summary))
# bzbug.cc
# bzbug.id
......@@ -218,7 +219,7 @@ def processbug(bgo, target, user_cache, milestone_cache, bzbug):
comments = comments[1:]
description = \
template.render_issue_description(bzbug, desctext, user_cache)
template.render_issue_description(bzurl, bzbug, desctext, user_cache)
labels = ['bugzilla']
if bzbug.status == 'NEEDINFO':
......@@ -278,8 +279,8 @@ def processbug(bgo, target, user_cache, milestone_cache, bzbug):
author = user_cache[comment['creator']].display_name()
else:
author = comment['creator']
gitlab_comment = template.render_comment(emoji, author, action, body,
comment_attachment)
gitlab_comment = template.render_comment(bzurl, emoji, author, action,
body, comment_attachment)
issue.notes.create({
'body': gitlab_comment,
......@@ -316,9 +317,9 @@ def processbug(bgo, target, user_cache, milestone_cache, bzbug):
print("Adding a comment in bugzilla and closing the bug there")
# TODO: Create a resolution for this specific case? MIGRATED or FWDED?
bz.update_bugs(bzbug.bug_id, bz.build_update(
comment=template.render_bugzilla_migration_comment(issue),
comment=template.render_bugzilla_migration_comment(instance, issue),
status='RESOLVED',
resolution='OBSOLETE'))
resolution=resolution))
def options():
......@@ -346,6 +347,8 @@ def options():
help="project name for gitlab, like \
'username/project'. If not provided, \
$user_namespace/$bugzilla_product will be used")
parser.add_argument('--fdo', action='store_true',
help="import for freedesktop.org rather than GNOME")
return parser.parse_args()
......@@ -364,12 +367,25 @@ def check_if_target_project_exists(target):
def main():
args = options()
if args.production:
glurl = "https://gitlab.gnome.org/"
if args.fdo:
if args.production:
glurl = "https://gitlab.freedesktop.org/"
else:
glurl = "http://localhost:8080/"
bzurl = "https://bugs.freedesktop.org"
giturl = "https://anongit.freedesktop.org/git/"
instance = "freedesktop.org"
bzresolution = 'MOVED'
else:
glurl = "https://gitlab-test.gnome.org/"
bzurl = "https://bugzilla.gnome.org/"
giturl = "https://git.gnome.org/browse/"
if args.production:
glurl = "https://gitlab.gnome.org/"
else:
glurl = "https://gitlab-test.gnome.org/"
bzurl = "https://bugzilla.gnome.org"
giturl = "https://git.gnome.org/browse/"
instance = "GNOME"
bzresolution = 'OBSOLETE'
target = common.GitLab(glurl, giturl, args.token, args.product,
args.target_project, args.automate)
......@@ -414,7 +430,8 @@ def main():
for bzbug in bzbugs:
count += 1
sys.stdout.write('[{}/{}] '.format(count, len(bzbugs)))
processbug(bgo, target, user_cache, milestone_cache, bzbug)
processbug(bgo, bzurl, instance, bzresolution, target, user_cache,
milestone_cache, bzbug)
if os.path.exists('users_cache'):
print('IMPORTANT: Remove the file \'users_cache\' after use, it \
......
......@@ -33,21 +33,23 @@ ATTACHMENT_TEMPLATE = """ \n\
MIGR_TEMPLATE = """-- GitLab Migration Automatic Message --
This bug has been migrated to GNOME's GitLab instance and has been closed \
from further activity.
This bug has been migrated to {instance}'s GitLab instance and has been \
closed from further activity.
You can subscribe and participate further through the new bug through this \
link to our GitLab instance: {}.
link to our GitLab instance: {gitlab_url}.
"""
def _bugzilla_url(bugid):
return 'https://bugzilla.gnome.org/show_bug.cgi?id={}'.format(bugid)
def _bugzilla_url(instance_base, bugid):
url = '{instance_base}/show_bug.cgi?id={bugid}'
return url.format(instance_base=instance_base, bugid=bugid)
def _autolink_markdown(text):
def _autolink_markdown(instance_base, text):
text = re.sub(r'([Bb]ug) ([0-9]+)',
'[\\1 \\2]({})'.format(_bugzilla_url('\\2')), text)
'[\\1 \\2]({})'.format(_bugzilla_url(instance_base, '\\2')),
text)
# Prevent spurious links to other GitLab issues
text = re.sub(r'([Cc]omment) #([0-9]+)', '\\1 \\2', text)
# Quote stack traces as preformatted text
......@@ -81,11 +83,12 @@ def _body_to_markdown_quote(body):
def render_issue_description(
bug, text, user_cache,
importing_address="https://bugzilla.gnome.org/show_bug.cgi?id=",
instance_base, bug, text, user_cache, importing_address=None,
bug_url_function=_bugzilla_url):
if not text:
text = ""
if not importing_address:
importing_address = "{}/show_bug.cgi?id=".format(instance_base)
assigned_to = ""
assignee = user_cache[bug.assigned_to]
......@@ -96,14 +99,17 @@ def render_issue_description(
if bug.depends_on:
deps += "### Depends on\n"
for bugid in bug.depends_on:
deps += " * [Bug {}]({})\n".format(bugid, bug_url_function(bugid))
deps += " * [Bug {}]({})\n".format(bugid,
bug_url_function(instance_base,
bugid))
blocks = ""
if bug.blocks:
blocks += "### Blocking\n"
for bugid in bug.blocks:
blocks += " * [Bug {}]({})\n".format(bugid,
bug_url_function(bugid))
bug_url_function(instance_base,
bugid))
see_also = ""
if bug.see_also:
......@@ -117,6 +123,7 @@ def render_issue_description(
pass
else:
ids = query.get('id', [])
# XXX
if bug_url.netloc == 'bugzilla.gnome.org' and ids:
is_bz = True
see_also += " * [Bug {}]({})\n".format(ids[0], url)
......@@ -128,7 +135,7 @@ def render_issue_description(
blocks=blocks,
see_also=see_also)
if bug_url_function == _bugzilla_url:
body = _autolink_markdown(text)
body = _autolink_markdown(instance_base, text)
else:
body = text
......@@ -147,15 +154,15 @@ def render_issue_description(
dependencies=dependencies)
def render_bugzilla_migration_comment(gl_issue):
return MIGR_TEMPLATE.format(gl_issue.web_url)
def render_bugzilla_migration_comment(instance, gl_issue):
return MIGR_TEMPLATE.format(instance=instance, gitlab_url=gl_issue.web_url)
def render_comment(emoji, author, action, body, attachment,
def render_comment(instance_base, emoji, author, action, body, attachment,
bug_url_function=_bugzilla_url):
if bug_url_function == _bugzilla_url and body:
body = _autolink_markdown(body)
body = _autolink_markdown(instance_base, body)
body = _body_to_markdown_quote(body)
......
......@@ -34,7 +34,8 @@ def test_update_content():
54321: issue_dep,
}
bztogl.update_content(bz, gl, user_cache, issues, issue, bug)
bztogl.update_content(bz, "https://bugzilla.gnome.org", gl, user_cache,
issues, issue, bug)
assert 'first comment' in issue.description
assert '#{}'.format(issue_dep.iid) in issue.description
......@@ -52,7 +53,7 @@ def test_close_bug():
bug = Bug(12345, bz)
issue = Issue()
bztogl.close_bug(bug, issue)
bztogl.close_bug("GNOME", bug, issue, "OBSOLETE")
class Bugzilla:
......
......@@ -2,6 +2,7 @@ import collections
from bztogl import template
BZURL = "https://bugzilla.gnome.org"
Bug = collections.namedtuple(
'Bug', 'id creator assigned_to blocks depends_on see_also version'
......@@ -9,12 +10,17 @@ Bug = collections.namedtuple(
def test_bugzilla_url():
url = template._bugzilla_url(123456)
url = template._bugzilla_url(BZURL, 123456)
assert url == 'https://bugzilla.gnome.org/show_bug.cgi?id=123456'
<<<<<<< HEAD
def _check_processed_markdown(input, expected):
processed_text = template._autolink_markdown(input)
=======
def _check_processed_markdown(input, expected, migrated_issues={}):
processed_text = template._autolink_markdown(BZURL, input, migrated_issues)
>>>>>>> 7d151cc... Add support for freedesktop.org services
assert processed_text == expected
......@@ -34,7 +40,12 @@ def test_spurious_gitlab_comment_links_are_removed():
def test_bug_without_creator_is_handled():
bug = Bug(712869, 'geary-maint@gnome.bugs', '', None, None, None, None)
user_cache = collections.defaultdict(lambda: None)
<<<<<<< HEAD
template.render_issue_description(bug, 'Text body', user_cache)
=======
template.render_issue_description(BZURL, bug, 'Text body',
migrated_issues, user_cache)
>>>>>>> 7d151cc... Add support for freedesktop.org services
def test_stack_traces_are_quoted():
......@@ -89,7 +100,13 @@ Here's another one.
def test_empty_version():
bug = Bug(712869, 'geary-maint@gnome.bugs', '', None, None, [], None)
user_cache = collections.defaultdict(lambda: None)
<<<<<<< HEAD
description = template.render_issue_description(bug,
=======
migrated_issues = {}
description = template.render_issue_description(BZURL,
bug,
>>>>>>> 7d151cc... Add support for freedesktop.org services
'Text body',
user_cache)
assert 'Version:' not in description
......@@ -98,7 +115,13 @@ def test_empty_version():
def test_master_version():
bug = Bug(712869, 'geary-maint@gnome.bugs', '', None, None, [], 'master')
user_cache = collections.defaultdict(lambda: None)
<<<<<<< HEAD
description = template.render_issue_description(bug,
=======
migrated_issues = {}
description = template.render_issue_description(BZURL,
bug,
>>>>>>> 7d151cc... Add support for freedesktop.org services
'Text body',
user_cache)
assert 'Version:' not in description
......@@ -107,12 +130,19 @@ def test_master_version():
def test_other_version():
bug = Bug(712869, 'geary-maint@gnome.bugs', '', None, None, [], '1.0')
user_cache = collections.defaultdict(lambda: None)
<<<<<<< HEAD
description = template.render_issue_description(bug,
'Text body',
=======
migrated_issues = {}
description = template.render_issue_description(BZURL, bug, 'Text body',
migrated_issues,
>>>>>>> 7d151cc... Add support for freedesktop.org services
user_cache)
assert 'Version: 1.0' in description
<<<<<<< HEAD
def test_no_see_also():
bug = Bug(712869, 'geary-maint@gnome.bugs', '', None, None, None, None)
user_cache = collections.defaultdict(lambda: None)
......@@ -128,12 +158,106 @@ def test_empty_see_also():
description = template.render_issue_description(bug,
'Text body',
user_cache)
=======
def test_no_relations():
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, None, None, None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Blocking' not in description
assert 'Depends on' not in description
assert 'See also' not in description
def test_empty_blocks():
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
[], None, None, None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Blocking' not in description
def test_bz_blocks():
block_id = '792388'
block_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
[block_id], None, None, None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Blocking' in description
assert 'Bug 792388' in description
assert block_url in description
def test_migrated_blocks():
block_id = 792388
block_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
[block_id], None, None, None)
issues = {
792388: Issue(1234)
}
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Blocking' in description
assert '#1234' in description
assert block_url not in description
def test_empty_depends_on():
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, [], None, None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Depends on' not in description
def test_bz_depends_on():
depends_id = '792388'
depends_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, [depends_id], None, None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Depends on' in description
assert 'Bug 792388' in description
assert depends_url in description
def test_migrated_depends_on():
depends_id = 792388
depends_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, [depends_id], None, None)
issues = {
792388: Issue(1234)
}
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'Depends on' in description
assert '#1234' in description
assert depends_url not in description
def test_empty_see_also():
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, None, [], None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
>>>>>>> 7d151cc... Add support for freedesktop.org services
assert 'See also' not in description
def test_bz_see_also():
bug_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
<<<<<<< HEAD
None, None, [bug_url], None)
user_cache = collections.defaultdict(lambda: None)
description = template.render_issue_description(bug,
......@@ -142,15 +266,45 @@ def test_bz_see_also():
assert 'See also' in description
assert 'Bug 792388' in description
assert bug_url in description
=======
None, None, [see_also_url], None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'See also' in description
assert 'Bug 792388' in description
assert see_also_url in description
def test_migrated_see_also():
see_also_url = 'https://bugzilla.gnome.org/show_bug.cgi?id=792388'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
None, None, [see_also_url], None)
issues = {
792388: Issue(1234)
}
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
assert 'See also' in description
assert '#1234' in description
assert see_also_url not in description
>>>>>>> 7d151cc... Add support for freedesktop.org services
def test_bogus_see_also():
bug_url = 'my hovercraft is full of eels'
bug = Bug(712869, 'geary-maint@gnome.bugs', '',
<<<<<<< HEAD
None, None, [bug_url], None)
user_cache = collections.defaultdict(lambda: None)
description = template.render_issue_description(bug,
'Text body',
user_cache)
=======
None, None, [see_also_url], None)
issues = collections.defaultdict(lambda: None)
description = template.render_issue_relations(BZURL, bug, 'Text body',
issues)
>>>>>>> 7d151cc... Add support for freedesktop.org services
assert 'See also' in description
assert bug_url in description
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