pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or .format(...), as well as unpacking of list comprehensions.
This commit is contained in:
parent
e27ac0ddbe
commit
9ce7c52a10
78 changed files with 356 additions and 389 deletions
|
@ -56,7 +56,7 @@ while len(json_implementations):
|
|||
|
||||
def make_api_call(path: str) -> Optional[List[Dict[str, Any]]]:
|
||||
response = requests.get(
|
||||
"https://api3.codebasehq.com/%s" % (path,),
|
||||
f"https://api3.codebasehq.com/{path}",
|
||||
auth=(config.CODEBASE_API_USERNAME, config.CODEBASE_API_KEY),
|
||||
params={"raw": "True"},
|
||||
headers={
|
||||
|
@ -76,13 +76,13 @@ def make_api_call(path: str) -> Optional[List[Dict[str, Any]]]:
|
|||
sys.exit(-1)
|
||||
else:
|
||||
logging.warn(
|
||||
"Found non-success response status code: %s %s" % (response.status_code, response.text)
|
||||
f"Found non-success response status code: {response.status_code} {response.text}"
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def make_url(path: str) -> str:
|
||||
return "%s/%s" % (config.CODEBASE_ROOT_URL, path)
|
||||
return f"{config.CODEBASE_ROOT_URL}/{path}"
|
||||
|
||||
|
||||
def handle_event(event: Dict[str, Any]) -> None:
|
||||
|
@ -102,11 +102,11 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
project_name = raw_props.get("name")
|
||||
project_repo_type = raw_props.get("scm_type")
|
||||
|
||||
url = make_url("projects/%s" % (project_link,))
|
||||
scm = "of type %s" % (project_repo_type,) if project_repo_type else ""
|
||||
url = make_url(f"projects/{project_link}")
|
||||
scm = f"of type {project_repo_type}" if project_repo_type else ""
|
||||
|
||||
subject = "Repository %s Created" % (project_name,)
|
||||
content = "%s created a new repository %s [%s](%s)" % (actor_name, scm, project_name, url)
|
||||
subject = f"Repository {project_name} Created"
|
||||
content = f"{actor_name} created a new repository {scm} [{project_name}]({url})"
|
||||
elif event_type == "push":
|
||||
stream = config.ZULIP_COMMITS_STREAM_NAME
|
||||
|
||||
|
@ -117,14 +117,14 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
deleted_ref = raw_props.get("deleted_ref")
|
||||
new_ref = raw_props.get("new_ref")
|
||||
|
||||
subject = "Push to %s on %s" % (branch, project)
|
||||
subject = f"Push to {branch} on {project}"
|
||||
|
||||
if deleted_ref:
|
||||
content = "%s deleted branch %s from %s" % (actor_name, branch, project)
|
||||
content = f"{actor_name} deleted branch {branch} from {project}"
|
||||
else:
|
||||
if new_ref:
|
||||
branch = "new branch %s" % (branch,)
|
||||
content = "%s pushed %s commit(s) to %s in project %s:\n\n" % (
|
||||
branch = f"new branch {branch}"
|
||||
content = "{} pushed {} commit(s) to {} in project {}:\n\n".format(
|
||||
actor_name,
|
||||
num_commits,
|
||||
branch,
|
||||
|
@ -132,11 +132,9 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
)
|
||||
for commit in raw_props.get("commits"):
|
||||
ref = commit.get("ref")
|
||||
url = make_url(
|
||||
"projects/%s/repositories/%s/commit/%s" % (project_link, repo_link, ref)
|
||||
)
|
||||
url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{ref}")
|
||||
message = commit.get("message")
|
||||
content += "* [%s](%s): %s\n" % (ref, url, message)
|
||||
content += f"* [{ref}]({url}): {message}\n"
|
||||
elif event_type == "ticketing_ticket":
|
||||
stream = config.ZULIP_TICKETS_STREAM_NAME
|
||||
|
||||
|
@ -144,11 +142,11 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
name = raw_props.get("subject")
|
||||
assignee = raw_props.get("assignee")
|
||||
priority = raw_props.get("priority")
|
||||
url = make_url("projects/%s/tickets/%s" % (project_link, num))
|
||||
url = make_url(f"projects/{project_link}/tickets/{num}")
|
||||
|
||||
if assignee is None:
|
||||
assignee = "no one"
|
||||
subject = "#%s: %s" % (num, name)
|
||||
subject = f"#{num}: {name}"
|
||||
content = (
|
||||
"""%s created a new ticket [#%s](%s) priority **%s** assigned to %s:\n\n~~~ quote\n %s"""
|
||||
% (actor_name, num, url, priority, assignee, name)
|
||||
|
@ -161,12 +159,12 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
body = raw_props.get("content")
|
||||
changes = raw_props.get("changes")
|
||||
|
||||
url = make_url("projects/%s/tickets/%s" % (project_link, num))
|
||||
subject = "#%s: %s" % (num, name)
|
||||
url = make_url(f"projects/{project_link}/tickets/{num}")
|
||||
subject = f"#{num}: {name}"
|
||||
|
||||
content = ""
|
||||
if body is not None and len(body) > 0:
|
||||
content = "%s added a comment to ticket [#%s](%s):\n\n~~~ quote\n%s\n\n" % (
|
||||
content = "{} added a comment to ticket [#{}]({}):\n\n~~~ quote\n{}\n\n".format(
|
||||
actor_name,
|
||||
num,
|
||||
url,
|
||||
|
@ -175,7 +173,7 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
|
||||
if "status_id" in changes:
|
||||
status_change = changes.get("status_id")
|
||||
content += "Status changed from **%s** to **%s**\n\n" % (
|
||||
content += "Status changed from **{}** to **{}**\n\n".format(
|
||||
status_change[0],
|
||||
status_change[1],
|
||||
)
|
||||
|
@ -184,10 +182,10 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
|
||||
name = raw_props.get("name")
|
||||
identifier = raw_props.get("identifier")
|
||||
url = make_url("projects/%s/milestone/%s" % (project_link, identifier))
|
||||
url = make_url(f"projects/{project_link}/milestone/{identifier}")
|
||||
|
||||
subject = name
|
||||
content = "%s created a new milestone [%s](%s)" % (actor_name, name, url)
|
||||
content = f"{actor_name} created a new milestone [{name}]({url})"
|
||||
elif event_type == "comment":
|
||||
stream = config.ZULIP_COMMITS_STREAM_NAME
|
||||
|
||||
|
@ -198,12 +196,10 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
if commit:
|
||||
repo_link = raw_props.get("repository_permalink")
|
||||
|
||||
url = make_url(
|
||||
"projects/%s/repositories/%s/commit/%s" % (project_link, repo_link, commit)
|
||||
)
|
||||
url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{commit}")
|
||||
|
||||
subject = "%s commented on %s" % (actor_name, commit)
|
||||
content = "%s commented on [%s](%s):\n\n~~~ quote\n%s" % (
|
||||
subject = f"{actor_name} commented on {commit}"
|
||||
content = "{} commented on [{}]({}):\n\n~~~ quote\n{}".format(
|
||||
actor_name,
|
||||
commit,
|
||||
url,
|
||||
|
@ -215,13 +211,13 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
category = raw_props.get("category")
|
||||
comment_content = raw_props.get("content")
|
||||
|
||||
subject = "Discussion: %s" % (subj,)
|
||||
subject = f"Discussion: {subj}"
|
||||
|
||||
if category:
|
||||
format_str = "%s started a new discussion in %s:\n\n~~~ quote\n%s\n~~~"
|
||||
content = format_str % (actor_name, category, comment_content)
|
||||
else:
|
||||
content = "%s posted:\n\n~~~ quote\n%s\n~~~" % (actor_name, comment_content)
|
||||
content = f"{actor_name} posted:\n\n~~~ quote\n{comment_content}\n~~~"
|
||||
|
||||
elif event_type == "deployment":
|
||||
stream = config.ZULIP_COMMITS_STREAM_NAME
|
||||
|
@ -233,19 +229,17 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
repo_link = raw_props.get("repository_permalink")
|
||||
|
||||
start_ref_url = make_url(
|
||||
"projects/%s/repositories/%s/commit/%s" % (project_link, repo_link, start_ref)
|
||||
)
|
||||
end_ref_url = make_url(
|
||||
"projects/%s/repositories/%s/commit/%s" % (project_link, repo_link, end_ref)
|
||||
f"projects/{project_link}/repositories/{repo_link}/commit/{start_ref}"
|
||||
)
|
||||
end_ref_url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{end_ref}")
|
||||
between_url = make_url(
|
||||
"projects/%s/repositories/%s/compare/%s...%s"
|
||||
% (project_link, repo_link, start_ref, end_ref)
|
||||
)
|
||||
|
||||
subject = "Deployment to %s" % (environment,)
|
||||
subject = f"Deployment to {environment}"
|
||||
|
||||
content = "%s deployed [%s](%s) [through](%s) [%s](%s) to the **%s** environment." % (
|
||||
content = "{} deployed [{}]({}) [through]({}) [{}]({}) to the **{}** environment.".format(
|
||||
actor_name,
|
||||
start_ref,
|
||||
start_ref_url,
|
||||
|
@ -256,7 +250,7 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
)
|
||||
if servers is not None:
|
||||
content += "\n\nServers deployed to: %s" % (
|
||||
", ".join(["`%s`" % (server,) for server in servers])
|
||||
", ".join(f"`{server}`" for server in servers)
|
||||
)
|
||||
|
||||
elif event_type == "named_tree":
|
||||
|
@ -270,7 +264,7 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
elif event_type == "sprint_ended":
|
||||
logging.warn("Sprint notifications not yet implemented")
|
||||
else:
|
||||
logging.info("Unknown event type %s, ignoring!" % (event_type,))
|
||||
logging.info(f"Unknown event type {event_type}, ignoring!")
|
||||
|
||||
if subject and content:
|
||||
if len(subject) > 60:
|
||||
|
@ -280,9 +274,9 @@ def handle_event(event: Dict[str, Any]) -> None:
|
|||
{"type": "stream", "to": stream, "subject": subject, "content": content}
|
||||
)
|
||||
if res["result"] == "success":
|
||||
logging.info("Successfully sent Zulip with id: %s" % (res["id"],))
|
||||
logging.info("Successfully sent Zulip with id: {}".format(res["id"]))
|
||||
else:
|
||||
logging.warn("Failed to send Zulip: %s %s" % (res["result"], res["msg"]))
|
||||
logging.warn("Failed to send Zulip: {} {}".format(res["result"], res["msg"]))
|
||||
|
||||
|
||||
# the main run loop for this mirror script
|
||||
|
@ -300,7 +294,7 @@ def run_mirror() -> None:
|
|||
else:
|
||||
since = datetime.fromtimestamp(float(timestamp), tz=pytz.utc)
|
||||
except (ValueError, OSError) as e:
|
||||
logging.warn("Could not open resume file: %s" % (str(e),))
|
||||
logging.warn(f"Could not open resume file: {str(e)}")
|
||||
since = default_since()
|
||||
|
||||
try:
|
||||
|
@ -339,9 +333,7 @@ def check_permissions() -> None:
|
|||
try:
|
||||
open(config.RESUME_FILE, "a+")
|
||||
except OSError as e:
|
||||
sys.stderr.write(
|
||||
"Could not open up the file %s for reading and writing" % (config.RESUME_FILE,)
|
||||
)
|
||||
sys.stderr.write(f"Could not open up the file {config.RESUME_FILE} for reading and writing")
|
||||
sys.stderr.write(str(e))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue