diff --git a/dashboard/templates/blueprint_report.html b/dashboard/templates/blueprint_report.html index 2b274e1c3..602331ad6 100644 --- a/dashboard/templates/blueprint_report.html +++ b/dashboard/templates/blueprint_report.html @@ -28,6 +28,11 @@
Registered By: {{blueprint.author_name}} ({{ blueprint.company_name }})
Registered On: {{blueprint.date_str}}
+{% if blueprint.summary %} +

Summary

+
{{ blueprint.summary }}
+{% endif %} + {% if blueprint.whiteboard %}

Whiteboard

{{ blueprint.whiteboard }}
diff --git a/dashboard/web.py b/dashboard/web.py index bb5b4b01c..ac9f56962 100644 --- a/dashboard/web.py +++ b/dashboard/web.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import cgi import datetime import functools import json @@ -664,6 +663,7 @@ def get_activity_json(records): (record['record_type'] == 'bpc')): blueprint = record.copy() _extend_record(blueprint) + blueprint['summary'] = utils.format_text(record['summary']) if 'mention_date' in record: blueprint['mention_date_str'] = format_datetime( record['mention_date']) @@ -976,28 +976,11 @@ def make_link(title, uri=None, options=None): return '%(title)s' % {'uri': uri, 'title': title} -def unwrap_text(text): - res = '' - for line in text.splitlines(): - s = line.rstrip() - if not s: - continue - res += line - if (not s[0].isalpha()) or (s[-1] in ['.', '!', '?', '>', ':', ';']): - res += '\n' - else: - res += ' ' - return res.rstrip() - - -@app.template_filter('commit_message') def make_commit_message(record): s = record['message'] module = record['module'] - # clear text - s = cgi.escape(re.sub(re.compile('\n{2,}', flags=re.MULTILINE), '\n', s)) - s = re.sub(r'([/\/]+)', r'\1​', s) + s = utils.format_text(s) # insert links s = re.sub(re.compile('(blueprint\s+)([\w-]+)', flags=re.IGNORECASE), @@ -1010,7 +993,7 @@ def make_commit_message(record): r' \1', s) - s = unwrap_text(s) + s = utils.unwrap_text(s) return s diff --git a/stackalytics/processor/utils.py b/stackalytics/processor/utils.py index abb1b1648..280c01ecd 100644 --- a/stackalytics/processor/utils.py +++ b/stackalytics/processor/utils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import cgi import datetime import iso8601 import json @@ -87,3 +88,23 @@ def load_user(runtime_storage_inst, user_id): def load_repos(runtime_storage_inst): return runtime_storage_inst.get_by_key('repos') or [] + + +def unwrap_text(text): + res = '' + for line in text.splitlines(): + s = line.rstrip() + if not s: + continue + res += line + if (not s[0].isalpha()) or (s[-1] in ['.', '!', '?', '>', ':', ';']): + res += '\n' + else: + res += ' ' + return res.rstrip() + + +def format_text(s): + s = cgi.escape(re.sub(re.compile('\n{2,}', flags=re.MULTILINE), '\n', s)) + s = re.sub(r'([/\/]+)', r'\1​', s) + return s diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 6a59b3f65..200281540 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -50,3 +50,17 @@ class TestUtils(testtools.TestCase): def test_email_invalid(self): self.assertFalse(utils.check_email_validity('pupkin@localhost')) self.assertFalse(utils.check_email_validity('222@some.(trash)')) + + def test_unwrap(self): + original = 'Lorem ipsum. Dolor\nsit amet.\n Lorem\n ipsum.\ndolor!\n' + expected = 'Lorem ipsum. Dolor sit amet.\n Lorem\n ipsum.\ndolor!' + + self.assertEqual(expected, utils.unwrap_text(original)) + + def test_format_text_split_long_link(self): + original = ('https://blueprints.launchpad.net/stackalytics/+spec/' + 'stackalytics-core') + expected = ('https://​blueprints.launchpad.net/​' + 'stackalytics/​+spec/​stackalytics-core') + + self.assertEqual(expected, utils.format_text(original)) diff --git a/tests/unit/test_web_utils.py b/tests/unit/test_web_utils.py index 7a657d1da..f4bda8567 100644 --- a/tests/unit/test_web_utils.py +++ b/tests/unit/test_web_utils.py @@ -82,21 +82,6 @@ Implements Blueprint ''' + ( self.assertEqual(expected, observed, 'Commit message should be processed correctly') - def test_unwrap(self): - original = 'Lorem ipsum. Dolor\nsit amet.\n Lorem\n ipsum.\ndolor!\n' - expected = 'Lorem ipsum. Dolor sit amet.\n Lorem\n ipsum.\ndolor!' - - self.assertEqual(expected, web.unwrap_text(original)) - - def test_unwrap_split_long_link(self): - original = ('https://blueprints.launchpad.net/stackalytics/+spec/' - 'stackalytics-core') - expected = ('https://​blueprints.launchpad.net/​' - 'stackalytics/​+spec/​stackalytics-core') - - self.assertEqual(expected, web.make_commit_message( - {'message': original, 'module': 'none'})) - @mock.patch('dashboard.web.get_vault') @mock.patch('dashboard.web.get_user_from_runtime_storage') def test_make_page_title(self, user_patch, vault_patch):