mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[FIX] runbot_merge: make github_login case insensitive
Rather than try to fix up various bits where we search & all and wonder what index we should be using, make the column a CIText. For mergebot the main use case would be properly handling delegate=XXX: currently if XXX is not a case-sensitive match we're going to create a new partner with the new github login and give *them* delegation, and the intended target of the delegation isn't going to work correctly. Also try to install the citext extension if it's not in the database, and run the database-creation process with `check=True` so if that fails we properly bubble up the error and don't try to run tests on a corrupted / broken DB. Fixes #318
This commit is contained in:
parent
742e3219a6
commit
b96bc9a58c
@ -248,7 +248,7 @@ class DbDict(dict):
|
||||
'-d', db, '-i', module,
|
||||
'--max-cron-threads', '0',
|
||||
'--stop-after-init'
|
||||
])
|
||||
], check=True)
|
||||
self[module] = db
|
||||
return db
|
||||
|
||||
|
@ -33,3 +33,11 @@ def enable_sentry():
|
||||
logger.exception("DSN found, failed to enable sentry...")
|
||||
else:
|
||||
logger.info("DSN found, sentry enabled...")
|
||||
|
||||
def _check_citext(cr):
|
||||
cr.execute("select 1 from pg_extension where extname = 'citext'")
|
||||
if not cr.rowcount:
|
||||
try:
|
||||
cr.execute('create extension citext')
|
||||
except Exception:
|
||||
raise AssertionError("runbot_merge needs the citext extension")
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': 'merge bot',
|
||||
'version': '1.2',
|
||||
'version': '1.3',
|
||||
'depends': ['contacts', 'website'],
|
||||
'data': [
|
||||
'security/security.xml',
|
||||
@ -12,4 +12,5 @@
|
||||
'views/templates.xml',
|
||||
],
|
||||
'post_load': 'enable_sentry',
|
||||
'pre_init_hook': '_check_citext',
|
||||
}
|
||||
|
2
runbot_merge/migrations/13.0.1.3/pre-migration.py
Normal file
2
runbot_merge/migrations/13.0.1.3/pre-migration.py
Normal file
@ -0,0 +1,2 @@
|
||||
def migrate(cr, version):
|
||||
cr.execute("DROP INDEX runbot_merge_unique_gh_login")
|
@ -1,10 +1,15 @@
|
||||
from email.utils import parseaddr
|
||||
from odoo import fields, models, tools, api
|
||||
|
||||
class CIText(fields.Char):
|
||||
type = 'char'
|
||||
column_type = ('citext', 'citext')
|
||||
column_cast_from = ('varchar', 'text')
|
||||
|
||||
class Partner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
github_login = fields.Char()
|
||||
github_login = CIText()
|
||||
delegate_reviewer = fields.Many2many('runbot_merge.pull_requests')
|
||||
formatted_email = fields.Char(string="commit email", compute='_rfc5322_formatted')
|
||||
review_rights = fields.One2many('res.partner.review', 'partner_id')
|
||||
|
@ -2625,10 +2625,14 @@ class TestReviewing(object):
|
||||
prx = repo.make_pr(title='title', body='body', target='master', head=c1)
|
||||
repo.post_status(prx.head, 'success', 'legal/cla')
|
||||
repo.post_status(prx.head, 'success', 'ci/runbot')
|
||||
prx.post_comment('hansen delegate=%s' % users['other'], config['role_reviewer']['token'])
|
||||
prx.post_comment('hansen r+', config['role_user']['token'])
|
||||
# flip case to check that github login is case-insensitive
|
||||
other = ''.join(c.lower() if c.isupper() else c.upper() for c in users['other'])
|
||||
prx.post_comment('hansen delegate=%s' % other, config['role_reviewer']['token'])
|
||||
env.run_crons()
|
||||
|
||||
with repo:
|
||||
# check this is ignored
|
||||
prx.post_comment('hansen r+', config['role_user']['token'])
|
||||
assert prx.user == users['user']
|
||||
assert env['runbot_merge.pull_requests'].search([
|
||||
('repository.name', '=', repo.name),
|
||||
@ -2636,6 +2640,7 @@ class TestReviewing(object):
|
||||
]).state == 'validated'
|
||||
|
||||
with repo:
|
||||
# check this works
|
||||
prx.post_comment('hansen r+', config['role_other']['token'])
|
||||
assert env['runbot_merge.pull_requests'].search([
|
||||
('repository.name', '=', repo.name),
|
||||
|
Loading…
Reference in New Issue
Block a user