From d1b630b5dab3132f6dfaaf6febd825e59a190f8c Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Mon, 17 Sep 2018 17:04:44 -0500 Subject: [PATCH] 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. --- ReviewBot.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ReviewBot.py b/ReviewBot.py index e66a9067..e1a42fe6 100644 --- a/ReviewBot.py +++ b/ReviewBot.py @@ -344,10 +344,7 @@ class ReviewBot(object): # Store in-case sub-classes need direct access to original values. self.action = a - fn = 'check_action_%s'%a.type - if not hasattr(self, fn): - fn = 'check_action__default' - func = getattr(self, fn) + func = getattr(self, self.action_method(a)) ret = func(req, a) # In the case of multiple actions take the "lowest" result where the @@ -359,6 +356,30 @@ class ReviewBot(object): 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 def _is_patchinfo(pkgname): return pkgname == 'patchinfo' or pkgname.startswith('patchinfo.')