Skip to content

Commit 5a3c7cf

Browse files
authored
Shorted issue body if necessary (#56)
1 parent 5f64150 commit 5a3c7cf

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

ci/make_issues.py

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import pandas as pd
1111

12+
GITHUB_ISSUE_LENGTH = 65000
13+
1214

1315
def get_commit_range(*, benchmarks: pd.DataFrame, sha: str) -> str:
1416
"""Get commit range between a hash and the previous hash that has a benchmark.
@@ -30,7 +32,7 @@ def get_commit_range(*, benchmarks: pd.DataFrame, sha: str) -> str:
3032
return result
3133

3234

33-
def execute(cmd):
35+
def execute(cmd: str) -> str:
3436
response = subprocess.run(cmd, shell=True, capture_output=True, check=False)
3537
if response.returncode != 0:
3638
raise ValueError(f"{response.stdout.decode()}\n\n{response.stderr.decode()}")
@@ -58,6 +60,44 @@ def time_to_str(x: float) -> str:
5860
return result
5961

6062

63+
def make_body(
64+
base_url: str,
65+
commit_range: str,
66+
benchmarks: pd.DataFrame,
67+
sha: str,
68+
shorten: bool = False,
69+
) -> str:
70+
body = f"[Commit Range]({base_url + commit_range})"
71+
body += "\n\n"
72+
body += (
73+
"Subsequent benchmarks may have skipped some commits. The link"
74+
" above lists the commits that are"
75+
" between the two benchmark runs where the regression was identified."
76+
"\n\n"
77+
)
78+
79+
regressions = benchmarks[benchmarks["sha"].eq(sha) & benchmarks["is_regression"]]
80+
for _, regression in regressions.iterrows():
81+
benchmark = regression["name"]
82+
params = regression["params"]
83+
base_url = "https://pandas-dev.github.io/asv-runner/#"
84+
url = f"{base_url}{benchmark}"
85+
abs_change = time_to_str(regression["abs_change"])
86+
severity = f"{regression['pct_change']:0.3%} ({abs_change})"
87+
body += f" - [ ] [{benchmark}]({url})"
88+
if params == "" or shorten:
89+
body += f" - {severity}\n"
90+
continue
91+
body += "\n"
92+
params_list = list(params.split(", "))
93+
params_suffix = "?p-" + "&p-".join(params_list)
94+
url = f"{base_url}{benchmark}{params_suffix}"
95+
url = urllib.parse.quote(url, safe="/:?=&#")
96+
body += f" - [ ] [{params}]({url}) - {severity}\n"
97+
body += "\n"
98+
return body
99+
100+
61101
def run(input_path: str | Path):
62102
if not isinstance(input_path, Path):
63103
input_path = Path(input_path)
@@ -82,36 +122,21 @@ def run(input_path: str | Path):
82122
title = f"Commit {sha}"
83123
base_url = "https://github.com/pandas-dev/pandas/compare/"
84124
commit_range = get_commit_range(benchmarks=benchmarks, sha=sha)
85-
body = f"[Commit Range]({base_url + commit_range})"
86-
body += "\n\n"
87-
body += (
88-
"Subsequent benchmarks may have skipped some commits. The link"
89-
" above lists the commits that are"
90-
" between the two benchmark runs where the regression was identified."
91-
"\n\n"
92-
)
93125

94-
regressions = benchmarks[
95-
benchmarks["sha"].eq(sha) & benchmarks["is_regression"]
96-
]
97-
for _, regression in regressions.iterrows():
98-
benchmark = regression["name"]
99-
params = regression["params"]
100-
base_url = "https://pandas-dev.github.io/asv-runner/#"
101-
url = f"{base_url}{benchmark}"
102-
abs_change = time_to_str(regression["abs_change"])
103-
severity = f"{regression['pct_change']:0.3%} ({abs_change})"
104-
body += f" - [ ] [{benchmark}]({url})"
105-
if params == "":
106-
result += f" - {severity}\n"
107-
continue
108-
body += "\n"
109-
params_list = list(params.split(", "))
110-
params_suffix = "?p-" + "&p-".join(params_list)
111-
url = f"{base_url}{benchmark}{params_suffix}"
112-
url = urllib.parse.quote(url, safe="/:?=&#")
113-
body += f" - [ ] [{params}]({url}) - {severity}\n"
114-
body += "\n"
126+
body = make_body(
127+
base_url=base_url,
128+
commit_range=commit_range,
129+
benchmarks=benchmarks,
130+
sha=sha,
131+
)
132+
if len(body) >= GITHUB_ISSUE_LENGTH:
133+
body = make_body(
134+
base_url=base_url,
135+
commit_range=commit_range,
136+
benchmarks=benchmarks,
137+
sha=sha,
138+
shorten=True,
139+
)
115140

116141
cmd = (
117142
f"gh issue create"

0 commit comments

Comments
 (0)