mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: imrpove pseudo markdown
This commit is contained in:
parent
23e1b93465
commit
c8bdd4f31e
@ -133,6 +133,27 @@ def list_local_dbs(additionnal_conditions=None):
|
|||||||
""" % additionnal_condition_str)
|
""" % additionnal_condition_str)
|
||||||
return [d[0] for d in local_cr.fetchall()]
|
return [d[0] for d in local_cr.fetchall()]
|
||||||
|
|
||||||
|
def markdown_escape(text):
|
||||||
|
patterns = {
|
||||||
|
r'\*\*(.+?)\*\*': '\\*\\*\\g<1>\\*\\*',
|
||||||
|
r'~~(.+?)~~': '\\~\\~\\g<1>\\~\\~',
|
||||||
|
r'__(.+?)__': '\\_\\_\\g<1>\\_\\_',
|
||||||
|
}
|
||||||
|
|
||||||
|
for p, b in patterns.items():
|
||||||
|
text = re.sub(p, b, text, flags=re.DOTALL)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def markdown_unescape(text):
|
||||||
|
patterns = {
|
||||||
|
r'\\\*\\\*': '**',
|
||||||
|
r'\\\~\\\~': '~~',
|
||||||
|
r'\\\_\\\_': '__',
|
||||||
|
}
|
||||||
|
|
||||||
|
for p, b in patterns.items():
|
||||||
|
text = re.sub(p, b, text, flags=re.DOTALL)
|
||||||
|
return text
|
||||||
|
|
||||||
def pseudo_markdown(text):
|
def pseudo_markdown(text):
|
||||||
text = html_escape(text)
|
text = html_escape(text)
|
||||||
@ -166,7 +187,7 @@ def pseudo_markdown(text):
|
|||||||
return f'<code>{codes[int(match.group(1))]}</code>'
|
return f'<code>{codes[int(match.group(1))]}</code>'
|
||||||
|
|
||||||
text = Markup(re.sub(r'<code>(\d+)</code>', code_replace, text, flags=re.DOTALL))
|
text = Markup(re.sub(r'<code>(\d+)</code>', code_replace, text, flags=re.DOTALL))
|
||||||
return text
|
return markdown_unescape(text)
|
||||||
|
|
||||||
|
|
||||||
def _make_github_session(token):
|
def _make_github_session(token):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
|
from odoo.addons.runbot.common import markdown_escape
|
||||||
|
|
||||||
class ConfigStep(models.Model):
|
class ConfigStep(models.Model):
|
||||||
_inherit = 'runbot.build.config.step'
|
_inherit = 'runbot.build.config.step'
|
||||||
@ -124,10 +124,10 @@ class ConfigStep(models.Model):
|
|||||||
for file, file_reviewers in reviewer_per_file.items():
|
for file, file_reviewers in reviewer_per_file.items():
|
||||||
href = 'https://%s/blob/%s/%s' % (commit_link.branch_id.remote_id.base_url, commit_link.commit_id.name, file.split('/', 1)[-1])
|
href = 'https://%s/blob/%s/%s' % (commit_link.branch_id.remote_id.base_url, commit_link.commit_id.name, file.split('/', 1)[-1])
|
||||||
if file_reviewers:
|
if file_reviewers:
|
||||||
build._log('', 'Adding %s to reviewers for file [%s](%s)' % (', '.join(sorted(file_reviewers)), file, href), log_type='markdown')
|
build._log('', 'Adding %s to reviewers for file [%s](%s)' % (', '.join(sorted(file_reviewers)), markdown_escape(file), href), log_type='markdown')
|
||||||
reviewers |= file_reviewers
|
reviewers |= file_reviewers
|
||||||
else:
|
else:
|
||||||
build._log('', 'No reviewer for file [%s](%s)' % (file, href), log_type='markdown')
|
build._log('', 'No reviewer for file [%s](%s)' % (markdown_escape(file), href), log_type='markdown')
|
||||||
|
|
||||||
if reviewers:
|
if reviewers:
|
||||||
pr = pr_by_commit[commit_link]
|
pr = pr_by_commit[commit_link]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .common import RunbotCase
|
from .common import RunbotCase
|
||||||
|
from odoo.addons.runbot.common import markdown_escape
|
||||||
|
|
||||||
class TestIrLogging(RunbotCase):
|
class TestIrLogging(RunbotCase):
|
||||||
|
|
||||||
@ -60,6 +60,19 @@ class TestIrLogging(RunbotCase):
|
|||||||
'This <a href="https://wwww.somewhere.com">link</a> goes to somewhere and <a href="http://www.nowhere.com">this one</a> to nowhere.'
|
'This <a href="https://wwww.somewhere.com">link</a> goes to somewhere and <a href="http://www.nowhere.com">this one</a> to nowhere.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# test links with markdown like symbols
|
||||||
|
log.message = f'Adding validation to reviewers for file [{markdown_escape("foo/__init__.py")}](https://www.nowhere.com/)'
|
||||||
|
self.assertEqual(
|
||||||
|
log._markdown(),
|
||||||
|
'Adding validation to reviewers for file <a href="https://www.nowhere.com/">foo/__init__.py</a>'
|
||||||
|
)
|
||||||
|
|
||||||
|
log.message = f'~~{markdown_escape("foo/__init__.py")}~~'
|
||||||
|
self.assertEqual(
|
||||||
|
log._markdown(),
|
||||||
|
'<del>foo/__init__.py</del>'
|
||||||
|
)
|
||||||
|
|
||||||
# test link with icon
|
# test link with icon
|
||||||
log.message = '[@icon-download](https://wwww.somewhere.com) goes to somewhere.'
|
log.message = '[@icon-download](https://wwww.somewhere.com) goes to somewhere.'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user