From 95536d558792a4c68028a5b8e303a8a846be5632 Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: May 04 2021 09:13:05 +0000 Subject: discussions: add component to the ticket title, reshuffle This makes ticket titles more readable, which helps in the Pagure's Issues view and also for email notifications. Fixes: https://pagure.io/fedora-qa/blockerbugs/issue/178 --- diff --git a/blockerbugs/config.py b/blockerbugs/config.py index 7170b3e..88487fc 100644 --- a/blockerbugs/config.py +++ b/blockerbugs/config.py @@ -58,7 +58,7 @@ class Config(object): PAGURE_BOT_USERNAME = 'blockerbot' PAGURE_BOT_ENABLED = True PAGURE_BOT_LOOP_THRESHOLD = 2 - PAGURE_DISCUSSION_TITLE = "rhbz#$bugid $summary" + PAGURE_DISCUSSION_TITLE = "[$component] $summary | rhbz#$bugid" PAGURE_DISCUSSION_CONTENT = '''\ Bug details: ** $bug_url ** Information from [BlockerBugs App]({}): diff --git a/blockerbugs/util/pagure_interface.py b/blockerbugs/util/pagure_interface.py index 5cbc31d..6d588bb 100644 --- a/blockerbugs/util/pagure_interface.py +++ b/blockerbugs/util/pagure_interface.py @@ -10,16 +10,8 @@ class PagureAPIException(Exception): def create_bug_discussion(bug): - title = Template(app.config['PAGURE_DISCUSSION_TITLE']).safe_substitute( - bugid=bug.bugid, - summary=bug.summary) - content = Template(app.config['PAGURE_DISCUSSION_CONTENT']).safe_substitute( - bugid=bug.bugid, - bug_img=app.config['BLOCKERBUGS_API'] + "bugimg/%s" % bug.bugid, - bug_url=bug.url, - vote_summary='Nobody voted yet.', - pagure_url=app.config['PAGURE_URL'], - pagure_repo=app.config['PAGURE_REPO'],) + title = render_discussion_template(app.config['PAGURE_DISCUSSION_TITLE'], bug) + content = render_discussion_template(app.config['PAGURE_DISCUSSION_CONTENT'], bug) return create_issue(title, content) @@ -33,17 +25,9 @@ def update_issue(issue_id, vote_summary): update_issue_url = app.config['PAGURE_API'] + app.config['PAGURE_REPO'] + '/issue/%s' % issue_id bug = issue_to_bug(issue_id) - bug_url = app.config['BUGZILLA_URL'] + "show_bug.cgi?id=%s" % bug.bugid - title = Template(app.config['PAGURE_DISCUSSION_TITLE']).safe_substitute( - bugid=bug.bugid, - summary=bug.summary) - content = Template(app.config['PAGURE_DISCUSSION_CONTENT']).safe_substitute( - bugid=bug.bugid, - bug_img=app.config['BLOCKERBUGS_API'] + "bugimg/%s" % bug.bugid, - bug_url=bug_url, - vote_summary=vote_summary, - pagure_url=app.config['PAGURE_URL'], - pagure_repo=app.config['PAGURE_REPO'],) + title = render_discussion_template(app.config['PAGURE_DISCUSSION_TITLE'], bug) + content = render_discussion_template(app.config['PAGURE_DISCUSSION_CONTENT'], + bug, vote_summary) data = { 'title': title, 'issue_content': content, @@ -159,3 +143,17 @@ def get_group(group): 'response text:\n%s' % (resp.status_code, resp.text)) return resp.json() + + +def render_discussion_template(template, bug, vote_summary='Nobody voted yet.'): + rendered = Template(template).substitute( + bug_img=f"{app.config['BLOCKERBUGS_API']}bugimg/{bug.bugid}", + bug_url=bug.url, + bugid=bug.bugid, + component=bug.component, + pagure_url=app.config['PAGURE_URL'], + pagure_repo=app.config['PAGURE_REPO'], + summary=bug.summary, + vote_summary=vote_summary, + ) + return rendered