From 55191625e83838f4a94a84abf33bd33f81d987cd Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 12 Jan 2018 15:30:12 -0600 Subject: [PATCH] osclib/request_splitter: rework quick strategy to handle Leap 15.0 workflow. The addition of factory-auto and repo-checker reviews need to be allowed since they are always present and do not constitute a non-quick review. In an attempt to future proof the strategy the allowed review groups are taken from the project configuration and repo-checker from config. --- osclib/request_splitter.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/osclib/request_splitter.py b/osclib/request_splitter.py index 6c7fe0a2..6742e953 100644 --- a/osclib/request_splitter.py +++ b/osclib/request_splitter.py @@ -3,6 +3,7 @@ import dateutil.parser import hashlib from lxml import etree as ET from osc import conf +from osc.core import show_project_meta import re class RequestSplitter(object): @@ -476,8 +477,37 @@ class StrategySuper(StrategyDevel): class StrategyQuick(StrategyNone): def apply(self, splitter): super(StrategyQuick, self).apply(splitter) + + # Leaper accepted which means any extra reviews have been added. splitter.filter_add('./review[@by_user="leaper" and @state="accepted"]') - splitter.filter_add('not(./review[not(@by_user="leaper" or @by_group="factory-staging")])') + + # No @by_project reviews that are not accepted. If not first round stage + # this should also ignore previous staging project reviews or already + # accepted human reviews. + splitter.filter_add('not(./review[@by_project and @state!="accepted"])') + + # Only allow reviews by whitelisted groups and users as all others will + # be considered non-quick (like @by_group="legal-auto"). The allowed + # groups are only those configured as reviewers on the target project. + meta = ET.fromstring(''.join(show_project_meta(splitter.api.apiurl, splitter.api.project))) + allowed_groups = meta.xpath('group[@role="reviewer"]/@groupid') + allowed_users = [] + if 'repo-checker' in splitter.config: + allowed_users.append(splitter.config['repo-checker']) + + self.filter_review_whitelist(splitter, 'by_group', allowed_groups) + self.filter_review_whitelist(splitter, 'by_user', allowed_users) + + def filter_review_whitelist(self, splitter, attribute, allowed): + # Rather than generate a bunch of @attribute="allowed[0]" pairs + # contains is used, but the attribute must be asserted first since + # concat() loses that requirement. + allowed = ' ' + ' '.join(allowed) + ' ' + splitter.filter_add( + # Assert that no(non-whitelisted and not accepted) review is found. + 'not(./review[@{attribute} and ' + 'not(contains("{allowed}", concat(" ", @{attribute}, " "))) and ' + '@state!="accepted"])'.format(attribute=attribute, allowed=allowed)) class StrategySpecial(StrategyNone): PACKAGES = [