Skip to content

Commit 49bebbf

Browse files
pr_file_map.py: add ignore_pull_request list, progress passes, dated title
- Add module-level ignore_pull_request: list[int]; get_open_prs() filters those PR numbers out (e.g. [123, 456, 789] skips #123, #456, #789). - Drop the redundant DIRECTORY.md comment above DIRECTORY_FILE (the module docstring and render_directory_section already explain it). - Fold the generation datetime into the H1 title: '# Open Pull Request File Map: 16 Sep 2026 at 21:45 UTC'. - Show progress on stderr via other/cheap_progress.py's progress() for the 'First pass' (fetch each PR's files) and 'Second pass' (classify files).
1 parent a6d20ad commit 49bebbf

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

scripts/pr_file_map.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
from datetime import UTC, datetime
5050
from pathlib import Path
5151

52-
# Auto-generated index of the repo. Almost every PR touches it, so a merge
53-
# conflict here is expected and is resolved with "accept both" in the GitHub UI.
5452
DIRECTORY_FILE = "DIRECTORY.md"
5553

54+
# Open PRs to skip in the report, e.g. [123, 456, 789] ignores #123, #456, #789.
55+
ignore_pull_request: list[int] = []
56+
5657

5758
def run_gh(args: list[str]) -> str:
5859
try:
@@ -113,7 +114,8 @@ def get_open_prs() -> list[dict]:
113114
raw = run_gh(
114115
["pr", "list", "--state", "open", "--limit", "1000", "--json", "number,title"]
115116
)
116-
return json.loads(raw)
117+
ignore = set(ignore_pull_request)
118+
return [pr for pr in json.loads(raw) if pr["number"] not in ignore]
117119

118120

119121
def get_pr_files(pr_number: int) -> list[str]:
@@ -197,6 +199,12 @@ def render_directory_section(
197199

198200

199201
def main() -> None:
202+
# Reuse the shared progress() helper from other/cheap_progress.py. It lives at
203+
# the repo root, which is not on sys.path when this script runs directly, so
204+
# add the repo root before importing rather than duplicating the helper here.
205+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
206+
from other.cheap_progress import progress
207+
200208
if shutil.which("gh") is None:
201209
sys.exit("Error: 'gh' (GitHub CLI) is not installed or not in PATH.")
202210

@@ -210,7 +218,7 @@ def main() -> None:
210218
pr_to_files: dict[int, list[str]] = {}
211219
touch_count = 0 # every (PR, file) pair; a file may be touched by many PRs
212220

213-
for pr in prs:
221+
for pr in progress(prs, desc="First pass"):
214222
pr_number = pr["number"]
215223
pr_files = get_pr_files(pr_number)
216224
pr_to_files[pr_number] = pr_files
@@ -232,7 +240,7 @@ def main() -> None:
232240
missing: dict[str, list[int]] = {}
233241
contested: dict[str, list[int]] = {}
234242

235-
for path, pr_numbers in file_to_prs.items():
243+
for path, pr_numbers in progress(file_to_prs.items(), desc="Second pass"):
236244
deduped = sorted(set(pr_numbers))
237245
target = existing if Path(path).exists() else missing
238246
target[path] = deduped
@@ -255,9 +263,9 @@ def main() -> None:
255263
)
256264

257265
# --- Render GitHub-flavored Markdown ---
258-
print("# Open Pull Request File Map\n")
266+
generated = f"{datetime.now(UTC):%d %b %Y at %H:%M} {UTC}"
267+
print(f"# Open Pull Request File Map: {generated}\n")
259268
print(f"- Script: `{script_display_path()}`")
260-
print(f"- Generated: `{datetime.now(UTC):%d %b %Y at %H:%M} {UTC}`")
261269
print(f"- Number of PRs: `{pr_count}`")
262270
print(f"- File touches (PR x file): `{touch_count}`")
263271
print(f"- Distinct files touched: `{distinct_count}`")

0 commit comments

Comments
 (0)