codeyear 0.2.16__tar.gz → 0.2.17__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.16 → codeyear-0.2.17}/PKG-INFO +2 -2
- {codeyear-0.2.16 → codeyear-0.2.17}/README.md +1 -1
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/__init__.py +1 -1
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/card.py +115 -9
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/cli.py +13 -3
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/github_public.py +66 -7
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/gui.py +72 -14
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/html_report.py +22 -9
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/i18n.py +5 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/languages.py +22 -5
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/poster.py +10 -6
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/report_theme.py +1 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/runner.py +37 -13
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/scanner.py +84 -11
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/stats.py +153 -47
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/wizard.py +2 -2
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/PKG-INFO +2 -2
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/SOURCES.txt +2 -1
- {codeyear-0.2.16 → codeyear-0.2.17}/pyproject.toml +1 -1
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_review_regressions.py +5 -1
- codeyear-0.2.17/tests/test_v0217_optimizations.py +392 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/LICENSE +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/__main__.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/config.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/keywords.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/personas.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/profile.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/server.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear/updater.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/dependency_links.txt +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/entry_points.txt +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/requires.txt +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/codeyear.egg-info/top_level.txt +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/setup.cfg +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_cli_boolean_overrides.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_commit_completeness.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_core.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_github_fallback.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_github_pagination_completeness.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_profile_push_safety.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_public_push_safety.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/tests/test_updater_prerelease.py +0 -0
- {codeyear-0.2.16 → codeyear-0.2.17}/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.17
|
|
4
4
|
Summary: Local-first annual coding report generated from your own git history.
|
|
5
5
|
Author: CodeYear contributors
|
|
6
6
|
License: MIT
|
|
@@ -410,7 +410,7 @@ codeyear github Qiongkura --year 2026 --card-only \
|
|
|
410
410
|
| `--all-branches` | 统计所有本地分支/tag 的提交(默认只看当前分支) |
|
|
411
411
|
| `--max-depth 6` | 每个根目录向下查找仓库的最大文件夹层数 |
|
|
412
412
|
| `--timeout 300` | 单个仓库的扫描超时(秒) |
|
|
413
|
-
| `--jobs
|
|
413
|
+
| `--jobs N` | 并行扫描的仓库数,默认按 CPU 核数(2–8)自动设置 |
|
|
414
414
|
| `--no-png` / `--no-html` | 跳过 PNG / HTML(可同时使用) |
|
|
415
415
|
| `--no-long` | 不生成完整版长图(默认生成) |
|
|
416
416
|
| `--no-card` | 不生成 GitHub 主页卡片 |
|
|
@@ -377,7 +377,7 @@ codeyear github Qiongkura --year 2026 --card-only \
|
|
|
377
377
|
| `--all-branches` | 统计所有本地分支/tag 的提交(默认只看当前分支) |
|
|
378
378
|
| `--max-depth 6` | 每个根目录向下查找仓库的最大文件夹层数 |
|
|
379
379
|
| `--timeout 300` | 单个仓库的扫描超时(秒) |
|
|
380
|
-
| `--jobs
|
|
380
|
+
| `--jobs N` | 并行扫描的仓库数,默认按 CPU 核数(2–8)自动设置 |
|
|
381
381
|
| `--no-png` / `--no-html` | 跳过 PNG / HTML(可同时使用) |
|
|
382
382
|
| `--no-long` | 不生成完整版长图(默认生成) |
|
|
383
383
|
| `--no-card` | 不生成 GitHub 主页卡片 |
|
|
@@ -13,7 +13,9 @@ from .stats import (
|
|
|
13
13
|
fmt_int,
|
|
14
14
|
fmt_signed_pair,
|
|
15
15
|
language_breakdown,
|
|
16
|
+
month_labels,
|
|
16
17
|
parse_daily,
|
|
18
|
+
peak_month,
|
|
17
19
|
window_days,
|
|
18
20
|
window_months,
|
|
19
21
|
)
|
|
@@ -260,7 +262,8 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
260
262
|
|
|
261
263
|
monthly = stats.monthly
|
|
262
264
|
peak = max(monthly) or 1
|
|
263
|
-
|
|
265
|
+
labels = month_labels(stats)
|
|
266
|
+
_peak_idx, peak_month_no = peak_month(stats)
|
|
264
267
|
peak_hour = stats.by_hour.index(max(stats.by_hour)) if any(stats.by_hour) else 0
|
|
265
268
|
owner = (stats.identity_label or "").split(" <")[0].strip()
|
|
266
269
|
|
|
@@ -341,7 +344,7 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
341
344
|
f'<rect x="{x}" y="{baseline - height}" width="{bar_w}" '
|
|
342
345
|
f'height="{height}" fill="{fill}"/>'
|
|
343
346
|
)
|
|
344
|
-
bars.append(_text(x + bar_w / 2, baseline + 14,
|
|
347
|
+
bars.append(_text(x + bar_w / 2, baseline + 14, labels[i], 9.5,
|
|
345
348
|
c["muted"], anchor="middle"))
|
|
346
349
|
|
|
347
350
|
# ---- contribution calendar ---------------------------------------
|
|
@@ -362,8 +365,111 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
362
365
|
charts = [
|
|
363
366
|
_text(M, 350, "MONTHLY RHYTHM", 10, c["muted"], spacing=1),
|
|
364
367
|
_text(RIGHT, 350, t(
|
|
365
|
-
f"峰值 {
|
|
366
|
-
f"Peak {MONTHS[
|
|
368
|
+
f"峰值 {peak_month_no:02d} 月 · {peak} 次",
|
|
369
|
+
f"Peak {MONTHS[peak_month_no - 1]} · {peak}",
|
|
370
|
+
), 10, c["accent"], anchor="end"),
|
|
371
|
+
*bars,
|
|
372
|
+
_rule(462, c["line"]),
|
|
373
|
+
_text(M, 480, "CONTRIBUTION", 10, c["muted"], spacing=1),
|
|
374
|
+
_text(RIGHT, 480, t(
|
|
375
|
+
f"{stats.active_days} 个活跃日",
|
|
376
|
+
f"{stats.active_days} active days",
|
|
377
|
+
), 10, c["muted"], anchor="end"),
|
|
378
|
+
_heatmap(stats, c, grid_x, 498, cell, gap_h),
|
|
379
|
+
*month_ticks,
|
|
380
|
+
_rule(602, c["line"]),
|
|
381
|
+
]
|
|
382
|
+
|
|
383
|
+
# ---- derived insights ---------------------------------------------
|
|
384
|
+
cols2 = [M, M + 306]
|
|
385
|
+
top_repo = stats.repo_details[0] if stats.repo_details else None
|
|
386
|
+
if top_repo and stats.commit_count:
|
|
387
|
+
share = top_repo["commits"] / stats.commit_count
|
|
388
|
+
focus_num, focus_unit = f"{share * 100:.0f}", "%"
|
|
389
|
+
focus_sub = t(
|
|
390
|
+
f"大部分提交在 {_truncate(top_repo['name'], 16)}",
|
|
391
|
+
f"Most commits in {_truncate(top_repo['name'], 22)}",
|
|
392
|
+
)
|
|
393
|
+
else:
|
|
394
|
+
focus_num, focus_unit, focus_sub = "—", "", t("暂无数据", "No data")
|
|
395
|
+
|
|
396
|
+
night, weekend = stats.night_share, stats.weekend_share
|
|
397
|
+
rhythm_num, rhythm_unit = f"{peak_hour:02d}:00", ""
|
|
398
|
+
rhythm_sub = t(
|
|
399
|
+
f"深夜提交占 {night:.0%} · 周末 {weekend:.0%}",
|
|
400
|
+
f"{night:.0%} late-night · {weekend:.0%} weekend",
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
size_map = dict(stats.size_buckets)
|
|
404
|
+
size_total = sum(size_map.values()) or 1
|
|
405
|
+
small_share = (size_map.get("0–10", 0) + size_map.get("10–100", 0)) / size_total
|
|
406
|
+
large_share = (size_map.get("500–2k", 0) + size_map.get("2k+", 0)) / size_total
|
|
407
|
+
style_num, style_unit = f"{small_share * 100:.0f}", "%"
|
|
408
|
+
style_sub = t(
|
|
409
|
+
f"小改动为主 · 大改仅 {large_share:.0%}",
|
|
410
|
+
f"Mostly small changes · large {large_share:.0%}",
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
sessions = stats.sessions or {}
|
|
414
|
+
sess_count = int(sessions.get("count") or 0)
|
|
415
|
+
avg_min = int(sessions.get("avg_minutes") or 0)
|
|
416
|
+
long_min = int(sessions.get("longest_minutes") or 0)
|
|
417
|
+
if avg_min:
|
|
418
|
+
if avg_min >= 90:
|
|
419
|
+
pace_num, pace_unit = f"{avg_min / 60:.1f}", t("小时", "h")
|
|
420
|
+
else:
|
|
421
|
+
pace_num, pace_unit = str(avg_min), t("分钟", "min")
|
|
422
|
+
long_label = (
|
|
423
|
+
f"{long_min / 60:.0f}h" if long_min >= 90 else f"{long_min}min"
|
|
424
|
+
) if en else (
|
|
425
|
+
f"{long_min / 60:.0f} 小时" if long_min >= 90 else f"{long_min} 分钟"
|
|
426
|
+
)
|
|
427
|
+
pace_sub = t(
|
|
428
|
+
f"{sess_count} 次连续写码 · 最长 {long_label}",
|
|
429
|
+
f"{sess_count} sessions · longest {long_label}",
|
|
430
|
+
)
|
|
431
|
+
else:
|
|
432
|
+
pace_num, pace_unit, pace_sub = "—", "", t("暂无会话", "No sessions")
|
|
433
|
+
|
|
434
|
+
churn_total = stats.insertions + stats.deletions
|
|
435
|
+
deletion_share = stats.deletions / churn_total if churn_total else 0
|
|
436
|
+
ratio = stats.insertions / stats.deletions if stats.deletions else 0
|
|
437
|
+
if deletion_share >= 0.5:
|
|
438
|
+
churn_kind = t("重构型", "Refactoring")
|
|
439
|
+
elif deletion_share >= 0.3:
|
|
440
|
+
churn_kind = t("平衡型", "Balanced")
|
|
441
|
+
else:
|
|
442
|
+
churn_kind = t("扩张型", "Expanding")
|
|
443
|
+
if ratio:
|
|
444
|
+
churn_num, churn_unit = f"{ratio:.1f}", ":1"
|
|
445
|
+
churn_sub = t(
|
|
446
|
+
f"每写 {ratio:.1f} 行才删 1 行",
|
|
447
|
+
f"{ratio:.1f} lines written per line deleted",
|
|
448
|
+
)
|
|
449
|
+
else:
|
|
450
|
+
churn_num, churn_unit = t("只增", "add-only"), ""
|
|
451
|
+
churn_sub = t(f"{churn_kind} · 没有删除", f"{churn_kind} · no deletions")
|
|
452
|
+
|
|
453
|
+
# ---- contribution calendar ---------------------------------------
|
|
454
|
+
cell, gap_h = 9, 2
|
|
455
|
+
start_w, end_w = date_window(stats)
|
|
456
|
+
grid_start = start_w - timedelta(days=start_w.weekday())
|
|
457
|
+
grid_end = end_w + timedelta(days=6 - end_w.weekday())
|
|
458
|
+
grid_cols = (grid_end - grid_start).days // 7 + 1
|
|
459
|
+
grid_w = grid_cols * (cell + gap_h) - gap_h
|
|
460
|
+
grid_x = (W - grid_w) / 2
|
|
461
|
+
|
|
462
|
+
month_ticks = []
|
|
463
|
+
for m_date, m_label in window_months(stats):
|
|
464
|
+
col = (m_date - grid_start).days // 7
|
|
465
|
+
mx = grid_x + col * (cell + gap_h)
|
|
466
|
+
month_ticks.append(_text(mx, 588, m_label, 9.5, c["muted"]))
|
|
467
|
+
|
|
468
|
+
charts = [
|
|
469
|
+
_text(M, 350, "MONTHLY RHYTHM", 10, c["muted"], spacing=1),
|
|
470
|
+
_text(RIGHT, 350, t(
|
|
471
|
+
f"峰值 {peak_month_no:02d} 月 · {peak} 次",
|
|
472
|
+
f"Peak {MONTHS[peak_month_no - 1]} · {peak}",
|
|
367
473
|
), 10, c["accent"], anchor="end"),
|
|
368
474
|
*bars,
|
|
369
475
|
_rule(462, c["line"]),
|
|
@@ -449,25 +555,25 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
|
|
|
449
555
|
|
|
450
556
|
peak_share = peak / max(stats.commit_count, 1)
|
|
451
557
|
burst_num, burst_unit = f"{peak_share * 100:.0f}", "%"
|
|
452
|
-
peak_label = MONTHS[
|
|
558
|
+
peak_label = MONTHS[peak_month_no - 1]
|
|
453
559
|
if peak_share >= 0.5:
|
|
454
560
|
burst_sub = t(
|
|
455
|
-
f"{
|
|
561
|
+
f"{peak_month_no} 月占了全年 {peak_share:.0%} 的提交",
|
|
456
562
|
f"{peak_label} accounted for {peak_share:.0%} of the year",
|
|
457
563
|
)
|
|
458
564
|
elif peak_share >= 0.3:
|
|
459
565
|
burst_sub = t(
|
|
460
|
-
f"{
|
|
566
|
+
f"{peak_month_no} 月最忙,占全年 {peak_share:.0%}",
|
|
461
567
|
f"{peak_label} was busiest at {peak_share:.0%}",
|
|
462
568
|
)
|
|
463
569
|
elif peak_share >= 0.18:
|
|
464
570
|
burst_sub = t(
|
|
465
|
-
f"{
|
|
571
|
+
f"{peak_month_no} 月提交最多,占 {peak_share:.0%}",
|
|
466
572
|
f"{peak_label} had the most commits ({peak_share:.0%})",
|
|
467
573
|
)
|
|
468
574
|
else:
|
|
469
575
|
burst_sub = t(
|
|
470
|
-
f"全年分布比较平均,{
|
|
576
|
+
f"全年分布比较平均,{peak_month_no} 月最多",
|
|
471
577
|
f"Fairly even across the year; {peak_label} was slightly ahead",
|
|
472
578
|
)
|
|
473
579
|
|
|
@@ -12,7 +12,14 @@ from pathlib import Path
|
|
|
12
12
|
from . import __version__, i18n
|
|
13
13
|
from .card import THEMES
|
|
14
14
|
from .config import load as load_config
|
|
15
|
-
from .runner import
|
|
15
|
+
from .runner import (
|
|
16
|
+
DEFAULT_JOBS,
|
|
17
|
+
detect_identity,
|
|
18
|
+
discover,
|
|
19
|
+
render,
|
|
20
|
+
report_path,
|
|
21
|
+
scan,
|
|
22
|
+
)
|
|
16
23
|
from .stats import fmt_int, window_days
|
|
17
24
|
from .updater import check_update, cleanup_old_executable, perform_update
|
|
18
25
|
|
|
@@ -58,6 +65,8 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
58
65
|
github.add_argument("--max-commits", type=int, default=cfg.get("max_commits", 200),
|
|
59
66
|
help="最多拉取多少条提交(无 token 时自动限制为 30)")
|
|
60
67
|
github.add_argument("--include-forks", action="store_true", help="包含 fork 仓库")
|
|
68
|
+
github.add_argument("--include-contributed", action="store_true",
|
|
69
|
+
help="同时统计你向他人/组织公开仓库贡献的提交(PR 合入的外部仓库)")
|
|
61
70
|
github.add_argument("--open", action=argparse.BooleanOptionalAction,
|
|
62
71
|
default=cfg.get("open", False), help="生成后打开报告")
|
|
63
72
|
github.add_argument("--quiet", action="store_true", help="不打印扫描进度")
|
|
@@ -123,8 +132,8 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
123
132
|
help="向下查找仓库的最大文件夹层数,默认 6")
|
|
124
133
|
scan.add_argument("--timeout", type=int, default=cfg.get("timeout", 300),
|
|
125
134
|
help="单个仓库的扫描超时秒数")
|
|
126
|
-
scan.add_argument("--jobs", type=int, default=cfg.get("jobs",
|
|
127
|
-
help="并行扫描的仓库数,默认
|
|
135
|
+
scan.add_argument("--jobs", type=int, default=cfg.get("jobs", DEFAULT_JOBS),
|
|
136
|
+
help=f"并行扫描的仓库数,默认 {DEFAULT_JOBS}(机器核数)")
|
|
128
137
|
scan.add_argument("--theme", choices=sorted(THEMES),
|
|
129
138
|
default=cfg.get("theme", "paper"),
|
|
130
139
|
help="卡片主题:paper / mono / forest / ocean")
|
|
@@ -220,6 +229,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
220
229
|
no_cache=args.no_cache,
|
|
221
230
|
lang=i18n.get_lang(),
|
|
222
231
|
tz=args.tz, require_complete=args.require_complete,
|
|
232
|
+
include_contributed=args.include_contributed,
|
|
223
233
|
)
|
|
224
234
|
if args.command == "serve":
|
|
225
235
|
from .server import serve
|
|
@@ -7,6 +7,7 @@ repositories through the GitHub REST API.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import contextlib
|
|
10
11
|
import json
|
|
11
12
|
import os
|
|
12
13
|
import re
|
|
@@ -137,19 +138,24 @@ def _slim_detail(detail: dict) -> dict:
|
|
|
137
138
|
def _save_cache(path: Path | None, details: dict) -> None:
|
|
138
139
|
if path is None:
|
|
139
140
|
return
|
|
141
|
+
tmp: Path | None = None
|
|
140
142
|
try:
|
|
141
143
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
142
144
|
if len(details) > CACHE_MAX:
|
|
143
145
|
details = dict(list(details.items())[-CACHE_MAX:])
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
ensure_ascii=False,
|
|
148
|
-
),
|
|
149
|
-
encoding="utf-8",
|
|
146
|
+
payload = json.dumps(
|
|
147
|
+
{"version": CACHE_VERSION, "details": details},
|
|
148
|
+
ensure_ascii=False,
|
|
150
149
|
)
|
|
150
|
+
# Write-then-rename: an interrupted run must never leave a truncated
|
|
151
|
+
# JSON file that breaks the next scan.
|
|
152
|
+
tmp = path.with_name(path.name + ".tmp")
|
|
153
|
+
tmp.write_text(payload, encoding="utf-8")
|
|
154
|
+
os.replace(tmp, path)
|
|
151
155
|
except OSError:
|
|
152
|
-
|
|
156
|
+
if tmp is not None:
|
|
157
|
+
with contextlib.suppress(OSError):
|
|
158
|
+
tmp.unlink()
|
|
153
159
|
|
|
154
160
|
|
|
155
161
|
def _dt(
|
|
@@ -421,6 +427,47 @@ def _total_commits(api: GitHubAPI, full: str, username: str) -> int:
|
|
|
421
427
|
return 0
|
|
422
428
|
|
|
423
429
|
|
|
430
|
+
def _contributed_repos(
|
|
431
|
+
api: GitHubAPI,
|
|
432
|
+
login: str,
|
|
433
|
+
year: int,
|
|
434
|
+
include_forks: bool,
|
|
435
|
+
) -> list[dict]:
|
|
436
|
+
"""Public repos the user committed to but does not own.
|
|
437
|
+
|
|
438
|
+
One search request (plus pagination) finds commits authored by *login* in
|
|
439
|
+
a year; the returned ``repository`` objects are merged into the scan set,
|
|
440
|
+
so PRs merged into an org or another project count too.
|
|
441
|
+
"""
|
|
442
|
+
found: dict[str, dict] = {}
|
|
443
|
+
query = f"author:{login} author-date:{year}-01-01..{year}-12-31"
|
|
444
|
+
for page in range(1, 4):
|
|
445
|
+
try:
|
|
446
|
+
data = api.get("/search/commits", {
|
|
447
|
+
"q": query, "per_page": 100, "page": page,
|
|
448
|
+
})
|
|
449
|
+
except Exception:
|
|
450
|
+
break
|
|
451
|
+
items = (data or {}).get("items") or []
|
|
452
|
+
if not items:
|
|
453
|
+
break
|
|
454
|
+
for item in items:
|
|
455
|
+
repo = item.get("repository") or {}
|
|
456
|
+
full = repo.get("full_name")
|
|
457
|
+
if not full or full in found or repo.get("private"):
|
|
458
|
+
continue
|
|
459
|
+
if repo.get("fork") and not include_forks:
|
|
460
|
+
continue
|
|
461
|
+
if (repo.get("owner") or {}).get("login", "").lower() == login.lower():
|
|
462
|
+
# Already covered by /users/{login}/repos.
|
|
463
|
+
continue
|
|
464
|
+
repo["_contributed_only"] = True
|
|
465
|
+
found[full] = repo
|
|
466
|
+
if len(items) < 100:
|
|
467
|
+
break
|
|
468
|
+
return list(found.values())
|
|
469
|
+
|
|
470
|
+
|
|
424
471
|
def fetch_stats(
|
|
425
472
|
username: str,
|
|
426
473
|
year: int,
|
|
@@ -431,6 +478,7 @@ def fetch_stats(
|
|
|
431
478
|
quiet: bool = False,
|
|
432
479
|
cache_path: Path | None = None,
|
|
433
480
|
tz: str | tzinfo | None = None,
|
|
481
|
+
include_contributed: bool = False,
|
|
434
482
|
) -> tuple[ReportStats, list[str], str]:
|
|
435
483
|
api = GitHubAPI(token)
|
|
436
484
|
target_tz = _parse_tz(tz)
|
|
@@ -457,6 +505,13 @@ def fetch_stats(
|
|
|
457
505
|
if not quiet:
|
|
458
506
|
print(f"CodeYear · github.com/{login} · {year}", file=sys.stderr)
|
|
459
507
|
repos = _repos(api, login, since, include_forks, tz=target_tz)
|
|
508
|
+
if include_contributed:
|
|
509
|
+
known = {r.get("full_name") for r in repos}
|
|
510
|
+
extra = [
|
|
511
|
+
r for r in _contributed_repos(api, login, year, include_forks)
|
|
512
|
+
if r.get("full_name") not in known
|
|
513
|
+
]
|
|
514
|
+
repos.extend(extra)
|
|
460
515
|
if getattr(repos, "truncated", False):
|
|
461
516
|
warnings = [i18n.tr(
|
|
462
517
|
"公开仓库超过分页上限,统计可能不完整。"
|
|
@@ -571,6 +626,7 @@ def run(
|
|
|
571
626
|
lang: str = "zh",
|
|
572
627
|
tz: str | None = None,
|
|
573
628
|
require_complete: bool = False,
|
|
629
|
+
include_contributed: bool = False,
|
|
574
630
|
) -> int:
|
|
575
631
|
cache_path = None
|
|
576
632
|
if not no_cache:
|
|
@@ -583,6 +639,7 @@ def run(
|
|
|
583
639
|
username, year, token=token, max_commits=max_commits,
|
|
584
640
|
include_forks=include_forks, quiet=quiet,
|
|
585
641
|
cache_path=cache_path, tz=tz,
|
|
642
|
+
include_contributed=include_contributed,
|
|
586
643
|
)
|
|
587
644
|
except NoPublicCommitsError:
|
|
588
645
|
if not fallback_previous or year != datetime.now().year:
|
|
@@ -591,6 +648,7 @@ def run(
|
|
|
591
648
|
username, year - 1, token=token, max_commits=max_commits,
|
|
592
649
|
include_forks=include_forks, quiet=quiet,
|
|
593
650
|
cache_path=cache_path, tz=tz,
|
|
651
|
+
include_contributed=include_contributed,
|
|
594
652
|
)
|
|
595
653
|
else:
|
|
596
654
|
if (fallback_previous and not stats.commit_count
|
|
@@ -599,6 +657,7 @@ def run(
|
|
|
599
657
|
username, year - 1, token=token, max_commits=max_commits,
|
|
600
658
|
include_forks=include_forks, quiet=quiet,
|
|
601
659
|
cache_path=cache_path, tz=tz,
|
|
660
|
+
include_contributed=include_contributed,
|
|
602
661
|
)
|
|
603
662
|
if previous.commit_count:
|
|
604
663
|
stats, warnings = previous, prev_warnings
|
|
@@ -19,7 +19,14 @@ from . import i18n
|
|
|
19
19
|
from .card import THEMES
|
|
20
20
|
from .config import load as load_config
|
|
21
21
|
from .config import save as save_config
|
|
22
|
-
from .runner import
|
|
22
|
+
from .runner import (
|
|
23
|
+
DEFAULT_JOBS,
|
|
24
|
+
detect_identity,
|
|
25
|
+
discover,
|
|
26
|
+
render,
|
|
27
|
+
report_path,
|
|
28
|
+
scan,
|
|
29
|
+
)
|
|
23
30
|
from .stats import fmt_int
|
|
24
31
|
from .updater import check_update, cleanup_old_executable, perform_update
|
|
25
32
|
|
|
@@ -48,6 +55,8 @@ class App:
|
|
|
48
55
|
self.html_path: Path | None = None
|
|
49
56
|
self.update_info: dict | None = None
|
|
50
57
|
self.busy = False
|
|
58
|
+
self.cancel_event: threading.Event | None = None
|
|
59
|
+
self._count_gen = 0
|
|
51
60
|
|
|
52
61
|
root.title(i18n.tr("CodeYear · 代码手账"))
|
|
53
62
|
root.geometry("860x960")
|
|
@@ -58,9 +67,7 @@ class App:
|
|
|
58
67
|
for folder in self.roots:
|
|
59
68
|
self.folder_list.insert("end", str(folder))
|
|
60
69
|
if self.roots:
|
|
61
|
-
self.
|
|
62
|
-
text=i18n.tr("已添加,开始生成时会统计仓库数量")
|
|
63
|
-
)
|
|
70
|
+
self._auto_count()
|
|
64
71
|
self._poll()
|
|
65
72
|
if not os.environ.get("CODEYEAR_NO_UPDATE_CHECK"):
|
|
66
73
|
threading.Thread(
|
|
@@ -284,7 +291,7 @@ class App:
|
|
|
284
291
|
tk.Label(advanced, text=i18n.tr("并行数"), bg=PAPER, fg=MUTED,
|
|
285
292
|
font=("Microsoft YaHei", 9)).pack(side="left")
|
|
286
293
|
self.jobs_var = tk.StringVar(
|
|
287
|
-
value=str(self.cfg.get("jobs",
|
|
294
|
+
value=str(self.cfg.get("jobs", DEFAULT_JOBS))
|
|
288
295
|
)
|
|
289
296
|
self.jobs_entry = ttk.Entry(
|
|
290
297
|
advanced, width=4, textvariable=self.jobs_var, style="CY.TEntry",
|
|
@@ -462,19 +469,43 @@ class App:
|
|
|
462
469
|
return
|
|
463
470
|
self.roots.append(resolved)
|
|
464
471
|
self.folder_list.insert("end", str(resolved))
|
|
465
|
-
self.
|
|
466
|
-
text=i18n.tr("已添加,开始生成时会统计仓库数量")
|
|
467
|
-
)
|
|
472
|
+
self._auto_count()
|
|
468
473
|
|
|
469
474
|
def _remove_folder(self) -> None:
|
|
470
475
|
selected = list(self.folder_list.curselection())
|
|
471
476
|
for index in reversed(selected):
|
|
472
477
|
self.folder_list.delete(index)
|
|
473
478
|
del self.roots[index]
|
|
479
|
+
self._auto_count()
|
|
474
480
|
|
|
475
481
|
def _clear_folders(self) -> None:
|
|
476
482
|
self.folder_list.delete(0, "end")
|
|
477
483
|
self.roots.clear()
|
|
484
|
+
self._auto_count()
|
|
485
|
+
|
|
486
|
+
def _auto_count(self) -> None:
|
|
487
|
+
"""Refresh the repo count in the background after a folder change."""
|
|
488
|
+
if self.busy:
|
|
489
|
+
return
|
|
490
|
+
if not self.roots:
|
|
491
|
+
self.count_label.configure(text="")
|
|
492
|
+
return
|
|
493
|
+
try:
|
|
494
|
+
depth = int(self.depth_var.get())
|
|
495
|
+
except ValueError:
|
|
496
|
+
depth = 6
|
|
497
|
+
excludes = [
|
|
498
|
+
item.strip() for item in self.exclude_var.get().split(",")
|
|
499
|
+
if item.strip()
|
|
500
|
+
]
|
|
501
|
+
self._count_gen += 1
|
|
502
|
+
generation = self._count_gen
|
|
503
|
+
self.count_label.configure(text=i18n.tr("正在检查…"))
|
|
504
|
+
threading.Thread(
|
|
505
|
+
target=self._count_work,
|
|
506
|
+
args=(list(self.roots), depth, excludes, generation),
|
|
507
|
+
daemon=True,
|
|
508
|
+
).start()
|
|
478
509
|
|
|
479
510
|
def _switch_lang(self) -> None:
|
|
480
511
|
if self.busy:
|
|
@@ -526,8 +557,7 @@ class App:
|
|
|
526
557
|
self._rolling_draw()
|
|
527
558
|
self._push_draw()
|
|
528
559
|
if self.roots:
|
|
529
|
-
self.
|
|
530
|
-
text=i18n.tr("已添加,开始生成时会统计仓库数量"))
|
|
560
|
+
self._auto_count()
|
|
531
561
|
self._set_result(saved["result"])
|
|
532
562
|
self.html_path = report_path(self.written, lang=i18n.get_lang())
|
|
533
563
|
if self.written:
|
|
@@ -556,15 +586,18 @@ class App:
|
|
|
556
586
|
if item.strip()
|
|
557
587
|
]
|
|
558
588
|
self.count_label.configure(text=i18n.tr("正在检查…"))
|
|
589
|
+
self._count_gen += 1
|
|
559
590
|
threading.Thread(
|
|
560
|
-
target=self._count_work,
|
|
591
|
+
target=self._count_work,
|
|
592
|
+
args=(list(self.roots), depth, excludes, self._count_gen),
|
|
561
593
|
daemon=True,
|
|
562
594
|
).start()
|
|
563
595
|
|
|
564
|
-
def _count_work(self, roots, depth, excludes=None) -> None:
|
|
596
|
+
def _count_work(self, roots, depth, excludes=None, generation=0) -> None:
|
|
565
597
|
try:
|
|
566
598
|
self.queue.put((
|
|
567
|
-
"checked", len(discover(roots, depth, exclude=excludes))
|
|
599
|
+
"checked", len(discover(roots, depth, exclude=excludes)),
|
|
600
|
+
generation,
|
|
568
601
|
))
|
|
569
602
|
except Exception as exc: # pragma: no cover - UI path
|
|
570
603
|
self.queue.put(("error", str(exc)))
|
|
@@ -663,6 +696,7 @@ class App:
|
|
|
663
696
|
push_profile = bool(self.push_profile_var.get())
|
|
664
697
|
|
|
665
698
|
self._set_busy(True)
|
|
699
|
+
self.cancel_event = threading.Event()
|
|
666
700
|
self.written = []
|
|
667
701
|
self.html_path = None
|
|
668
702
|
self.progress.configure(value=0, maximum=1)
|
|
@@ -714,6 +748,7 @@ class App:
|
|
|
714
748
|
use_mailmap=not bool(self.cfg.get("no_mailmap", False)),
|
|
715
749
|
all_branches=all_branches,
|
|
716
750
|
rolling=rolling,
|
|
751
|
+
cancel_event=self.cancel_event,
|
|
717
752
|
)
|
|
718
753
|
if stats.commit_count == 0:
|
|
719
754
|
raise RuntimeError(i18n.tr(
|
|
@@ -759,6 +794,9 @@ class App:
|
|
|
759
794
|
"找到 {count} 个仓库,开始扫描…", count=count,
|
|
760
795
|
))
|
|
761
796
|
elif kind == "checked":
|
|
797
|
+
if len(event) > 2 and event[2] != self._count_gen:
|
|
798
|
+
# A newer folder change already superseded this count.
|
|
799
|
+
continue
|
|
762
800
|
self.count_label.configure(text=i18n.tr(
|
|
763
801
|
"找到 {count} 个 git 仓库", count=event[1],
|
|
764
802
|
))
|
|
@@ -806,15 +844,35 @@ class App:
|
|
|
806
844
|
|
|
807
845
|
def _fail(self, message: str) -> None:
|
|
808
846
|
self._set_busy(False)
|
|
847
|
+
if message.strip() == i18n.tr("已取消。"):
|
|
848
|
+
self.status.configure(text=i18n.tr("已取消扫描。"))
|
|
849
|
+
self.progress.configure(value=0)
|
|
850
|
+
return
|
|
809
851
|
self.status.configure(text=i18n.tr(
|
|
810
852
|
"失败:{message}", message=message,
|
|
811
853
|
))
|
|
812
854
|
messagebox.showerror(i18n.tr("生成失败"), message)
|
|
813
855
|
|
|
856
|
+
def _cancel(self) -> None:
|
|
857
|
+
if self.cancel_event is not None:
|
|
858
|
+
self.cancel_event.set()
|
|
859
|
+
self.status.configure(text=i18n.tr("正在取消…"))
|
|
860
|
+
self.start_btn.configure(state="disabled")
|
|
861
|
+
|
|
814
862
|
def _set_busy(self, busy: bool) -> None:
|
|
815
863
|
self.busy = busy
|
|
816
864
|
state = "disabled" if busy else "normal"
|
|
817
|
-
self
|
|
865
|
+
if hasattr(self, "start_btn"):
|
|
866
|
+
if busy:
|
|
867
|
+
self.start_btn.configure(
|
|
868
|
+
state="normal", text=i18n.tr("取消"), command=self._cancel,
|
|
869
|
+
)
|
|
870
|
+
else:
|
|
871
|
+
self.start_btn.configure(
|
|
872
|
+
state="normal", text=i18n.tr("开始生成"),
|
|
873
|
+
command=self._start,
|
|
874
|
+
)
|
|
875
|
+
self.cancel_event = self.cancel_event if busy else None
|
|
818
876
|
if hasattr(self, "lang_btn"):
|
|
819
877
|
self.lang_btn.configure(state=state)
|
|
820
878
|
if hasattr(self, "update_btn"):
|
|
@@ -24,7 +24,10 @@ from .stats import (
|
|
|
24
24
|
fmt_human,
|
|
25
25
|
fmt_int,
|
|
26
26
|
language_breakdown,
|
|
27
|
+
month_labels,
|
|
28
|
+
month_numbers,
|
|
27
29
|
parse_daily,
|
|
30
|
+
peak_month,
|
|
28
31
|
window_months,
|
|
29
32
|
)
|
|
30
33
|
|
|
@@ -792,7 +795,9 @@ def build_records(stats: ReportStats) -> str:
|
|
|
792
795
|
|
|
793
796
|
def build_monthly(stats: ReportStats) -> str:
|
|
794
797
|
max_v = max(stats.monthly) or 1
|
|
795
|
-
|
|
798
|
+
labels = month_labels(stats)
|
|
799
|
+
numbers = month_numbers(stats)
|
|
800
|
+
_peak_idx, peak = peak_month(stats)
|
|
796
801
|
|
|
797
802
|
def column(month: int, value: int) -> str:
|
|
798
803
|
pct = max(value / max_v * 100, 1.5)
|
|
@@ -807,12 +812,15 @@ def build_monthly(stats: ReportStats) -> str:
|
|
|
807
812
|
f'<i style="height:{pct:.1f}%"></i>{label}</div>'
|
|
808
813
|
)
|
|
809
814
|
|
|
810
|
-
cols = "".join(
|
|
811
|
-
|
|
815
|
+
cols = "".join(
|
|
816
|
+
column(numbers[i] if i < len(numbers) else i + 1, v)
|
|
817
|
+
for i, v in enumerate(stats.monthly)
|
|
818
|
+
)
|
|
819
|
+
tick_html = "".join(f"<span>{escape(label)}</span>" for label in labels)
|
|
812
820
|
return _panel(
|
|
813
821
|
f"月度节奏 <b>· 峰值 {peak:02d} 月 · {max_v} 次</b>",
|
|
814
822
|
f'<div class="month-chart" role="img" aria-label="月度提交次数">{cols}</div>'
|
|
815
|
-
f'<div class="month-labels">{
|
|
823
|
+
f'<div class="month-labels">{tick_html}</div>',
|
|
816
824
|
span=True,
|
|
817
825
|
)
|
|
818
826
|
|
|
@@ -1186,9 +1194,12 @@ def build_compare(stats: ReportStats) -> str:
|
|
|
1186
1194
|
prev_monthly += [0] * (12 - len(prev_monthly))
|
|
1187
1195
|
cur_monthly = list(stats.monthly) + [0] * (12 - len(stats.monthly))
|
|
1188
1196
|
chart_max = max([1, *prev_monthly[:12], *cur_monthly[:12]])
|
|
1197
|
+
labels = month_labels(stats)
|
|
1198
|
+
numbers = month_numbers(stats)
|
|
1189
1199
|
cols = []
|
|
1190
1200
|
for i in range(12):
|
|
1191
1201
|
pv, cv = prev_monthly[i], cur_monthly[i]
|
|
1202
|
+
month_no = numbers[i] if i < len(numbers) else i + 1
|
|
1192
1203
|
pp = pv / chart_max * 100
|
|
1193
1204
|
cp = cv / chart_max * 100
|
|
1194
1205
|
prev_label = (
|
|
@@ -1200,24 +1211,26 @@ def build_compare(stats: ReportStats) -> str:
|
|
|
1200
1211
|
cols.append(
|
|
1201
1212
|
f'<div class="cmp-col"><div class="cmp-bars">'
|
|
1202
1213
|
f'<div class="cmp-bar prev"><i style="height:{pp:.1f}%" '
|
|
1203
|
-
f'data-tip="{prev_year} · {
|
|
1214
|
+
f'data-tip="{prev_year} · {month_no} 月 · {pv} 次提交"></i>'
|
|
1204
1215
|
f"{prev_label}</div>"
|
|
1205
1216
|
f'<div class="cmp-bar cur"><i style="height:{cp:.1f}%" '
|
|
1206
|
-
f'data-tip="{stats.year} · {
|
|
1217
|
+
f'data-tip="{stats.year} · {month_no} 月 · {cv} 次提交"></i>'
|
|
1207
1218
|
f"{cur_label}</div>"
|
|
1208
|
-
f'</div><span>{i + 1}</span></div>'
|
|
1219
|
+
f'</div><span>{escape(labels[i]) if i < len(labels) else i + 1}</span></div>'
|
|
1209
1220
|
)
|
|
1210
1221
|
notes = []
|
|
1211
1222
|
cur_peak = max(cur_monthly[:12])
|
|
1212
1223
|
prev_peak = max(prev_monthly[:12])
|
|
1213
1224
|
if cur_peak:
|
|
1225
|
+
ci = cur_monthly.index(cur_peak)
|
|
1214
1226
|
notes.append(
|
|
1215
|
-
f"<span>今年峰值 {
|
|
1227
|
+
f"<span>今年峰值 {numbers[ci] if ci < len(numbers) else ci + 1} 月 · "
|
|
1216
1228
|
f"{cur_peak:,} 次</span>"
|
|
1217
1229
|
)
|
|
1218
1230
|
if prev_peak:
|
|
1231
|
+
pi = prev_monthly.index(prev_peak)
|
|
1219
1232
|
notes.append(
|
|
1220
|
-
f"<span>去年峰值 {
|
|
1233
|
+
f"<span>去年峰值 {numbers[pi] if pi < len(numbers) else pi + 1} 月 · "
|
|
1221
1234
|
f"{prev_peak:,} 次</span>"
|
|
1222
1235
|
)
|
|
1223
1236
|
|