Skip to content

Commit ad2a26f

Browse files
committed
Use OSC 8 terminal links and refactor
1 parent 0e110c2 commit ad2a26f

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

issues_by_dev.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Find number of open CPython issues per core dev.
2+
Find number of open issues/PRs in the Python org team.
33
"""
44

55
# /// script
@@ -60,6 +60,18 @@ def check_issues(author: str | None = None) -> Author:
6060
return Author(issues, prs)
6161

6262

63+
def markdown_link(url: str, text: str | int) -> str:
64+
return f"[{text}]({url})"
65+
66+
67+
def terminal_link(url: str, text: str | int) -> str:
68+
return f"\033]8;;{url}\033\\{text}\033]8;;\033\\"
69+
70+
71+
def no_link(url: str, text: str | int) -> str:
72+
return str(text)
73+
74+
6375
def main() -> None:
6476
parser = argparse.ArgumentParser(
6577
description=__doc__,
@@ -107,10 +119,9 @@ def main() -> None:
107119
field_names = ["", "Author", "Issues", "PRs", "Total"]
108120
if args.markdown:
109121
table.set_style(TableStyle.MARKDOWN)
110-
elif args.links:
111-
table.align["Issues link"] = "l"
112-
table.align["PRs link"] = "l"
113-
field_names.extend(["Issues link", "PRs link"])
122+
else:
123+
table.set_style(TableStyle.SINGLE_BORDER)
124+
114125
table.field_names = field_names
115126

116127
print()
@@ -124,26 +135,22 @@ def main() -> None:
124135
if x or y:
125136
match (args.markdown, args.links):
126137
case True, True:
127-
row = (
128-
i,
129-
author,
130-
f"[{x}](https://github.com/python/cpython/issues/{author})",
131-
f"[{y}](https://github.com/python/cpython/pulls/{author})",
132-
f"[{x + y}](https://github.com/python/cpython/"
133-
f"issues?q=is%3Aopen+author%3A{author})",
134-
)
138+
link_function = markdown_link
135139
case False, True:
136-
row = (
137-
i,
138-
author,
139-
x,
140-
y,
141-
x + y,
142-
f"https://github.com/python/cpython/issues/{author}",
143-
f"https://github.com/python/cpython/pulls/{author}",
144-
)
140+
link_function = terminal_link
145141
case _:
146-
row = (i, author, x, y, x + y)
142+
link_function = no_link
143+
144+
row = (
145+
i,
146+
author,
147+
link_function(f"https://github.com/python/cpython/issues/{author}", x),
148+
link_function(f"https://github.com/python/cpython/pulls/{author}", y),
149+
link_function(
150+
f"https://github.com/python/cpython/issues?q=is%3Aopen+author%3A{author}",
151+
x + y,
152+
),
153+
)
147154

148155
table.add_row(row)
149156

@@ -154,8 +161,6 @@ def main() -> None:
154161
f"{total_prs:,}",
155162
f"{total_issues + total_prs:,}",
156163
]
157-
if args.links and not args.markdown:
158-
total_row.extend(["", ""])
159164

160165
table.add_row(total_row)
161166
print(table)

0 commit comments

Comments
 (0)