From f00c1dc18bbd88738b8cf0849fca7eb63d72d3a1 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Aug 21 2018 21:40:15 +0000 Subject: Pylint. --- diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..00d81a5 --- /dev/null +++ b/pylintrc @@ -0,0 +1,2 @@ +[MESSAGES CONTROL] +disable=R,C,no-member,fixme,bare-except diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index c017b2a..fd7b008 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -39,7 +39,7 @@ def _matching_jira_issue_query(issue, config, free=False): if free: query += ' and status not in (Done, Dropped)' results = client.search_issues(query) - log.debug("Found %i results for query %r" % (len(results), query)) + log.debug("Found %i results for query %r", len(results), query) return results @@ -78,15 +78,14 @@ def get_existing_jira_issue_legacy(issue, config): def _attach_link(config, downstream, remote_link): - log.info(" Attaching tracking link %r to %r" % ( - remote_link, downstream.key)) + log.info(" Attaching tracking link %r to %r", remote_link, downstream.key) modified_desc = downstream.fields.description + " " client = jira.client.JIRA(**config['sync2jira']['jira']) # This is crazy. Querying for application links requires admin perms which # we don't have, so duckpunch the client to think it has already made the # query. - client._applicationlinks = [] # Crazy. + client._applicationlinks = [] # pylint: disable=protected-access # Add the link. client.add_remote_link(downstream.id, remote_link) @@ -94,7 +93,7 @@ def _attach_link(config, downstream, remote_link): # Finally, after we've added the link we have to edit the issue so that it # gets re-indexed, otherwise our searches won't work. Also, Handle some # weird API changes here... - log.debug(" Modifying desc of %r to trigger re-index." % downstream.key) + log.debug(" Modifying desc of %r to trigger re-index.", downstream.key) downstream.update({'description': modified_desc}) return downstream @@ -106,8 +105,7 @@ def upgrade_jira_issue(downstream, issue, config): Simply mark it with an external-url field value. """ - log.info(" Upgrading %r %r issue for %r" % ( - downstream.key, issue.downstream, issue)) + log.info(" Upgrading %r %r issue for %r", downstream.key, issue.downstream, issue) if config['sync2jira']['testing']: log.info(" Testing flag is true. Skipping actual upgrade.") return @@ -118,7 +116,7 @@ def upgrade_jira_issue(downstream, issue, config): def create_jira_issue(issue, config): - log.info(" Creating %r issue for %r" % (issue.downstream, issue)) + log.info(" Creating %r issue for %r", issue.downstream, issue) if config['sync2jira']['testing']: log.info(" Testing flag is true. Skipping actual creation.") return @@ -149,8 +147,7 @@ def create_jira_issue(issue, config): def close_as_duplicate(duplicate, keeper, config): - log.info(" Closing %s as duplicate of %s" % ( - duplicate.permalink(), keeper.permalink())) + log.info(" Closing %s as duplicate of %s", duplicate.permalink(), keeper.permalink()) client = jira.client.JIRA(**config['sync2jira']['jira']) if config['sync2jira']['testing']: log.info(" Testing flag is true. Skipping actual delete.") @@ -182,7 +179,7 @@ def close_as_duplicate(duplicate, keeper, config): try: client.transition_issue(duplicate, closed) except: - log.exception("Failed to close %r" % duplicate.permalink()) + log.exception("Failed to close %r", duplicate.permalink()) def close_duplicates(issue, config): @@ -206,7 +203,7 @@ def sync_with_jira(issue, config): log.info(" Looking for matching downstream issue via new method.") existing = get_existing_jira_issue(issue, config) if existing: - log.info(" Found existing, matching downstream %r." % existing.key) + log.info(" Found existing, matching downstream %r.", existing.key) return # If we're *not* configured to do legacy matching (upgrade mode) then there diff --git a/sync2jira/main.py b/sync2jira/main.py index 2720d8a..0fd08dc 100644 --- a/sync2jira/main.py +++ b/sync2jira/main.py @@ -83,17 +83,17 @@ def listen(config): for _, _, topic, msg in fedmsg.tail_messages(**config): idx = msg['msg_id'] suffix = ".".join(topic.split('.')[3:]) - log.debug("Encountered %r %r %r" % (suffix, topic, idx)) + log.debug("Encountered %r %r %r", suffix, topic, idx) if suffix not in handlers: continue - log.info("Handling %r %r %r" % (suffix, topic, idx)) + log.info("Handling %r %r %r", suffix, topic, idx) issue = handlers[suffix](msg, config) if not issue: - log.warn("%s, %s yielded no Issue object." % (suffix, idx)) + log.warning("%s, %s yielded no Issue object.", suffix, idx) continue d.sync_with_jira(issue, config) @@ -101,14 +101,14 @@ def listen(config): def initialize(config): log.info("Running initialization to sync all issues from upstream to jira") - log.info(" Testing flag is %r" % config['sync2jira']['testing']) + log.info(" Testing flag is %r", config['sync2jira']['testing']) mapping = config['sync2jira']['map'] for upstream in mapping.get('pagure', {}).keys(): for issue in u.pagure_issues(upstream, config): try: d.sync_with_jira(issue, config) except: - log.error("Failed on %r" % issue) + log.error("Failed on %r", issue) raise log.info("Done with pagure initialization.") @@ -117,7 +117,7 @@ def initialize(config): try: d.sync_with_jira(issue, config) except: - log.error("Failed on %r" % issue) + log.error("Failed on %r", issue) raise log.info("Done with github initialization.") @@ -153,7 +153,7 @@ def list_managed(): def close_duplicates(): config = load_config() logging.config.dictConfig(config['logging']) - log.info(" Testing flag is %r" % config['sync2jira']['testing']) + log.info(" Testing flag is %r", config['sync2jira']['testing']) mapping = config['sync2jira']['map'] warnings.simplefilter("ignore") @@ -162,7 +162,7 @@ def close_duplicates(): try: d.close_duplicates(issue, config) except: - log.error("Failed on %r" % issue) + log.error("Failed on %r", issue) raise log.info("Done with pagure duplicates.") @@ -171,7 +171,7 @@ def close_duplicates(): try: d.close_duplicates(issue, config) except: - log.error("Failed on %r" % issue) + log.error("Failed on %r", issue) raise log.info("Done with github duplicates.") diff --git a/sync2jira/upstream.py b/sync2jira/upstream.py index 0c90c21..31993be 100644 --- a/sync2jira/upstream.py +++ b/sync2jira/upstream.py @@ -42,26 +42,26 @@ def handle_github_message(msg, config): mapped_repos = config['sync2jira']['map']['github'] if upstream not in mapped_repos: - log.info("%r not in github map: %r" % (upstream, mapped_repos.keys())) + log.info("%r not in github map: %r", upstream, mapped_repos.keys()) return None - filter = config['sync2jira']\ + _filter = config['sync2jira']\ .get('filters', {})\ .get('github', {})\ .get(upstream, {'state': 'open'}) - for key, expected in filter.items(): + for key, expected in _filter.items(): # special handling for label: we look for it in the list of msg labels if key == 'labels': actual = [label['name'] for label in msg['msg']['issue']['labels']] if expected not in actual: - log.info("Label %s not set on issue" % expected) + log.info("Label %s not set on issue", expected) return None else: # direct comparison actual = msg['msg']['issue'].get(key) if actual != expected: - log.info("Actual %r %r != expected %r" % (key, actual, expected)) + log.info("Actual %r %r != expected %r", key, actual, expected) return None return i.Issue.from_github(upstream, msg['msg']['issue'], config) @@ -75,15 +75,15 @@ def handle_pagure_message(msg, config): mapped_repos = config['sync2jira']['map']['pagure'] if upstream not in mapped_repos: - log.info("%r not in pagure map: %r" % (upstream, mapped_repos.keys())) + log.info("%r not in pagure map: %r", upstream, mapped_repos.keys()) return None - filter = config['sync2jira']\ + _filter = config['sync2jira']\ .get('filters', {})\ .get('pagure', {})\ .get(upstream, {'status': 'Open'}) - for key, expected in filter.items(): + for key, expected in _filter.items(): # special handling for tag: we look for it in the list of msg tags if key == 'tags': actual = msg['msg']['issue'].get('tags', []) + msg['msg'].get('tags', []) @@ -95,13 +95,13 @@ def handle_pagure_message(msg, config): intersection = set(actual) & set(expected) if not intersection: - log.info("None of %r in %r on issue." % (expected, actual)) + log.info("None of %r in %r on issue.", expected, actual) return None else: # direct comparison actual = msg['msg']['issue'].get(key) if actual != expected: - log.info("Actual %r %r != expected %r" % (key, actual, expected)) + log.info("Actual %r %r != expected %r", key, actual, expected) return None return i.Issue.from_pagure(upstream, msg['msg']['issue'], config) @@ -137,12 +137,12 @@ def github_issues(upstream, config): else: headers = {'Authorization': 'token ' + token} - filter = config['sync2jira']\ + _filter = config['sync2jira']\ .get('filters', {})\ .get('github', {})\ .get(upstream, {'state': 'open'}) url = 'https://api.github.com/repos/%s/issues' % upstream - url += '?' + urlencode(filter) + url += '?' + urlencode(_filter) issues = _get_all_github_issues(url, headers) issues = list((