From 56a6ecc5c0f10e41ffab49e72c69e4e299869c15 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mar 22 2019 20:41:46 +0000 Subject: Flake8. --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index 1a26e76..f09eceb 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -32,8 +32,11 @@ remote_link_title = "Upstream issue" jira_cache = {} + def _comment_format(comment): - return "Upstream, %s wrote:\n\n{quote}\n%s\n{quote}" % (comment['author'], comment['body']) + return "Upstream, %s wrote:\n\n{quote}\n%s\n{quote}" % ( + comment['author'], comment['body']) + def _get_jira_client(issue, config): @@ -70,6 +73,7 @@ def _matching_jira_issue_query(client, issue, config, free=False): log.debug("Found %i results for query %r", len(results), query) return results + def _find_comment_in_jira(comment, j_comments): formated_comment = _comment_format(comment) for item in j_comments: @@ -80,12 +84,13 @@ def _find_comment_in_jira(comment, j_comments): def _comment_matching(g_comments, j_comments): return list( - filter(lambda x: - _find_comment_in_jira(x, j_comments) == None or x['changed'] != None, + filter( + lambda x: _find_comment_in_jira(x, j_comments) is None or x['changed'] is not None, g_comments ) ) + def _get_existing_jira_issue(client, issue, config): """ Get a jira issue by the linked remote issue. @@ -254,16 +259,16 @@ def sync_with_jira(issue, config): log.info(" Looking for relative complement between downstream comments and upstream") comments_d = _comment_matching(issue.comments, comments) for comment in comments_d: - if comment['changed'] == None: + if comment['changed'] is None: comment_body = _comment_format(comment) client.add_comment(existing, comment_body) else: j_comment = find(lambda y: y.raw['body'] == _comment_format(comment), comments) comment_body = "%s wrote: %s" % (comment['author'], comment['changed']) - if j_comment == None: + if j_comment is None: client.add_comment(existing, comment_body) else: - j_comment.update(body = comment_body) + j_comment.update(body=comment_body) log.info(" Comments synchronization done.") log.info(" Found existing, matching downstream %r.", existing.key) return diff --git a/sync2jira/upstream.py b/sync2jira/upstream.py index 78d6275..e8c9767 100644 --- a/sync2jira/upstream.py +++ b/sync2jira/upstream.py @@ -152,6 +152,7 @@ def github_issues(upstream, config): for issue in issues: yield issue + def handle_github_comment(msg, config): owner = msg['msg']['repository']['owner']['login'] repo = msg['msg']['repository']['name'] @@ -180,6 +181,7 @@ def handle_github_comment(msg, config): c['changed'] = comment['body'] return i.Issue.from_github(upstream, issue, config) + def handle_pagure_comment(msg, config): upstream = msg['msg']['project']['name'] ns = msg['msg']['project'].get('namespace') or None @@ -194,6 +196,7 @@ def handle_pagure_comment(msg, config): issue = msg['msg']['issue'] return i.Issue.from_pagure(upstream, issue, config) + def _get_all_github_issues(url, headers): """ Pagination utility. Obnoxious. """ link = dict(next=url) @@ -205,16 +208,18 @@ def _get_all_github_issues(url, headers): yield issue link = _github_link_field_to_dict(response.headers.get('link', None)) + def _fetch_github_data(url, headers): response = requests.get(url, headers=headers) if not bool(response): try: reason = response.json() - except: + except Exception: reason = response.text raise IOError("response: %r %r %r" % (response, reason, response.request.url)) return response + def _github_link_field_to_dict(field): """ Utility for ripping apart github's Link header field. It's kind of ugly.