mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 15:35:46 +07:00

A common error on runbot is to generate link containing a __init__.py file [/some/path/to/__init__.py](/some/path/to/__init__.py) This would be rendered as <a href="/some/path/to/<ins>init<ins>.py">/some/path/to/<ins>init<ins>.py</a> Breaking the link, and the display of the name By default markdown will not render links avoiding this issue, but it will remain for the content of the a, needing to manage some kind of escaping. The way to escape markdown is to add a \ before any special character This must be done upront before formating, adding the method markdown_escape Our implementation of markdown is not meant to meet the exact specification of markdown but better suit our needs. One of the requirements is to be able to use it to format message easily but adding dynamic countent comming from the outside. One of the error than can occur is also 'Some code `%s`' % code can also cause problem if code contains ` This issue could be solved using indented code block, but this would need to complexify the generated string, have a dedicated method to escape the code blocs, ... Since we have the controll on the input, we can easily sanitize all ynamic content to avoid such issues. For code block we introduce a way to escape backtick (\`). It is non standard but will be easier to use. Combine with that, the build._log method now allows to add args with the values to format the string (similar to logging) but will escape params by default. (cr.execute spirit) name = '__init__.py' url = 'path/to/__init__.py' code = '# comment `for` something' build._log('f', 'Some message [%s](%s) \n `%s`', name, url, code) name, url and code will be escaped
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
# -*- encoding: utf-8 -*-
|
|
|
|
import glob
|
|
import io
|
|
import logging
|
|
import re
|
|
|
|
from odoo import models, fields
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Step(models.Model):
|
|
_inherit = "runbot.build.config.step"
|
|
|
|
job_type = fields.Selection(selection_add=[('cla_check', 'Check cla')], ondelete={'cla_check': 'cascade'})
|
|
|
|
def _run_cla_check(self, build):
|
|
build._checkout()
|
|
cla_glob = glob.glob(build._get_server_commit()._source_path("doc/cla/*/*.md"))
|
|
error = False
|
|
checked = set()
|
|
if cla_glob:
|
|
for commit in build.params_id.commit_ids:
|
|
email = commit.author_email
|
|
if email in checked:
|
|
continue
|
|
checked.add(email)
|
|
build._log('check_cla', "[Odoo CLA signature](https://www.odoo.com/sign-cla) check for %s (%s) ", commit.author, email, log_type='markdown')
|
|
mo = re.search('[^ <@]+@[^ @>]+', email or '')
|
|
if mo:
|
|
email = mo.group(0).lower()
|
|
if not re.match(r'.*@(odoo|openerp|tinyerp)\.com$', email):
|
|
try:
|
|
cla = ''.join(io.open(f, encoding='utf-8').read() for f in cla_glob)
|
|
if cla.lower().find(email) == -1:
|
|
error = True
|
|
build._log('check_cla', 'Email not found in cla file %s' % email, level="ERROR")
|
|
except UnicodeDecodeError:
|
|
error = True
|
|
build._log('check_cla', 'Invalid CLA encoding (must be utf-8)', level="ERROR")
|
|
else:
|
|
error = True
|
|
build._log('check_cla', 'Invalid email format %s' % email, level="ERROR")
|
|
else:
|
|
error = True
|
|
build._log('check_cla', "Missing cla file", level="ERROR")
|
|
|
|
if error:
|
|
build.local_result = 'ko'
|
|
elif not build.local_result:
|
|
build.local_result = 'ok'
|