From 2f8c02e9e0dba6e2721b6fe9c5a5b7d2b9ecc1cd Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 20 Mar 2020 14:40:01 +0100 Subject: [PATCH] Fix check_source for repository specific package names If the package name as reported by OBS does not match the one we're expecting, then loop through all repositories and check if we find one there. This is weakening the policy a little as this will open the door for false negatives - e.g. that got the right package name only for another repository. But as we do submission between code streams all the time, I can't limit the package parsing to repositories building against the target. So the opened hole is to be closed by sanity check on review-team - as a matter of fact the policy is not to catch people playing macro games around Name, but for people that use completely different names in source and target. Fixes #2274 --- check_source.py | 66 +++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/check_source.py b/check_source.py index 1423bfaa..671f57c4 100755 --- a/check_source.py +++ b/check_source.py @@ -70,6 +70,42 @@ class CheckSource(ReviewBot.ReviewBot): # It might make sense to supersede maintbot, but for now. self.skip_add_reviews = True + def is_good_name(self, package, target_package): + self.logger.debug(f"is_good_name {package} <-> {target_package}") + if target_package is None: + # if the name doesn't matter, existance is all + return package is not None + + return target_package == package + + def package_source_parse(self, project, package, revision=None, target_package=None): + ret = self._package_source_parse(project, package, revision) + + if self.is_good_name(ret['name'], target_package): + return ret + + d = {} + for repo in osc.core.get_repositories_of_project(self.apiurl, project): + r = self._package_source_parse(project, package, revision, repo) + if r['name'] is not None: + d[r['name']] = r + + if len(d) == 1: + # here is only one so use that + ret = d[next(iter(d))] + else: + # check if any name matches + self.logger.debug("found multiple names %s", ', '.join(d.keys())) + for n, r in d.items(): + if n == target_package: + ret = r + break + + if not self.is_good_name(ret['name'], target_package): + self.logger.error("none of the names matched") + + return ret + def check_source_submission(self, source_project, source_package, source_revision, target_project, target_package): super(CheckSource, self).check_source_submission(source_project, source_package, source_revision, target_project, target_package) self.target_project_config(target_project) @@ -149,7 +185,7 @@ class CheckSource(ReviewBot.ReviewBot): os.rename(source_package, target_package) shutil.rmtree(os.path.join(target_package, '.osc')) - new_info = self.package_source_parse(source_project, source_package, source_revision) + new_info = self.package_source_parse(source_project, source_package, source_revision, target_package) if not new_info.get('filename', '').endswith('.kiwi') and new_info['name'] != target_package: shutil.rmtree(dir) self.review_messages['declined'] = "A package submitted as %s has to build as 'Name: %s' - found Name '%s'" % (target_package, target_package, new_info['name']) @@ -312,34 +348,6 @@ class CheckSource(ReviewBot.ReviewBot): return ret - def package_source_parse(self, project, package, revision=None): - ret = self._package_source_parse(project, package, revision) - - if ret['name'] is not None: - return ret - - d = {} - for repo in osc.core.get_repositories_of_project(self.apiurl, project): - r = self._package_source_parse(project, package, revision, repo) - if r['name'] is not None: - d[r['name']] = r - - if len(d) == 1: - # here is only one so use that - ret = d[next(iter(d))] - else: - # check if any name matches - self.logger.debug("found multiple names %s", ', '.join(d.keys())) - for n, r in d.items(): - if n == package: - ret = r - break - - if ret['name'] is None: - self.logger.error("none of the names matched") - - return ret - def only_changes(self): u = osc.core.makeurl(self.apiurl, ['request', self.request.reqid], {'cmd': 'diff', 'view': 'xml'})