Skip to content

Commit 369c99d

Browse files
authored
Avoid utils/check_bad_commit.py failing due to rate limit (requesting api.github.com) (#39918)
fix Co-authored-by: ydshieh <[email protected]>
1 parent b771e47 commit 369c99d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

utils/check_bad_commit.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ def get_commit_info(commit):
171171
print(f"start_commit: {args.start_commit}")
172172
print(f"end_commit: {args.end_commit}")
173173

174+
# `get_commit_info` uses `requests.get()` to request info. via `api.github.com` without using token.
175+
# If there are many new failed tests in a workflow run, this script may fail at some point with `KeyError` at
176+
# `pr_number = pr_info_for_commit[0]["number"]` due to the rate limit.
177+
# Let's cache the commit info. and reuse them whenever possible.
178+
commit_info_cache = {}
179+
174180
if len({args.test is None, args.file is None}) != 2:
175181
raise ValueError("Exactly one argument `test` or `file` must be specified.")
176182

@@ -191,7 +197,14 @@ def get_commit_info(commit):
191197
for test in failed_tests:
192198
commit = find_bad_commit(target_test=test, start_commit=args.start_commit, end_commit=args.end_commit)
193199
info = {"test": test, "commit": commit}
194-
info.update(get_commit_info(commit))
200+
201+
if commit in commit_info_cache:
202+
commit_info = commit_info_cache[commit]
203+
else:
204+
commit_info = get_commit_info(commit)
205+
commit_info_cache[commit] = commit_info
206+
207+
info.update(commit_info)
195208
failed_tests_with_bad_commits.append(info)
196209

197210
# If no single-gpu test failures, remove the key

0 commit comments

Comments
 (0)