Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace string interpolation with log arguments and f-strings #254

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions sync2jira/downstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def get_jira_client(issue, config):

if not isinstance(issue, Issue) and not isinstance(issue, PR):
log.error("passed in issue is not an Issue instance")
log.error("It is a %s" % type(issue).__name__)
raise TypeError("Got %s, expected Issue" % type(issue).__name__)
log.error("It is a %s", type(issue).__name__)
raise TypeError(f"Got {type(issue).__name__}, expected Issue")

# Use the Jira instance set in the issue config. If none then
# use the configured default jira instance.
Expand All @@ -137,9 +137,8 @@ def _matching_jira_issue_query(client, issue, config, free=False):
:rtype: List
"""
# Searches for any remote link to the issue.url
query = 'issueFunction in linkedIssuesOfRemote("%s") and ' \
'issueFunction in linkedIssuesOfRemote("%s")' % (
remote_link_title, issue.url)
query = (f'issueFunction in linkedIssuesOfRemote("{remote_link_title}") and '
f'issueFunction in linkedIssuesOfRemote("{issue.url}")')
if free:
query += ' and statusCategory != Done'
# Query the JIRA client and store the results
Expand Down Expand Up @@ -236,20 +235,20 @@ def alert_user_of_duplicate_issues(issue, final_result, results_of_query,

# Get owner name and email from Jira
ds_owner = issue.downstream.get('owner')
ds_owner = ds_owner.strip() if ds_owner else ds_owner
ret = client.search_users(ds_owner)
if len(ret) > 1:
log.warning('Found multiple users for username %s' % ds_owner)
log.warning('Found multiple users for username %s', ds_owner)
found = False
for person in ret:
if person.key == ds_owner:
ret = [person]
found = True
break
if not found:
log.warning('Could not find JIRA user for username %s' % ds_owner)
log.warning('Could not find JIRA user for username %s', ds_owner)
if not ret:
message = 'No owner could be found for username %s' % ds_owner
log.warning(message.strip())
log.warning('No owner could be found for username %s', ds_owner)
return

user = {'name': ret[0].displayName, 'email': ret[0].emailAddress}
Expand All @@ -265,18 +264,18 @@ def alert_user_of_duplicate_issues(issue, final_result, results_of_query,
admin_username = [name for name in admin][0]
ret = client.search_users(admin_username)
if len(ret) > 1:
log.warning('Found multiple users for admin %s' % list(admin.keys())[0])
log.warning('Found multiple users for admin %s', admin_username)
found = False
for person in ret:
if person.key == ds_owner:
ret = [person]
found = True
break
if not found:
log.warning('Could not find JIRA user for admin %s' % list(admin.keys())[0])
log.warning('Could not find JIRA user for admin %s', admin_username)
if not ret:
message = 'No admin could be found for username %s' % list(admin.keys())[0]
log.warning(message.strip())
message = f'No admin could be found for username {admin_username}'
log.warning(message)
raise ValueError(message)
admins.append(ret[0].emailAddress)
admin_template.append({'name': ret[0].displayName, 'email': ret[0].emailAddress})
Expand Down Expand Up @@ -417,7 +416,7 @@ def _get_existing_jira_issue_legacy(client, issue, config):
"""

kwargs = dict(issue.downstream.items())
kwargs["External issue URL"] = "%s" % issue.url
kwargs["External issue URL"] = str(issue.url)
kwargs = sorted(kwargs.items(), key=operator.itemgetter(0))

query = " AND ".join(
Expand Down Expand Up @@ -527,10 +526,9 @@ def assignee_fullname(issue):
owner = issue.downstream.get('owner')
if owner:
client.assign_issue(downstream.id, owner)
log.warning('Assigned %s to owner: %s' %
(issue.title, owner))
log.warning('Assigned %s to owner: %s', issue.title, owner)
return
log.warning('Was not able to assign user %s' % issue.assignee[0]['fullname'])
log.warning('Was not able to assign user %s', issue.assignee[0]['fullname'])


def change_status(client, downstream, status, issue):
Expand All @@ -552,11 +550,13 @@ def change_status(client, downstream, status, issue):
if id:
try:
client.transition_issue(downstream, id)
log.info('Updated downstream to %s status for issue %s' % (status, issue.title))
log.info('Updated downstream to %s status for issue %s',
status, issue.title)
except JIRAError:
log.error('Updating downstream issue failed for %s: %s' % (status, issue.title))
log.error('Updating downstream issue failed for %s: %s',
status, issue.title)
else:
log.warning('Could not update JIRA %s for %s' % (status, issue.title))
log.warning('Could not update JIRA %s for %s', status, issue.title)


def _get_preferred_issue_types(config, issue):
Expand Down Expand Up @@ -689,7 +689,8 @@ def _create_jira_issue(client, issue, config):
f"[{issue.upstream}-#{issue.upstream_id}|{issue.url}]"
client.add_comment(downstream, comment)
if len(preferred_types) > 1:
comment = 'Some labels look like issue types but were not considered: %s' % preferred_types[1:]
comment = ('Some labels look like issue types but were not considered:'
+ str({preferred_types[1:]}))
client.add_comment(downstream, comment)

remote_link = dict(url=issue.url, title=remote_link_title)
Expand Down Expand Up @@ -734,7 +735,7 @@ def _update_jira_issue(existing, issue, client, config):
"""
# Start with comments
# Only synchronize comments for listings that op-in
log.info("Updating information for upstream issue: %s" % issue.title)
log.info("Updating information for upstream issue: %s", issue.title)

# Get a list of what the user wants to update for the upstream issue
updates = issue.downstream.get('issue_updates', [])
Expand Down Expand Up @@ -793,7 +794,7 @@ def _update_jira_issue(existing, issue, client, config):
log.info("Attempting to update downstream issue on upstream closed event")
_update_on_close(existing, issue, updates)

log.info('Done updating %s!' % issue.title)
log.info('Done updating %s!', issue.title)


def _update_transition(client, existing, issue):
Expand Down Expand Up @@ -855,7 +856,7 @@ def _update_comments(client, existing, issue):
comment_body = _comment_format(comment)
client.add_comment(existing, comment_body)
if len(comments_d) > 0:
log.info("Comments synchronization done on %i comments." % len(comments_d))
log.info("Comments synchronization done on %i comments.", len(comments_d))


def _update_fixVersion(updates, existing, issue, client):
Expand Down Expand Up @@ -898,9 +899,10 @@ def _update_fixVersion(updates, existing, issue, client):
# If the fixVersion is not in JIRA, it will throw an error
try:
existing.update(data)
log.info('Updated %s fixVersion(s)' % len(fix_version))
log.info('Updated %s fixVersion(s)', len(fix_version))
except JIRAError:
log.warning('Error updating the fixVersion. %s is an invalid fixVersion.' % issue.fixVersion)
log.warning('Error updating the fixVersion. %s is an invalid fixVersion.',
issue.fixVersion)
# Add a comment to indicate there was an issue
client.add_comment(existing, f"Error updating fixVersion: {issue.fixVersion}")

Expand Down Expand Up @@ -963,7 +965,7 @@ def _update_jira_labels(issue, labels):

data = {'labels': _labels}
issue.update(data)
log.info('Updated %s tag(s)' % len(_labels))
log.info('Updated %s tag(s)', len(_labels))


def _update_github_project_fields(client, existing, issue,
Expand Down Expand Up @@ -1066,7 +1068,7 @@ def _build_description(issue):

if any('transition' in item for item in issue.downstream.get('issue_updates', {})):
# Just add it to the top of the description
formatted_status = "Upstream issue status: %s" % issue.status
formatted_status = "Upstream issue status: " + issue.status
description = formatted_status + '\n' + description

if issue.reporter:
Expand Down Expand Up @@ -1278,7 +1280,7 @@ def _close_as_duplicate(client, duplicate, keeper, config):
else:
log.exception("Failed to close %r", duplicate.permalink())
else:
log.warning("Unable to find close transition for %r" % duplicate.key)
log.warning("Unable to find close transition for %r", duplicate.key)


def close_duplicates(issue, config):
Expand Down
2 changes: 1 addition & 1 deletion sync2jira/intermediary.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def from_github(cls, upstream, issue, config):
)

def __repr__(self):
return "<Issue %s >" % self.url
return f"<Issue {self.url} >"


class PR(object):
Expand Down
4 changes: 2 additions & 2 deletions sync2jira/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def load_config(loader=fedmsg.config.load_config):
if not specified.issubset(possible):
message = "Specified handlers: %s, must be a subset of %s."
raise ValueError(message % (
", ".join(['"%s"' % item for item in specified]),
", ".join(['"%s"' % item for item in possible]),
", ".join(f'"{item}"' for item in specified),
", ".join(f'"{item}"' for item in possible),
))

if 'jira' not in config['sync2jira']:
Expand Down
Loading