Skip to content

Commit a096cf3

Browse files
committed
address copilot comments
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 5ad69d6 commit a096cf3

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎tools/contribution/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rough signal; read the actual contributions before drawing conclusions.
3030

3131
## Requirements
3232

33-
- Python 3.7+
33+
- Python 3.8+
3434
- [`requests`](https://pypi.org/project/requests/): `pip install requests`
3535

3636
## github_org_contributions.py

‎tools/contribution/apache_list_mentions.py‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import mailbox
4848
import re
4949
import sys
50-
from email.utils import parseaddr
5150
from pathlib import Path
5251
from typing import Dict, Iterable, List, Tuple
5352

@@ -85,15 +84,26 @@ def download_mbox(list_name: str, domain: str, ym: str, out_dir: Path) -> Path:
8584
out_path = out_dir / f"{list_name}@{domain}-{ym}.mbox"
8685

8786
headers = {"User-Agent": "apache-list-mentions/1.0"}
88-
r = requests.get(url, headers=headers, timeout=120)
89-
90-
if r.status_code == 404 or not r.content.strip():
87+
with requests.get(url, headers=headers, timeout=120, stream=True) as r:
88+
if r.status_code == 404:
89+
raise FileNotFoundError(f"No archive found for {ym}")
90+
r.raise_for_status()
91+
92+
# Stream to a temp file so an interrupted download is never reused as a cached archive
93+
tmp_path = out_path.with_suffix(".mbox.part")
94+
has_content = False
95+
try:
96+
with tmp_path.open("wb") as f:
97+
for chunk in r.iter_content(chunk_size=1024 * 1024):
98+
has_content = has_content or bool(chunk.strip())
99+
f.write(chunk)
100+
except BaseException:
101+
tmp_path.unlink(missing_ok=True)
102+
raise
103+
104+
if not has_content:
105+
tmp_path.unlink(missing_ok=True)
91106
raise FileNotFoundError(f"No archive found for {ym}")
92-
93-
r.raise_for_status()
94-
# Write via a temp file so an interrupted download is never reused as a cached archive
95-
tmp_path = out_path.with_suffix(".mbox.part")
96-
tmp_path.write_bytes(r.content)
97107
tmp_path.replace(out_path)
98108
return out_path
99109

‎tools/contribution/github_org_contributions.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def shift_years(d: dt.datetime, years: int) -> dt.datetime:
8484

8585
def year_chunks(from_dt: dt.datetime, to_dt: dt.datetime) -> Iterable[Tuple[dt.datetime, dt.datetime]]:
8686
"""
87-
Split [from_dt, to_dt] into consecutive windows of at most one year.
87+
Split [from_dt, to_dt) into consecutive end-exclusive windows of at most one year.
8888
"""
8989
start = from_dt
9090
while start < to_dt:
@@ -154,7 +154,7 @@ def count_user(token: str, login: str, org_id: str, org_login: str, repo_rx: re.
154154
})
155155
user = data.get("user")
156156
if not user:
157-
raise RuntimeError("User not found")
157+
raise RuntimeError(f"User not found: {login}")
158158
user_login = user["login"]
159159

160160
cc = user["contributionsCollection"]

0 commit comments

Comments
 (0)