|
5 | 5 | Lists all open pull requests in the current directory's git repo (via `gh`) |
6 | 6 | and, for each file touched by any open PR, which PR number(s) touch it. |
7 | 7 |
|
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 |
9 | 11 | exist in the working directory, each with its modifying PR numbers, followed |
10 | 12 | by a separate section for files referenced by open PRs but that do not exist |
11 | 13 | in the working directory (e.g. deleted, renamed, or on a branch not checked |
12 | 14 | out locally). |
13 | 15 |
|
| 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 | +
|
14 | 21 | Requirements: gh (GitHub CLI), authenticated (`gh auth login`) |
15 | 22 |
|
16 | 23 | Usage: |
|
19 | 26 | """ |
20 | 27 |
|
21 | 28 | import json |
22 | | -import os |
23 | 29 | import shutil |
24 | 30 | import subprocess |
25 | 31 | import sys |
26 | 32 | from collections import defaultdict |
| 33 | +from datetime import UTC, datetime |
| 34 | +from pathlib import Path |
27 | 35 |
|
28 | 36 |
|
29 | 37 | def run_gh(args: list[str]) -> str: |
@@ -73,26 +81,44 @@ def main() -> None: |
73 | 81 | check_gh_auth() |
74 | 82 |
|
75 | 83 | prs = get_open_prs() |
| 84 | + pr_count = len(prs) |
| 85 | + print(f"PR count from get_open_prs(): {pr_count}", file=sys.stderr) |
76 | 86 | if not prs: |
77 | 87 | print("No open pull requests found.") |
78 | 88 | return |
79 | 89 |
|
80 | 90 | file_to_prs: dict[str, list[int]] = defaultdict(list) |
| 91 | + file_count = 0 |
81 | 92 |
|
82 | 93 | for pr in prs: |
83 | 94 | 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: |
85 | 98 | file_to_prs[path].append(pr_number) |
| 99 | + print(f"File count from get_pr_files(): {file_count}", file=sys.stderr) |
86 | 100 |
|
87 | 101 | existing: dict[str, list[int]] = {} |
88 | 102 | missing: dict[str, list[int]] = {} |
89 | 103 |
|
90 | 104 | 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 |
92 | 106 | 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 | + ) |
93 | 113 |
|
94 | 114 | # --- Render GitHub-flavored Markdown --- |
95 | 115 | 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") |
96 | 122 |
|
97 | 123 | print("## Existing files\n") |
98 | 124 | if existing: |
|
0 commit comments