ReviewBot: break down sub-types of delete requests.

Their is very little overlap in the types of reviews one typically wants
to perform on delete requests. Already all of the existing code will crash
if a delete project request is reviewed.
This commit is contained in:
Jimmy Berry 2018-09-17 17:04:44 -05:00
parent 628c1a107d
commit d1b630b5da

View File

@ -344,10 +344,7 @@ class ReviewBot(object):
# Store in-case sub-classes need direct access to original values. # Store in-case sub-classes need direct access to original values.
self.action = a self.action = a
fn = 'check_action_%s'%a.type func = getattr(self, self.action_method(a))
if not hasattr(self, fn):
fn = 'check_action__default'
func = getattr(self, fn)
ret = func(req, a) ret = func(req, a)
# In the case of multiple actions take the "lowest" result where the # In the case of multiple actions take the "lowest" result where the
@ -359,6 +356,30 @@ class ReviewBot(object):
return overall return overall
def action_method(self, action):
method_prefix = 'check_action'
method_type = action.type
method_suffix = None
if method_type == 'delete':
method_suffix = 'project'
if action.tgt_package is not None:
method_suffix = 'package'
elif action.tgt_repository is not None:
method_suffix = 'repository'
if method_suffix:
method = '_'.join([method_prefix, method_type, method_suffix])
if hasattr(self, method):
return method
method = '_'.join([method_prefix, method_type])
if hasattr(self, method):
return method
method_type = '_default'
return '_'.join([method_prefix, method_type])
@staticmethod @staticmethod
def _is_patchinfo(pkgname): def _is_patchinfo(pkgname):
return pkgname == 'patchinfo' or pkgname.startswith('patchinfo.') return pkgname == 'patchinfo' or pkgname.startswith('patchinfo.')