codeyear 0.2.15__tar.gz → 0.2.16__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codeyear-0.2.15 → codeyear-0.2.16}/PKG-INFO +4 -4
- {codeyear-0.2.15 → codeyear-0.2.16}/README.md +3 -3
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/__init__.py +1 -1
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/card.py +13 -15
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/cli.py +42 -79
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/config.py +5 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/github_public.py +94 -14
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/gui.py +51 -11
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/html_report.py +57 -32
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/i18n.py +8 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/poster.py +13 -15
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/report_theme.py +8 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/runner.py +14 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/scanner.py +17 -29
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/server.py +88 -11
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/stats.py +78 -12
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/updater.py +65 -20
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/PKG-INFO +4 -4
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/SOURCES.txt +1 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/pyproject.toml +1 -1
- codeyear-0.2.16/tests/test_commit_completeness.py +86 -0
- codeyear-0.2.16/tests/test_review_regressions.py +446 -0
- codeyear-0.2.15/tests/test_review_regressions.py +0 -45
- {codeyear-0.2.15 → codeyear-0.2.16}/LICENSE +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/__main__.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/keywords.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/languages.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/personas.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/profile.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear/wizard.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/dependency_links.txt +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/entry_points.txt +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/requires.txt +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/codeyear.egg-info/top_level.txt +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/setup.cfg +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_cli_boolean_overrides.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_core.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_github_fallback.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_github_pagination_completeness.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_profile_push_safety.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_public_push_safety.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_updater_prerelease.py +0 -0
- {codeyear-0.2.15 → codeyear-0.2.16}/tests/test_updater_versions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codeyear
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
4
4
|
Summary: Local-first annual coding report generated from your own git history.
|
|
5
5
|
Author: CodeYear contributors
|
|
6
6
|
License: MIT
|
|
@@ -66,7 +66,7 @@ codeyear
|
|
|
66
66
|
也可以从 Release 下载 wheel:
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
|
-
pip install https://github.com/Qiongkura/codeyear/releases/download/v0.2.
|
|
69
|
+
pip install https://github.com/Qiongkura/codeyear/releases/download/v0.2.16/codeyear-0.2.16-py3-none-any.whl
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
> exe 未做代码签名,Windows SmartScreen 可能提示;点「更多信息 → 仍要运行」。
|
|
@@ -86,7 +86,7 @@ python -m codeyear scan ~/code --open
|
|
|
86
86
|
或者用 uv 一行免安装运行(需要先装 [uv](https://docs.astral.sh/uv/)):
|
|
87
87
|
|
|
88
88
|
```bash
|
|
89
|
-
uvx --from "https://github.com/Qiongkura/codeyear/releases/download/v0.2.
|
|
89
|
+
uvx --from "https://github.com/Qiongkura/codeyear/releases/download/v0.2.16/codeyear-0.2.16-py3-none-any.whl" codeyear scan ~/code --open
|
|
90
90
|
# 或直接从源码运行:
|
|
91
91
|
uvx --from git+https://github.com/Qiongkura/codeyear.git codeyear scan ~/code --open
|
|
92
92
|
```
|
|
@@ -218,7 +218,7 @@ https://your-host/card.svg?username=Qiongkura&year=2026&lang=en
|
|
|
218
218
|
> 文件名绕过 GitHub 的图片缓存;无需手动粘贴 embed 片段。模板默认每天 04:00 UTC
|
|
219
219
|
> 更新;改 workflow 里的 `cron` 可切成每周一 `0 4 * * 1` 或每月 1 日 `0 4 1 * *`。
|
|
220
220
|
> 跨年时如果新的一年还没有提交,`--fallback-previous` 会继续显示上一年的卡片。
|
|
221
|
-
> 模板直接安装 Release 里的 wheel;升级时改 `CODEYEAR_VERSION`(当前 `0.2.
|
|
221
|
+
> 模板直接安装 Release 里的 wheel;升级时改 `CODEYEAR_VERSION`(当前 `0.2.16`)。
|
|
222
222
|
> 提交量大的账号建议在 Profile 仓库添加 `CODEYEAR_TOKEN`(PAT)secret;模板会优先使用它,
|
|
223
223
|
> 否则回退到 `GITHUB_TOKEN`。`GITHUB_TOKEN` 在 Actions 里通常只有 1,000 次/小时额度,
|
|
224
224
|
> 超过这个量时提交详情会被截断。
|
|
@@ -33,7 +33,7 @@ codeyear
|
|
|
33
33
|
也可以从 Release 下载 wheel:
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
pip install https://github.com/Qiongkura/codeyear/releases/download/v0.2.
|
|
36
|
+
pip install https://github.com/Qiongkura/codeyear/releases/download/v0.2.16/codeyear-0.2.16-py3-none-any.whl
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
> exe 未做代码签名,Windows SmartScreen 可能提示;点「更多信息 → 仍要运行」。
|
|
@@ -53,7 +53,7 @@ python -m codeyear scan ~/code --open
|
|
|
53
53
|
或者用 uv 一行免安装运行(需要先装 [uv](https://docs.astral.sh/uv/)):
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
|
-
uvx --from "https://github.com/Qiongkura/codeyear/releases/download/v0.2.
|
|
56
|
+
uvx --from "https://github.com/Qiongkura/codeyear/releases/download/v0.2.16/codeyear-0.2.16-py3-none-any.whl" codeyear scan ~/code --open
|
|
57
57
|
# 或直接从源码运行:
|
|
58
58
|
uvx --from git+https://github.com/Qiongkura/codeyear.git codeyear scan ~/code --open
|
|
59
59
|
```
|
|
@@ -185,7 +185,7 @@ https://your-host/card.svg?username=Qiongkura&year=2026&lang=en
|
|
|
185
185
|
> 文件名绕过 GitHub 的图片缓存;无需手动粘贴 embed 片段。模板默认每天 04:00 UTC
|
|
186
186
|
> 更新;改 workflow 里的 `cron` 可切成每周一 `0 4 * * 1` 或每月 1 日 `0 4 1 * *`。
|
|
187
187
|
> 跨年时如果新的一年还没有提交,`--fallback-previous` 会继续显示上一年的卡片。
|
|
188
|
-
> 模板直接安装 Release 里的 wheel;升级时改 `CODEYEAR_VERSION`(当前 `0.2.
|
|
188
|
+
> 模板直接安装 Release 里的 wheel;升级时改 `CODEYEAR_VERSION`(当前 `0.2.16`)。
|
|
189
189
|
> 提交量大的账号建议在 Profile 仓库添加 `CODEYEAR_TOKEN`(PAT)secret;模板会优先使用它,
|
|
190
190
|
> 否则回退到 `GITHUB_TOKEN`。`GITHUB_TOKEN` 在 Actions 里通常只有 1,000 次/小时额度,
|
|
191
191
|
> 超过这个量时提交详情会被截断。
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import html
|
|
6
|
-
from datetime import
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
9
|
from .stats import (
|
|
@@ -14,6 +14,8 @@ from .stats import (
|
|
|
14
14
|
fmt_signed_pair,
|
|
15
15
|
language_breakdown,
|
|
16
16
|
parse_daily,
|
|
17
|
+
window_days,
|
|
18
|
+
window_months,
|
|
17
19
|
)
|
|
18
20
|
|
|
19
21
|
W, H = 640, 1254
|
|
@@ -247,9 +249,10 @@ MONTHS = [
|
|
|
247
249
|
|
|
248
250
|
|
|
249
251
|
def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
250
|
-
theme: str = "paper", lang: str = "zh"
|
|
252
|
+
theme: str = "paper", lang: str = "zh",
|
|
253
|
+
palette_override: dict | None = None) -> str:
|
|
251
254
|
light, dark_theme = THEMES.get(theme, THEMES["paper"])
|
|
252
|
-
c = dark_theme if dark else light
|
|
255
|
+
c = palette_override if palette_override is not None else (dark_theme if dark else light)
|
|
253
256
|
en = lang == "en"
|
|
254
257
|
|
|
255
258
|
def t(zh: str, english: str) -> str:
|
|
@@ -300,7 +303,7 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
300
303
|
header.append(_rule(142, c["line"]))
|
|
301
304
|
|
|
302
305
|
# ---- six summary tiles (3 x 2) ------------------------------------
|
|
303
|
-
active_pct = stats.active_days / (
|
|
306
|
+
active_pct = stats.active_days / window_days(stats)
|
|
304
307
|
tiles = [
|
|
305
308
|
(t("COMMITS / 提交", "COMMITS"), fmt_int(stats.commit_count),
|
|
306
309
|
t("年度提交", "commits this year")),
|
|
@@ -343,19 +346,18 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
343
346
|
|
|
344
347
|
# ---- contribution calendar ---------------------------------------
|
|
345
348
|
cell, gap_h = 9, 2
|
|
346
|
-
|
|
347
|
-
grid_start
|
|
348
|
-
grid_end =
|
|
349
|
-
grid_end += timedelta(days=6 - grid_end.weekday())
|
|
349
|
+
start_w, end_w = date_window(stats)
|
|
350
|
+
grid_start = start_w - timedelta(days=start_w.weekday())
|
|
351
|
+
grid_end = end_w + timedelta(days=6 - end_w.weekday())
|
|
350
352
|
grid_cols = (grid_end - grid_start).days // 7 + 1
|
|
351
353
|
grid_w = grid_cols * (cell + gap_h) - gap_h
|
|
352
354
|
grid_x = (W - grid_w) / 2
|
|
353
355
|
|
|
354
356
|
month_ticks = []
|
|
355
|
-
for
|
|
356
|
-
col = (
|
|
357
|
+
for m_date, m_label in window_months(stats):
|
|
358
|
+
col = (m_date - grid_start).days // 7
|
|
357
359
|
mx = grid_x + col * (cell + gap_h)
|
|
358
|
-
month_ticks.append(_text(mx, 588,
|
|
360
|
+
month_ticks.append(_text(mx, 588, m_label, 9.5, c["muted"]))
|
|
359
361
|
|
|
360
362
|
charts = [
|
|
361
363
|
_text(M, 350, "MONTHLY RHYTHM", 10, c["muted"], spacing=1),
|
|
@@ -702,10 +704,6 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
702
704
|
"""
|
|
703
705
|
|
|
704
706
|
|
|
705
|
-
def _is_leap(year: int) -> bool:
|
|
706
|
-
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
|
|
707
|
-
|
|
708
|
-
|
|
709
707
|
def render(stats: ReportStats, out_path: str | Path, *,
|
|
710
708
|
theme: str = "paper", lang: str = "zh") -> list[Path]:
|
|
711
709
|
path = Path(out_path)
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
|
-
import json
|
|
7
6
|
import os
|
|
8
|
-
import subprocess
|
|
9
7
|
import sys
|
|
10
8
|
import webbrowser
|
|
11
9
|
from datetime import date
|
|
@@ -13,17 +11,25 @@ from pathlib import Path
|
|
|
13
11
|
|
|
14
12
|
from . import __version__, i18n
|
|
15
13
|
from .card import THEMES
|
|
16
|
-
from .card import render as render_card
|
|
17
14
|
from .config import load as load_config
|
|
18
|
-
from .
|
|
19
|
-
from .
|
|
20
|
-
from .poster import render as render_poster
|
|
21
|
-
from .poster import render_long
|
|
22
|
-
from .runner import discover, report_path, scan
|
|
23
|
-
from .stats import fmt_int
|
|
15
|
+
from .runner import detect_identity, discover, render, report_path, scan
|
|
16
|
+
from .stats import fmt_int, window_days
|
|
24
17
|
from .updater import check_update, cleanup_old_executable, perform_update
|
|
25
18
|
|
|
26
|
-
|
|
19
|
+
|
|
20
|
+
class _CopyAppendAction(argparse.Action):
|
|
21
|
+
"""Append action that never mutates a config-provided default list."""
|
|
22
|
+
|
|
23
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
24
|
+
items = list(getattr(namespace, self.dest, None) or [])
|
|
25
|
+
if getattr(namespace, f"_cy_copied_{self.dest}", False) is False:
|
|
26
|
+
items = [] if values == "" else list(items)
|
|
27
|
+
setattr(namespace, f"_cy_copied_{self.dest}", True)
|
|
28
|
+
if values == "":
|
|
29
|
+
items = []
|
|
30
|
+
else:
|
|
31
|
+
items.append(values)
|
|
32
|
+
setattr(namespace, self.dest, items)
|
|
27
33
|
|
|
28
34
|
|
|
29
35
|
def _build_parser() -> argparse.ArgumentParser:
|
|
@@ -88,7 +94,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
88
94
|
scan.add_argument("--rolling", action=argparse.BooleanOptionalAction,
|
|
89
95
|
default=cfg.get("rolling", False),
|
|
90
96
|
help="统计过去 365 天(滚动年度),而非自然年")
|
|
91
|
-
scan.add_argument("--exclude", action=
|
|
97
|
+
scan.add_argument("--exclude", action=_CopyAppendAction, default=list(cfg.get("exclude", [])),
|
|
92
98
|
help="排除指定仓库名或通配符(可重复或逗号分隔)")
|
|
93
99
|
scan.add_argument("--out", default=cfg.get("out", "codeyear-output"),
|
|
94
100
|
help="输出目录,默认 ./codeyear-output")
|
|
@@ -100,7 +106,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
100
106
|
scan.add_argument("--fallback-previous", action=argparse.BooleanOptionalAction,
|
|
101
107
|
default=cfg.get("fallback_previous", False),
|
|
102
108
|
help="当年没有提交时回退到上一年,适合跨年自动更新")
|
|
103
|
-
scan.add_argument("--alias", action=
|
|
109
|
+
scan.add_argument("--alias", action=_CopyAppendAction, default=list(cfg.get("aliases", [])),
|
|
104
110
|
help="额外作者邮箱或名字,可重复;用于旧提交")
|
|
105
111
|
scan.add_argument("--no-mailmap", action="store_true",
|
|
106
112
|
default=cfg.get("no_mailmap", False),
|
|
@@ -151,22 +157,7 @@ def _open_path(path: Path) -> None:
|
|
|
151
157
|
|
|
152
158
|
def _detect_identity() -> tuple[str, str] | None:
|
|
153
159
|
"""The runner's git identity, used to keep only their own commits."""
|
|
154
|
-
|
|
155
|
-
def config(key: str) -> str:
|
|
156
|
-
try:
|
|
157
|
-
proc = subprocess.run(
|
|
158
|
-
["git", "config", "--global", key],
|
|
159
|
-
capture_output=True, text=True, encoding="utf-8",
|
|
160
|
-
errors="replace", timeout=10, creationflags=_NO_WINDOW,
|
|
161
|
-
)
|
|
162
|
-
except (OSError, subprocess.TimeoutExpired):
|
|
163
|
-
return ""
|
|
164
|
-
return (proc.stdout or "").strip()
|
|
165
|
-
|
|
166
|
-
email, name = config("user.email"), config("user.name")
|
|
167
|
-
if email or name:
|
|
168
|
-
return (email, name)
|
|
169
|
-
return None
|
|
160
|
+
return detect_identity()
|
|
170
161
|
|
|
171
162
|
|
|
172
163
|
def main(argv: list[str] | None = None) -> int:
|
|
@@ -296,6 +287,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
296
287
|
jobs=max(1, args.jobs), progress=progress,
|
|
297
288
|
compare=args.compare, use_mailmap=not args.no_mailmap,
|
|
298
289
|
all_branches=args.all_branches,
|
|
290
|
+
rolling=args.rolling,
|
|
299
291
|
)
|
|
300
292
|
if previous.commit_count:
|
|
301
293
|
stats, warnings = previous, prev_warnings
|
|
@@ -312,56 +304,31 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
312
304
|
return 3
|
|
313
305
|
|
|
314
306
|
out_dir = Path(args.out)
|
|
315
|
-
|
|
316
|
-
base = out_dir / f"codeyear-{args.year}"
|
|
317
|
-
|
|
318
|
-
written: list[tuple[str, Path]] = []
|
|
319
|
-
|
|
320
|
-
json_path = base.with_suffix(".json")
|
|
321
|
-
json_path.write_text(
|
|
322
|
-
json.dumps(stats.as_dict(), ensure_ascii=False, indent=2),
|
|
323
|
-
encoding="utf-8",
|
|
324
|
-
)
|
|
325
|
-
written.append(("JSON", json_path))
|
|
326
|
-
|
|
307
|
+
formats = {"json"}
|
|
327
308
|
if not args.no_html:
|
|
328
|
-
|
|
329
|
-
written.append(("HTML", html_path))
|
|
330
|
-
en_path = render_html_en(stats, out_dir / f"codeyear-{args.year}-en.html")
|
|
331
|
-
written.append(("HTML-EN", en_path))
|
|
332
|
-
|
|
309
|
+
formats.add("html")
|
|
333
310
|
if not args.no_png:
|
|
334
|
-
|
|
335
|
-
written.append(("PNG", png_path))
|
|
336
|
-
if i18n.get_lang() == "en":
|
|
337
|
-
png_en = render_poster(
|
|
338
|
-
stats, out_dir / f"codeyear-{args.year}-en.png", lang="en")
|
|
339
|
-
written.append(("PNG-EN", png_en))
|
|
311
|
+
formats.add("png")
|
|
340
312
|
if not args.no_long:
|
|
341
|
-
|
|
342
|
-
written.append(("LONG", long_path))
|
|
343
|
-
if i18n.get_lang() == "en":
|
|
344
|
-
long_en = render_long(
|
|
345
|
-
stats, out_dir / f"codeyear-{args.year}-en-long.png",
|
|
346
|
-
lang="en")
|
|
347
|
-
written.append(("LONG-EN", long_en))
|
|
348
|
-
|
|
349
|
-
card_paths = []
|
|
350
|
-
en_cards = []
|
|
351
|
-
card_theme = getattr(args, "theme", "paper") or "paper"
|
|
313
|
+
formats.add("long")
|
|
352
314
|
if not args.no_card:
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
315
|
+
formats.add("card")
|
|
316
|
+
card_theme = getattr(args, "theme", "paper") or "paper"
|
|
317
|
+
written = render(
|
|
318
|
+
stats, out_dir, formats=formats,
|
|
319
|
+
card_theme=card_theme, lang=i18n.get_lang(),
|
|
320
|
+
)
|
|
321
|
+
by_label = dict(written)
|
|
322
|
+
card_paths = (
|
|
323
|
+
[by_label["CARD"], by_label["CARD-DARK"]]
|
|
324
|
+
if "CARD" in by_label and "CARD-DARK" in by_label
|
|
325
|
+
else []
|
|
326
|
+
)
|
|
327
|
+
en_cards = (
|
|
328
|
+
[by_label["CARD-EN"], by_label["CARD-DARK-EN"]]
|
|
329
|
+
if "CARD-EN" in by_label and "CARD-DARK-EN" in by_label
|
|
330
|
+
else []
|
|
331
|
+
)
|
|
365
332
|
|
|
366
333
|
exit_code = 0
|
|
367
334
|
if args.profile_repo:
|
|
@@ -398,7 +365,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
398
365
|
exit_code = 1
|
|
399
366
|
|
|
400
367
|
# Console summary
|
|
401
|
-
active_pct = stats.active_days / (
|
|
368
|
+
active_pct = stats.active_days / window_days(stats)
|
|
402
369
|
print()
|
|
403
370
|
print(i18n.tr(
|
|
404
371
|
"CodeYear {year} · {title}",
|
|
@@ -446,9 +413,5 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
446
413
|
return exit_code
|
|
447
414
|
|
|
448
415
|
|
|
449
|
-
def _is_leap(year: int) -> bool:
|
|
450
|
-
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
|
|
451
|
-
|
|
452
|
-
|
|
453
416
|
if __name__ == "__main__": # pragma: no cover
|
|
454
417
|
raise SystemExit(main())
|
|
@@ -36,6 +36,7 @@ SCHEMA = {
|
|
|
36
36
|
"github_user": str,
|
|
37
37
|
"profile_repo": str,
|
|
38
38
|
"push_profile": bool,
|
|
39
|
+
"lang": str,
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
|
|
@@ -76,6 +77,8 @@ def load() -> dict:
|
|
|
76
77
|
"paper", "mono", "forest", "ocean",
|
|
77
78
|
}:
|
|
78
79
|
continue
|
|
80
|
+
if key == "lang" and value not in {"zh", "en"}:
|
|
81
|
+
continue
|
|
79
82
|
clean[key] = value
|
|
80
83
|
if clean.get("max_commits", 1) <= 0:
|
|
81
84
|
clean.pop("max_commits", None)
|
|
@@ -105,6 +108,8 @@ def save(values: dict) -> Path:
|
|
|
105
108
|
elif expected is str and isinstance(value, str):
|
|
106
109
|
if key == "theme" and value not in {"paper", "mono", "forest", "ocean"}:
|
|
107
110
|
continue
|
|
111
|
+
if key == "lang" and value not in {"zh", "en"}:
|
|
112
|
+
continue
|
|
108
113
|
clean[key] = value
|
|
109
114
|
target = path()
|
|
110
115
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -108,6 +108,32 @@ def _load_cache(path: Path | None) -> dict:
|
|
|
108
108
|
return details if isinstance(details, dict) else {}
|
|
109
109
|
|
|
110
110
|
|
|
111
|
+
def _slim_detail(detail: dict) -> dict:
|
|
112
|
+
"""Keep only fields needed by CodeYear, dropping multi-KB diff patches."""
|
|
113
|
+
commit = detail.get("commit") or {}
|
|
114
|
+
author = commit.get("author") or {}
|
|
115
|
+
msg_lines = (commit.get("message") or "").splitlines()
|
|
116
|
+
return {
|
|
117
|
+
"parents": [{} for _ in (detail.get("parents") or [])],
|
|
118
|
+
"commit": {
|
|
119
|
+
"author": {"date": author.get("date")},
|
|
120
|
+
"message": msg_lines[0][:200] if msg_lines else "",
|
|
121
|
+
},
|
|
122
|
+
"stats": {
|
|
123
|
+
"additions": int((detail.get("stats") or {}).get("additions", 0)),
|
|
124
|
+
"deletions": int((detail.get("stats") or {}).get("deletions", 0)),
|
|
125
|
+
},
|
|
126
|
+
"files": [
|
|
127
|
+
{
|
|
128
|
+
"filename": f.get("filename") or "",
|
|
129
|
+
"additions": int(f.get("additions", 0)),
|
|
130
|
+
"deletions": int(f.get("deletions", 0)),
|
|
131
|
+
}
|
|
132
|
+
for f in (detail.get("files") or [])
|
|
133
|
+
],
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
111
137
|
def _save_cache(path: Path | None, details: dict) -> None:
|
|
112
138
|
if path is None:
|
|
113
139
|
return
|
|
@@ -250,6 +276,16 @@ def _commits(
|
|
|
250
276
|
since = f"{year - 1}-12-31T00:00:00Z"
|
|
251
277
|
until = f"{year + 1}-01-02T00:00:00Z"
|
|
252
278
|
listed = _IncompleteList()
|
|
279
|
+
def _eligible_list_item(item: dict) -> bool:
|
|
280
|
+
if len(item.get("parents") or []) > 1:
|
|
281
|
+
return False
|
|
282
|
+
raw_date = ((item.get("commit") or {}).get("author") or {}).get("date")
|
|
283
|
+
if raw_date:
|
|
284
|
+
d = _dt(raw_date, tz=target_tz)
|
|
285
|
+
if d is not None and d.year != year:
|
|
286
|
+
return False
|
|
287
|
+
return True
|
|
288
|
+
|
|
253
289
|
# A busy repository can exceed 1,000 commits in one year; keep paging
|
|
254
290
|
# until the caller's budget is reached or GitHub runs out of pages.
|
|
255
291
|
for page in range(1, 101):
|
|
@@ -259,8 +295,27 @@ def _commits(
|
|
|
259
295
|
})
|
|
260
296
|
if not data:
|
|
261
297
|
break
|
|
262
|
-
|
|
263
|
-
if len(
|
|
298
|
+
eligible = [item for item in data if _eligible_list_item(item)]
|
|
299
|
+
if len(listed) + len(eligible) > limit:
|
|
300
|
+
listed.extend(eligible[: limit - len(listed)])
|
|
301
|
+
listed.truncated = True
|
|
302
|
+
break
|
|
303
|
+
listed.extend(eligible)
|
|
304
|
+
if len(data) < 100:
|
|
305
|
+
break
|
|
306
|
+
if len(listed) >= limit:
|
|
307
|
+
# At an exact page boundary, completeness cannot be inferred from
|
|
308
|
+
# a full page alone. Probe for another entry rather than warn on a
|
|
309
|
+
# repository whose history ends exactly at the limit.
|
|
310
|
+
if len(listed) == limit and page < 100:
|
|
311
|
+
extra = api.get(f"/repos/{full}/commits", {
|
|
312
|
+
"author": username, "since": since, "until": until,
|
|
313
|
+
"per_page": 100, "page": page + 1,
|
|
314
|
+
}) or []
|
|
315
|
+
extra_eligible = [it for it in extra if _eligible_list_item(it)]
|
|
316
|
+
listed.truncated = bool(extra_eligible or len(extra) == 100)
|
|
317
|
+
else:
|
|
318
|
+
listed.truncated = True
|
|
264
319
|
break
|
|
265
320
|
else:
|
|
266
321
|
listed.truncated = True
|
|
@@ -286,7 +341,7 @@ def _commits(
|
|
|
286
341
|
idx, item = entry
|
|
287
342
|
detail = api.get(f"/repos/{full}/commits/{item['sha']}")
|
|
288
343
|
if cache is not None and detail:
|
|
289
|
-
cache[keys[idx]] = detail
|
|
344
|
+
cache[keys[idx]] = _slim_detail(detail)
|
|
290
345
|
return detail
|
|
291
346
|
|
|
292
347
|
# Commit details are independent; a small pool cuts wall time without
|
|
@@ -296,9 +351,13 @@ def _commits(
|
|
|
296
351
|
for (index, _item), detail in zip(missing, fetched):
|
|
297
352
|
details[index] = detail
|
|
298
353
|
|
|
299
|
-
commits
|
|
354
|
+
commits = _IncompleteList()
|
|
355
|
+
# The list endpoint may have more entries than the detail budget, or may
|
|
356
|
+
# hit our page cap. Preserve that fact even when filtering removes merges.
|
|
357
|
+
commits.truncated = listed.truncated or len(listed) > limit
|
|
300
358
|
for item, detail in zip(items, details):
|
|
301
359
|
if not detail:
|
|
360
|
+
commits.truncated = True
|
|
302
361
|
continue
|
|
303
362
|
# Match the local scanner's --no-merges behavior.
|
|
304
363
|
if len(detail.get("parents") or []) > 1:
|
|
@@ -307,7 +366,10 @@ def _commits(
|
|
|
307
366
|
dt = _dt(author_date, tz=target_tz)
|
|
308
367
|
if dt is None:
|
|
309
368
|
dt = _dt((item.get("commit") or {}).get("author", {}).get("date"), tz=target_tz)
|
|
310
|
-
if dt is None
|
|
369
|
+
if dt is None:
|
|
370
|
+
commits.truncated = True
|
|
371
|
+
continue
|
|
372
|
+
if dt.year != year:
|
|
311
373
|
continue
|
|
312
374
|
message = ((detail.get("commit") or {}).get("message") or "").splitlines()
|
|
313
375
|
subject = message[0].strip() if message else ""
|
|
@@ -346,7 +408,7 @@ def _commits(
|
|
|
346
408
|
|
|
347
409
|
|
|
348
410
|
def _total_commits(api: GitHubAPI, full: str, username: str) -> int:
|
|
349
|
-
for
|
|
411
|
+
for attempt in range(2):
|
|
350
412
|
data = api.get(f"/repos/{full}/stats/contributors")
|
|
351
413
|
if isinstance(data, list):
|
|
352
414
|
for contributor in data:
|
|
@@ -354,7 +416,8 @@ def _total_commits(api: GitHubAPI, full: str, username: str) -> int:
|
|
|
354
416
|
if (author.get("login") or "").lower() == username.lower():
|
|
355
417
|
return sum(int(week.get("c", 0)) for week in contributor.get("weeks", []))
|
|
356
418
|
return 0
|
|
357
|
-
|
|
419
|
+
if attempt == 0:
|
|
420
|
+
time.sleep(0.35)
|
|
358
421
|
return 0
|
|
359
422
|
|
|
360
423
|
|
|
@@ -421,18 +484,19 @@ def fetch_stats(
|
|
|
421
484
|
except RuntimeError as exc:
|
|
422
485
|
warnings.append(str(exc))
|
|
423
486
|
break
|
|
487
|
+
if getattr(commits, "truncated", False):
|
|
488
|
+
warnings.append(i18n.tr(
|
|
489
|
+
"{repo} 的提交数据可能不完整(分页、数量上限或详情缺失)。", repo=full,
|
|
490
|
+
))
|
|
424
491
|
if not commits:
|
|
425
492
|
continue
|
|
426
493
|
total += len(commits)
|
|
427
|
-
if total >= max_commits
|
|
494
|
+
if total >= max_commits and (
|
|
495
|
+
getattr(commits, "truncated", False) or index < len(repos)
|
|
496
|
+
):
|
|
428
497
|
warnings.append(i18n.tr(
|
|
429
498
|
"已达到 --max-commits 上限({limit})", limit=max_commits,
|
|
430
499
|
))
|
|
431
|
-
try:
|
|
432
|
-
repo_total = _total_commits(api, full, login)
|
|
433
|
-
except RuntimeError as exc:
|
|
434
|
-
warnings.append(str(exc))
|
|
435
|
-
repo_total = 0
|
|
436
500
|
results.append(RepoResult(
|
|
437
501
|
path=Path(full),
|
|
438
502
|
name=full,
|
|
@@ -441,10 +505,26 @@ def fetch_stats(
|
|
|
441
505
|
readme_line=repo.get("description") or "",
|
|
442
506
|
root=full,
|
|
443
507
|
root_dt=_dt(repo.get("created_at"), tz=target_tz),
|
|
444
|
-
total_commits=
|
|
508
|
+
total_commits=len(commits),
|
|
445
509
|
tags_in_year=0,
|
|
446
510
|
))
|
|
447
511
|
|
|
512
|
+
if results:
|
|
513
|
+
def _fetch_repo_total(res: RepoResult) -> tuple[int, str | None]:
|
|
514
|
+
try:
|
|
515
|
+
return _total_commits(api, res.name, login), None
|
|
516
|
+
except RuntimeError as exc:
|
|
517
|
+
return 0, str(exc)
|
|
518
|
+
|
|
519
|
+
with ThreadPoolExecutor(
|
|
520
|
+
max_workers=min(len(results), DETAIL_WORKERS)
|
|
521
|
+
) as pool:
|
|
522
|
+
totals = list(pool.map(_fetch_repo_total, results))
|
|
523
|
+
for res, (repo_total, err) in zip(results, totals):
|
|
524
|
+
if err:
|
|
525
|
+
warnings.append(err)
|
|
526
|
+
res.total_commits = repo_total or len(res.commits)
|
|
527
|
+
|
|
448
528
|
if not results:
|
|
449
529
|
_save_cache(cache_path, cache)
|
|
450
530
|
if warnings:
|