From d6628beadfc8edc4fb0b045ca7e5edbb91213404 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 18 Feb 2022 15:50:32 +0100 Subject: [PATCH] Target E125 - Continuation line with same indent https://www.flake8rules.com/rules/E125.html --- .flake8 | 2 +- ReviewBot.py | 38 +++++++++++++++++++++------------- check_maintenance_incidents.py | 4 ++-- metrics.py | 2 +- osclib/core.py | 6 +++--- osclib/origin.py | 6 +++--- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/.flake8 b/.flake8 index 9a3b63bf..11f24b14 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] exclude = abichecker max-line-length = 100 -ignore = W503,W504,E501,F401,E128,E251,E201,E202,E302,E305,F841,E261,E712,E126,E711,E125 +ignore = W503,W504,E501,F401,E128,E251,E201,E202,E302,E305,F841,E261,E712,E126,E711 diff --git a/ReviewBot.py b/ReviewBot.py index 15c338d0..10d6806c 100644 --- a/ReviewBot.py +++ b/ReviewBot.py @@ -310,6 +310,18 @@ class ReviewBot(object): else: self.logger.debug("%s review not changed" % (req.reqid)) + def _is_duplicate_review(self, review, query, allow_duplicate): + if review.by_group != query.get('by_group'): + return False + if review.by_project != query.get('by_project'): + return False + if review.by_package != query.get('by_package'): + return False + if review.by_user != query.get('by_user'): + return False + # Only duplicate when allow_duplicate and state != new. + return (not allow_duplicate or review.state == 'new') + # allow_duplicate=True should only be used if it makes sense to force a # re-review in a scenario where the bot adding the review will rerun. # Normally a declined review will automatically be reopened along with the @@ -331,13 +343,8 @@ class ReviewBot(object): else: raise osc.oscerr.WrongArgs("missing by_*") - for r in req.reviews: - if (r.by_group == by_group and - r.by_project == by_project and - r.by_package == by_package and - r.by_user == by_user and - # Only duplicate when allow_duplicate and state != new. - (not allow_duplicate or r.state == 'new')): + for review in req.reviews: + if self._is_duplicate_review(review, query, allow_duplicate): del query['cmd'] self.logger.debug('skipped adding duplicate review for {}'.format( '/'.join(query.values()))) @@ -736,13 +743,7 @@ class ReviewBot(object): message = self.comment_api.add_marker(message, bot_name, info) message = self.comment_api.truncate(message.strip()) - if (comment is not None and - ((identical and - # Remove marker from comments since handled during comment_find(). - self.comment_api.remove_marker(comment['comment']) == - self.comment_api.remove_marker(message)) or - (not identical and comment['comment'].count('\n') == message.count('\n'))) - ): + if self._is_comment_identical(comment, message, identical): # Assume same state/result and number of lines in message is duplicate. self.logger.debug('previous comment too similar on {}'.format(debug_key)) return @@ -764,6 +765,15 @@ class ReviewBot(object): self.comment_handler_remove() + def _is_comment_identical(self, comment, message, identical): + if comment is None: + return False + if identical: + # Remove marker from comments since handled during comment_find(). + return self.comment_api.remove_marker(comment['comment']) == self.comment_api.remove_marker(message) + else: + return comment['comment'].count('\n') == message.count('\n') + def _check_matching_srcmd5(self, project, package, rev, history_limit = 5): """check if factory sources contain the package and revision. check head and history""" self.logger.debug("checking %s in %s" % (package, project)) diff --git a/check_maintenance_incidents.py b/check_maintenance_incidents.py index 935fd191..0e0279f7 100755 --- a/check_maintenance_incidents.py +++ b/check_maintenance_incidents.py @@ -81,8 +81,8 @@ class MaintenanceChecker(ReviewBot.ReviewBot): origin = mapping[pkgname] self.logger.debug("{} comes from {}, submitted from {}".format(pkgname, origin, a.src_project)) if origin.startswith('SUSE:SLE-12') and a.src_project.startswith('SUSE:SLE-12') \ - or origin.startswith('SUSE:SLE-15') and a.src_project.startswith('SUSE:SLE-15') \ - or origin.startswith('openSUSE:Leap') and a.src_project.startswith('openSUSE:Leap'): + or origin.startswith('SUSE:SLE-15') and a.src_project.startswith('SUSE:SLE-15') \ + or origin.startswith('openSUSE:Leap') and a.src_project.startswith('openSUSE:Leap'): self.logger.info("{} submitted from {}, no maintainer review needed".format(pkgname, a.src_project)) return diff --git a/metrics.py b/metrics.py index 87c2184a..5a496afe 100755 --- a/metrics.py +++ b/metrics.py @@ -158,7 +158,7 @@ def ingest_requests(api, project): # Staging related reviews. for number, review in enumerate( - request.xpath('review[contains(@by_project, "{}:Staging:")]'.format(project)), start=1): + request.xpath('review[contains(@by_project, "{}:Staging:")]'.format(project)), start=1): staged_at = date_parse(review.get('when')) project_type = 'adi' if api.is_adi_project(review.get('by_project')) else 'letter' diff --git a/osclib/core.py b/osclib/core.py index f099a123..fe1ca2c1 100644 --- a/osclib/core.py +++ b/osclib/core.py @@ -1035,7 +1035,7 @@ def request_create_submit(apiurl, source_project, source_package, return False for request, action in request_action_list( - apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['submit']): + apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['submit']): if ignore_if_any_request: return False if not supersede and request.state.name in ('new', 'review'): @@ -1061,7 +1061,7 @@ def request_create_submit(apiurl, source_project, source_package, def request_create_delete(apiurl, target_project, target_package, message=None): for request, action in request_action_list( - apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['delete']): + apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['delete']): return False # No proper API function to perform the same operation. @@ -1078,7 +1078,7 @@ def request_create_change_devel(apiurl, source_project, source_package, target_package = source_package for request, action in request_action_list( - apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['change_devel']): + apiurl, target_project, target_package, REQUEST_STATES_MINUS_ACCEPTED, ['change_devel']): return False message = message_suffix('created', message) diff --git a/osclib/origin.py b/osclib/origin.py index 7e84faef..0c57b592 100644 --- a/osclib/origin.py +++ b/osclib/origin.py @@ -170,7 +170,7 @@ def config_resolve_variable(value, config_project, key='config'): def config_origin_list(config, apiurl=None, project=None, package=None, skip_workarounds=False): origin_list = [] for origin, values in config_origin_generator( - config['origins'], apiurl, project, package, skip_workarounds): + config['origins'], apiurl, project, package, skip_workarounds): origin_list.append(origin) return origin_list @@ -266,7 +266,7 @@ def origin_find(apiurl, target_project, package, source_hash=None, current=False def project_source_contain(apiurl, project, package, source_hash): for source_hash_consider in package_source_hash_history( - apiurl, project, package, include_project_link=True): + apiurl, project, package, include_project_link=True): project_source_log('contain', project, source_hash_consider, source_hash) if source_hash_consider == source_hash: return True @@ -314,7 +314,7 @@ def origin_find_fallback(apiurl, target_project, package, source_hash, user): # Attempt to find a revision of target package that matches an origin. first = True for source_hash_consider in package_source_hash_history( - apiurl, target_project, package, include_project_link=True): + apiurl, target_project, package, include_project_link=True): if first: first = False continue