Skip to content

Commit 39bfa82

Browse files
Copilotcclauss
andauthored
Use pathlib and add PR/file status reporting in pr_file_map
Co-authored-by: cclauss <3709715+cclauss@users.noreply.github.com>
1 parent d04b15b commit 39bfa82

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

scripts/pr_file_map.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
Lists all open pull requests in the current directory's git repo (via `gh`)
66
and, for each file touched by any open PR, which PR number(s) touch it.
77
8-
Output is GitHub-flavored Markdown: a sorted list of files that currently
8+
Output is GitHub-flavored Markdown that includes this script's path, the
9+
current UTC datetime, and summary counts for open PRs, file entries, and
10+
existing/missing files. It then renders a sorted list of files that currently
911
exist in the working directory, each with its modifying PR numbers, followed
1012
by a separate section for files referenced by open PRs but that do not exist
1113
in the working directory (e.g. deleted, renamed, or on a branch not checked
1214
out locally).
1315
16+
Run status is also written to stderr with:
17+
- Number of PRs from `get_open_prs()`
18+
- Number of files from `get_pr_files()`
19+
- Number of existing and missing files
20+
1421
Requirements: gh (GitHub CLI), authenticated (`gh auth login`)
1522
1623
Usage:
@@ -19,11 +26,12 @@
1926
"""
2027

2128
import json
22-
import os
2329
import shutil
2430
import subprocess
2531
import sys
2632
from collections import defaultdict
33+
from datetime import UTC, datetime
34+
from pathlib import Path
2735

2836

2937
def run_gh(args: list[str]) -> str:
@@ -73,26 +81,44 @@ def main() -> None:
7381
check_gh_auth()
7482

7583
prs = get_open_prs()
84+
pr_count = len(prs)
85+
print(f"PR count from get_open_prs(): {pr_count}", file=sys.stderr)
7686
if not prs:
7787
print("No open pull requests found.")
7888
return
7989

8090
file_to_prs: dict[str, list[int]] = defaultdict(list)
91+
file_count = 0
8192

8293
for pr in prs:
8394
pr_number = pr["number"]
84-
for path in get_pr_files(pr_number):
95+
pr_files = get_pr_files(pr_number)
96+
file_count += len(pr_files)
97+
for path in pr_files:
8598
file_to_prs[path].append(pr_number)
99+
print(f"File count from get_pr_files(): {file_count}", file=sys.stderr)
86100

87101
existing: dict[str, list[int]] = {}
88102
missing: dict[str, list[int]] = {}
89103

90104
for path, pr_numbers in file_to_prs.items():
91-
target = existing if os.path.exists(path) else missing
105+
target = existing if Path(path).exists() else missing
92106
target[path] = sorted(set(pr_numbers))
107+
existing_count = len(existing)
108+
missing_count = len(missing)
109+
print(
110+
f"Existing files: {existing_count}, Missing files: {missing_count}",
111+
file=sys.stderr,
112+
)
93113

94114
# --- Render GitHub-flavored Markdown ---
95115
print("# Open Pull Request File Map\n")
116+
print(f"- Script: `{Path(__file__).resolve()}`")
117+
print(f"- Generated (UTC): `{datetime.now(UTC).isoformat()}`")
118+
print(f"- Number of PRs: `{pr_count}`")
119+
print(f"- Number of files: `{file_count}`")
120+
print(f"- Existing files: `{existing_count}`")
121+
print(f"- Missing files: `{missing_count}`\n")
96122

97123
print("## Existing files\n")
98124
if existing:

0 commit comments

Comments
 (0)