runbot/runbot_cla/build_config.py
Xavier-Do 81fefee137 [FIX] runbot: fix coverage since shared sources
The requirements path and python version where defined from
server in cmd. Since in coverage we add a 'python' before server,
it is difficult to define which element of the cmd is the server.

A solution here is simply to define requirements install and
python version when building cmd since we have access to all
build/source informations. We also add python part in every
cases, and coverage params are now a _cmd python_params.

The _cmd method now returns a Command object instead of a
list, which behave has a list for the cmd part but also contains
a pres and posts list.

pres are requirement install, preparation, ...
cmd is the original cmd list, element can be append or added, this
will allow to keep existing python job without to much changes.
posts are post cmd commands, like coverage result making.

This commit also fix issue with create_job dependencies.
2019-07-16 12:06:09 +02:00

52 lines
1.8 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')])
def _run_step(self, build, log_path):
if self.job_type == 'cla_check':
return self._runbot_cla_check(build, log_path)
return super(Step, self)._run_step(build, log_path)
def _runbot_cla_check(self, build, log_path):
build._checkout()
cla_glob = glob.glob(build._get_server_commit()._source_path("doc/cla/*/*.md"))
if cla_glob:
description = "%s Odoo CLA signature check" % build.author
mo = re.search('[^ <@]+@[^ @>]+', build.author_email or '')
state = "failure"
if mo:
email = mo.group(0).lower()
if re.match('.*@(odoo|openerp|tinyerp)\.com$', email):
state = "success"
else:
try:
cla = ''.join(io.open(f, encoding='utf-8').read() for f in cla_glob)
if cla.lower().find(email) != -1:
state = "success"
except UnicodeDecodeError:
description = 'Invalid CLA encoding (must be utf-8)'
_logger.info('CLA build:%s email:%s result:%s', build.dest, email, state)
status = {
"state": state,
"target_url": "https://www.odoo.com/sign-cla",
"description": description,
"context": "legal/cla"
}
build._log('check_cla', 'CLA %s' % state)
build._github_status_notify_all(status)
# 0 is myself, -1 is everybody else, -2 nothing
return -2