git-contribution-analyzer 0.8.0__py3-none-any.whl
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.
- git_contribution_analyzer/__init__.py +3 -0
- git_contribution_analyzer/adapters/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/local_identity.py +51 -0
- git_contribution_analyzer/adapters/git/native_git.py +353 -0
- git_contribution_analyzer/adapters/git/pydriller_history.py +57 -0
- git_contribution_analyzer/adapters/git/repository_discovery.py +75 -0
- git_contribution_analyzer/adapters/gui/__init__.py +1 -0
- git_contribution_analyzer/adapters/gui/app.py +63 -0
- git_contribution_analyzer/adapters/gui/controller.py +1084 -0
- git_contribution_analyzer/adapters/gui/models/__init__.py +3 -0
- git_contribution_analyzer/adapters/gui/models/base_table.py +108 -0
- git_contribution_analyzer/adapters/gui/settings.py +53 -0
- git_contribution_analyzer/adapters/gui/task_runner.py +196 -0
- git_contribution_analyzer/adapters/llm/__init__.py +1 -0
- git_contribution_analyzer/adapters/llm/anthropic.py +52 -0
- git_contribution_analyzer/adapters/llm/base.py +142 -0
- git_contribution_analyzer/adapters/llm/cache.py +148 -0
- git_contribution_analyzer/adapters/llm/claude_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/codex_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/command_base.py +153 -0
- git_contribution_analyzer/adapters/llm/mock.py +82 -0
- git_contribution_analyzer/adapters/llm/ollama.py +53 -0
- git_contribution_analyzer/adapters/llm/openai_compatible.py +61 -0
- git_contribution_analyzer/adapters/llm/registry.py +117 -0
- git_contribution_analyzer/adapters/mcp/__init__.py +13 -0
- git_contribution_analyzer/adapters/mcp/installer.py +175 -0
- git_contribution_analyzer/adapters/mcp/prompts_resources.py +218 -0
- git_contribution_analyzer/adapters/mcp/protocol.py +361 -0
- git_contribution_analyzer/adapters/mcp/server.py +52 -0
- git_contribution_analyzer/adapters/mcp/tools.py +621 -0
- git_contribution_analyzer/adapters/outcomes/__init__.py +1 -0
- git_contribution_analyzer/adapters/outcomes/yaml_loader.py +55 -0
- git_contribution_analyzer/adapters/outcomes/yaml_store.py +104 -0
- git_contribution_analyzer/adapters/reporting/__init__.py +1 -0
- git_contribution_analyzer/adapters/reporting/brag_markdown.py +115 -0
- git_contribution_analyzer/adapters/reporting/html_report.py +1413 -0
- git_contribution_analyzer/adapters/reporting/markdown.py +217 -0
- git_contribution_analyzer/adapters/reporting/portfolio_markdown.py +167 -0
- git_contribution_analyzer/adapters/reporting/recap_markdown.py +212 -0
- git_contribution_analyzer/adapters/reporting/resume_markdown.py +37 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_csv.py +117 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_markdown.py +90 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_series_markdown.py +31 -0
- git_contribution_analyzer/adapters/storage/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/analysis.py +708 -0
- git_contribution_analyzer/adapters/storage/sqlite/database.py +98 -0
- git_contribution_analyzer/adapters/storage/sqlite/git_index.py +482 -0
- git_contribution_analyzer/adapters/storage/sqlite/identity_merge.py +373 -0
- git_contribution_analyzer/adapters/storage/sqlite/llm_audit.py +109 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/env.py +34 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/script.py.mako +22 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0001_initial.py +51 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0002_git_index.py +146 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0003_analysis.py +79 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0004_llm_audit.py +69 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0005_run_types.py +42 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0006_identity_merges.py +83 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0007_structural_baselines.py +173 -0
- git_contribution_analyzer/adapters/storage/sqlite/models.py +354 -0
- git_contribution_analyzer/adapters/storage/sqlite/structural_baseline.py +841 -0
- git_contribution_analyzer/adapters/workspace/__init__.py +1 -0
- git_contribution_analyzer/adapters/workspace/config.py +135 -0
- git_contribution_analyzer/adapters/workspace/git_exclude.py +32 -0
- git_contribution_analyzer/adapters/workspace/layout.py +40 -0
- git_contribution_analyzer/adapters/workspace/locks.py +27 -0
- git_contribution_analyzer/adapters/workspace/portfolio_workspace.py +380 -0
- git_contribution_analyzer/adapters/workspace/ranking_config.py +17 -0
- git_contribution_analyzer/application/__init__.py +1 -0
- git_contribution_analyzer/application/dto/__init__.py +19 -0
- git_contribution_analyzer/application/dto/gui.py +86 -0
- git_contribution_analyzer/application/dto/results.py +21 -0
- git_contribution_analyzer/application/facades/__init__.py +3 -0
- git_contribution_analyzer/application/facades/gui.py +568 -0
- git_contribution_analyzer/application/ports/__init__.py +22 -0
- git_contribution_analyzer/application/ports/cancellation.py +50 -0
- git_contribution_analyzer/application/ports/git_history.py +22 -0
- git_contribution_analyzer/application/ports/llm.py +44 -0
- git_contribution_analyzer/application/ports/portfolio_store.py +34 -0
- git_contribution_analyzer/application/ports/progress.py +43 -0
- git_contribution_analyzer/application/ports/structural_baseline.py +93 -0
- git_contribution_analyzer/application/services/__init__.py +1 -0
- git_contribution_analyzer/application/services/assessment_explanation.py +127 -0
- git_contribution_analyzer/application/services/default_person.py +61 -0
- git_contribution_analyzer/application/services/evidence_snapshot.py +64 -0
- git_contribution_analyzer/application/services/person_selection.py +88 -0
- git_contribution_analyzer/application/services/resume_generation.py +318 -0
- git_contribution_analyzer/application/services/semantic_enhancement.py +157 -0
- git_contribution_analyzer/application/services/time_boundaries.py +49 -0
- git_contribution_analyzer/application/use_cases/__init__.py +1 -0
- git_contribution_analyzer/application/use_cases/analyze_contributions.py +276 -0
- git_contribution_analyzer/application/use_cases/analyze_project.py +295 -0
- git_contribution_analyzer/application/use_cases/assess_portfolio.py +327 -0
- git_contribution_analyzer/application/use_cases/assess_work.py +602 -0
- git_contribution_analyzer/application/use_cases/assess_work_series.py +212 -0
- git_contribution_analyzer/application/use_cases/compare_assessment_runs.py +121 -0
- git_contribution_analyzer/application/use_cases/export_report.py +49 -0
- git_contribution_analyzer/application/use_cases/generate_brag.py +308 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_recap.py +244 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_resume.py +152 -0
- git_contribution_analyzer/application/use_cases/generate_recap.py +316 -0
- git_contribution_analyzer/application/use_cases/generate_report.py +32 -0
- git_contribution_analyzer/application/use_cases/generate_resume.py +209 -0
- git_contribution_analyzer/application/use_cases/get_portfolio_status.py +83 -0
- git_contribution_analyzer/application/use_cases/get_run.py +16 -0
- git_contribution_analyzer/application/use_cases/get_status.py +69 -0
- git_contribution_analyzer/application/use_cases/index_repository.py +267 -0
- git_contribution_analyzer/application/use_cases/init_portfolio.py +89 -0
- git_contribution_analyzer/application/use_cases/init_project.py +71 -0
- git_contribution_analyzer/application/use_cases/list_identities.py +16 -0
- git_contribution_analyzer/application/use_cases/list_providers.py +29 -0
- git_contribution_analyzer/application/use_cases/list_runs.py +17 -0
- git_contribution_analyzer/application/use_cases/manage_identity_merges.py +48 -0
- git_contribution_analyzer/application/use_cases/manage_outcomes.py +189 -0
- git_contribution_analyzer/application/use_cases/manage_structural_baselines.py +262 -0
- git_contribution_analyzer/application/use_cases/map_identity.py +28 -0
- git_contribution_analyzer/application/use_cases/recover_runs.py +22 -0
- git_contribution_analyzer/application/use_cases/run_doctor.py +81 -0
- git_contribution_analyzer/application/use_cases/sync_portfolio.py +232 -0
- git_contribution_analyzer/application/use_cases/test_provider.py +22 -0
- git_contribution_analyzer/application/use_cases/uninit_project.py +23 -0
- git_contribution_analyzer/application/use_cases/verify_portfolio.py +165 -0
- git_contribution_analyzer/cli/__init__.py +1 -0
- git_contribution_analyzer/cli/app.py +1430 -0
- git_contribution_analyzer/cli/exit_codes.py +13 -0
- git_contribution_analyzer/cli/output.py +26 -0
- git_contribution_analyzer/cli/portfolio_commands.py +629 -0
- git_contribution_analyzer/domain/__init__.py +1 -0
- git_contribution_analyzer/domain/errors.py +55 -0
- git_contribution_analyzer/domain/models/__init__.py +3 -0
- git_contribution_analyzer/domain/models/analysis.py +29 -0
- git_contribution_analyzer/domain/models/assessment.py +12 -0
- git_contribution_analyzer/domain/models/brag.py +148 -0
- git_contribution_analyzer/domain/models/contribution.py +55 -0
- git_contribution_analyzer/domain/models/git_history.py +69 -0
- git_contribution_analyzer/domain/models/person_selection.py +46 -0
- git_contribution_analyzer/domain/models/portfolio.py +498 -0
- git_contribution_analyzer/domain/models/ranking.py +48 -0
- git_contribution_analyzer/domain/models/recap.py +235 -0
- git_contribution_analyzer/domain/models/repository.py +10 -0
- git_contribution_analyzer/domain/models/resume.py +59 -0
- git_contribution_analyzer/domain/models/run.py +10 -0
- git_contribution_analyzer/domain/models/semantic.py +34 -0
- git_contribution_analyzer/domain/models/snapshot.py +208 -0
- git_contribution_analyzer/domain/models/structural_baseline.py +120 -0
- git_contribution_analyzer/domain/models/work_assessment.py +81 -0
- git_contribution_analyzer/domain/services/assessment_periods.py +182 -0
- git_contribution_analyzer/domain/services/brag_rules.py +250 -0
- git_contribution_analyzer/domain/services/capability_rules.py +91 -0
- git_contribution_analyzer/domain/services/contribution_clustering.py +98 -0
- git_contribution_analyzer/domain/services/contribution_rules.py +79 -0
- git_contribution_analyzer/domain/services/difficulty_rules.py +191 -0
- git_contribution_analyzer/domain/services/dimensional_summary.py +117 -0
- git_contribution_analyzer/domain/services/portfolio_aggregation.py +250 -0
- git_contribution_analyzer/domain/services/portfolio_resume_rules.py +265 -0
- git_contribution_analyzer/domain/services/portfolio_verifier.py +238 -0
- git_contribution_analyzer/domain/services/ranking_rules.py +226 -0
- git_contribution_analyzer/domain/services/recap_rules.py +268 -0
- git_contribution_analyzer/domain/services/resume_claim_rules.py +70 -0
- git_contribution_analyzer/domain/services/structural_baseline.py +317 -0
- git_contribution_analyzer/domain/services/structural_signals.py +151 -0
- git_contribution_analyzer/domain/services/workload_rules.py +185 -0
- git_contribution_analyzer/gui/__init__.py +1 -0
- git_contribution_analyzer/gui/qml/Main.qml +1141 -0
- git_contribution_analyzer/gui/qml/__init__.py +1 -0
- git_contribution_analyzer/prompts/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/explanation.txt +4 -0
- git_contribution_analyzer/prompts/resume/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-concise.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-star.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-xyz.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/system.txt +3 -0
- git_contribution_analyzer/prompts/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/v1/capability_explanation.txt +2 -0
- git_contribution_analyzer/prompts/v1/contribution_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/overall_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/resume_bullet.txt +2 -0
- git_contribution_analyzer-0.8.0.dist-info/METADATA +667 -0
- git_contribution_analyzer-0.8.0.dist-info/RECORD +187 -0
- git_contribution_analyzer-0.8.0.dist-info/WHEEL +4 -0
- git_contribution_analyzer-0.8.0.dist-info/entry_points.txt +3 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/LICENSE +201 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/NOTICE +6 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from threading import Lock
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
11
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
12
|
+
from git_contribution_analyzer.application.ports.cancellation import (
|
|
13
|
+
CancellationToken,
|
|
14
|
+
NeverCancelledToken,
|
|
15
|
+
)
|
|
16
|
+
from git_contribution_analyzer.application.ports.progress import (
|
|
17
|
+
NullProgressReporter,
|
|
18
|
+
ProgressEvent,
|
|
19
|
+
ProgressReporter,
|
|
20
|
+
)
|
|
21
|
+
from git_contribution_analyzer.application.use_cases.index_repository import index_repository
|
|
22
|
+
from git_contribution_analyzer.application.use_cases.init_project import init_project
|
|
23
|
+
from git_contribution_analyzer.application.use_cases.list_identities import list_identities
|
|
24
|
+
from git_contribution_analyzer.application.use_cases.map_identity import map_identity
|
|
25
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError, GcaError
|
|
26
|
+
from git_contribution_analyzer.domain.models.portfolio import (
|
|
27
|
+
PortfolioIdentityRule,
|
|
28
|
+
PortfolioRepoSpec,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
RepoProgressCallback = Callable[[str, int, int, str], None]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def apply_portfolio_identities(
|
|
35
|
+
repo_path: Path,
|
|
36
|
+
rules: tuple[PortfolioIdentityRule, ...],
|
|
37
|
+
) -> int:
|
|
38
|
+
"""将 Portfolio 级精确邮箱/别名规则幂等地同步到单个成员仓."""
|
|
39
|
+
if not rules:
|
|
40
|
+
return 0
|
|
41
|
+
persons = list_identities(repo_path)["persons"]
|
|
42
|
+
mapped = 0
|
|
43
|
+
for rule in rules:
|
|
44
|
+
canonical_email_low = rule.canonical_email.lower()
|
|
45
|
+
alias_matchers = [
|
|
46
|
+
(alias.email.lower(), alias.name) for alias in rule.aliases
|
|
47
|
+
]
|
|
48
|
+
for person in persons:
|
|
49
|
+
person_email = str(person.get("email") or "").lower()
|
|
50
|
+
person_confirmed = bool(person.get("confirmed"))
|
|
51
|
+
for alias in person.get("aliases", []):
|
|
52
|
+
alias_email = str(alias.get("email") or "")
|
|
53
|
+
alias_name = str(alias.get("name") or "")
|
|
54
|
+
alias_email_low = alias_email.lower()
|
|
55
|
+
is_canonical_match = alias_email_low == canonical_email_low
|
|
56
|
+
is_alias_match = any(
|
|
57
|
+
email_low == alias_email_low
|
|
58
|
+
and (expected_name is None or expected_name == alias_name)
|
|
59
|
+
for email_low, expected_name in alias_matchers
|
|
60
|
+
)
|
|
61
|
+
if not (is_canonical_match or is_alias_match):
|
|
62
|
+
continue
|
|
63
|
+
if (
|
|
64
|
+
person_confirmed
|
|
65
|
+
and person_email == canonical_email_low
|
|
66
|
+
and bool(alias.get("confirmed"))
|
|
67
|
+
):
|
|
68
|
+
continue
|
|
69
|
+
map_identity(
|
|
70
|
+
repo_path,
|
|
71
|
+
name=alias_name,
|
|
72
|
+
email=alias_email,
|
|
73
|
+
person_name=rule.canonical_name,
|
|
74
|
+
person_email=rule.canonical_email,
|
|
75
|
+
)
|
|
76
|
+
mapped += 1
|
|
77
|
+
return mapped
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _sync_single_repo(
|
|
81
|
+
*,
|
|
82
|
+
repo: PortfolioRepoSpec,
|
|
83
|
+
repo_path: Path,
|
|
84
|
+
identities: tuple[PortfolioIdentityRule, ...],
|
|
85
|
+
full_rebuild: bool,
|
|
86
|
+
progress: ProgressReporter,
|
|
87
|
+
cancellation: CancellationToken,
|
|
88
|
+
) -> dict[str, Any]:
|
|
89
|
+
cancellation.raise_if_cancelled()
|
|
90
|
+
if not repo_path.is_dir():
|
|
91
|
+
raise GcaError(f"Repository path does not exist: {repo.repo_key}")
|
|
92
|
+
layout = WorkspaceLayout.for_repository(repo_path)
|
|
93
|
+
if not layout.root.is_dir():
|
|
94
|
+
init_project(
|
|
95
|
+
repo_path,
|
|
96
|
+
progress=progress,
|
|
97
|
+
cancellation=cancellation,
|
|
98
|
+
)
|
|
99
|
+
action = "initialized"
|
|
100
|
+
else:
|
|
101
|
+
index_repository(
|
|
102
|
+
repo_path,
|
|
103
|
+
full_rebuild=full_rebuild,
|
|
104
|
+
progress=progress,
|
|
105
|
+
cancellation=cancellation,
|
|
106
|
+
)
|
|
107
|
+
action = "rebuilt" if full_rebuild else "synced"
|
|
108
|
+
|
|
109
|
+
mapped_count = apply_portfolio_identities(repo_path, identities)
|
|
110
|
+
return {
|
|
111
|
+
"repoKey": repo.repo_key,
|
|
112
|
+
"group": repo.group,
|
|
113
|
+
"action": action,
|
|
114
|
+
"identitiesMapped": mapped_count,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def sync_portfolio(
|
|
119
|
+
portfolio_dir: Path,
|
|
120
|
+
*,
|
|
121
|
+
full_rebuild: bool = False,
|
|
122
|
+
continue_on_error: bool = True,
|
|
123
|
+
concurrency: int = 1,
|
|
124
|
+
progress: ProgressReporter | None = None,
|
|
125
|
+
cancellation: CancellationToken | None = None,
|
|
126
|
+
on_repo_progress: RepoProgressCallback | None = None,
|
|
127
|
+
) -> dict[str, Any]:
|
|
128
|
+
"""批量初始化/同步全部成员仓并统一应用 Portfolio 身份归一规则, 支持并发与逐仓进度."""
|
|
129
|
+
if concurrency < 1:
|
|
130
|
+
raise ConfigurationError("concurrency must be at least 1")
|
|
131
|
+
|
|
132
|
+
active_progress = progress or NullProgressReporter()
|
|
133
|
+
active_cancellation = cancellation or NeverCancelledToken()
|
|
134
|
+
store = FilePortfolioStore(portfolio_dir)
|
|
135
|
+
manifest = store.load_manifest()
|
|
136
|
+
|
|
137
|
+
repos = manifest.repositories
|
|
138
|
+
total = len(repos)
|
|
139
|
+
order_index = {repo.repo_key: idx for idx, repo in enumerate(repos)}
|
|
140
|
+
synced: list[dict[str, Any]] = []
|
|
141
|
+
failed: list[dict[str, str]] = []
|
|
142
|
+
completed_count = 0
|
|
143
|
+
progress_lock = Lock()
|
|
144
|
+
|
|
145
|
+
def _notify(repo: PortfolioRepoSpec, repo_path: Path, detail: str) -> None:
|
|
146
|
+
nonlocal completed_count
|
|
147
|
+
with progress_lock:
|
|
148
|
+
completed_count += 1
|
|
149
|
+
current = completed_count
|
|
150
|
+
active_progress.report(
|
|
151
|
+
ProgressEvent(
|
|
152
|
+
task_id=f"portfolio-sync:{manifest.name}",
|
|
153
|
+
operation="portfolio-sync",
|
|
154
|
+
stage="syncing",
|
|
155
|
+
repository=repo_path,
|
|
156
|
+
current=current,
|
|
157
|
+
total=total,
|
|
158
|
+
message=f"{repo.repo_key}: {detail}",
|
|
159
|
+
occurred_at=datetime.now(UTC),
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
if on_repo_progress is not None:
|
|
163
|
+
on_repo_progress(repo.repo_key, current, total, detail)
|
|
164
|
+
|
|
165
|
+
if concurrency == 1 or total <= 1:
|
|
166
|
+
for repo in repos:
|
|
167
|
+
active_cancellation.raise_if_cancelled()
|
|
168
|
+
repo_path = store.resolve_repo_path(repo)
|
|
169
|
+
try:
|
|
170
|
+
outcome = _sync_single_repo(
|
|
171
|
+
repo=repo,
|
|
172
|
+
repo_path=repo_path,
|
|
173
|
+
identities=manifest.identities,
|
|
174
|
+
full_rebuild=full_rebuild,
|
|
175
|
+
progress=active_progress,
|
|
176
|
+
cancellation=active_cancellation,
|
|
177
|
+
)
|
|
178
|
+
synced.append(outcome)
|
|
179
|
+
_notify(
|
|
180
|
+
repo,
|
|
181
|
+
repo_path,
|
|
182
|
+
f"{outcome['action']} ({outcome['identitiesMapped']} identities mapped)",
|
|
183
|
+
)
|
|
184
|
+
except GcaError as exc:
|
|
185
|
+
if not continue_on_error:
|
|
186
|
+
raise
|
|
187
|
+
failed.append({"repoKey": repo.repo_key, "error": str(exc)})
|
|
188
|
+
_notify(repo, repo_path, f"failed ({exc})")
|
|
189
|
+
else:
|
|
190
|
+
max_workers = min(concurrency, total)
|
|
191
|
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
192
|
+
future_map = {
|
|
193
|
+
executor.submit(
|
|
194
|
+
_sync_single_repo,
|
|
195
|
+
repo=repo,
|
|
196
|
+
repo_path=store.resolve_repo_path(repo),
|
|
197
|
+
identities=manifest.identities,
|
|
198
|
+
full_rebuild=full_rebuild,
|
|
199
|
+
progress=active_progress,
|
|
200
|
+
cancellation=active_cancellation,
|
|
201
|
+
): (repo, store.resolve_repo_path(repo))
|
|
202
|
+
for repo in repos
|
|
203
|
+
}
|
|
204
|
+
for future in as_completed(future_map):
|
|
205
|
+
repo, repo_path = future_map[future]
|
|
206
|
+
try:
|
|
207
|
+
outcome = future.result()
|
|
208
|
+
synced.append(outcome)
|
|
209
|
+
_notify(
|
|
210
|
+
repo,
|
|
211
|
+
repo_path,
|
|
212
|
+
f"{outcome['action']} ({outcome['identitiesMapped']} identities mapped)",
|
|
213
|
+
)
|
|
214
|
+
except GcaError as exc:
|
|
215
|
+
if not continue_on_error:
|
|
216
|
+
raise
|
|
217
|
+
failed.append({"repoKey": repo.repo_key, "error": str(exc)})
|
|
218
|
+
_notify(repo, repo_path, f"failed ({exc})")
|
|
219
|
+
|
|
220
|
+
synced.sort(key=lambda item: order_index[str(item["repoKey"])])
|
|
221
|
+
failed.sort(key=lambda item: order_index[str(item["repoKey"])])
|
|
222
|
+
|
|
223
|
+
status = "COMPLETED" if not failed else ("PARTIAL" if synced else "FAILED")
|
|
224
|
+
return {
|
|
225
|
+
"portfolioName": manifest.name,
|
|
226
|
+
"status": status,
|
|
227
|
+
"totalRepositories": total,
|
|
228
|
+
"syncedRepositories": len(synced),
|
|
229
|
+
"failedRepositories": len(failed),
|
|
230
|
+
"synced": synced,
|
|
231
|
+
"failed": failed,
|
|
232
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
7
|
+
from git_contribution_analyzer.adapters.llm.registry import build_provider
|
|
8
|
+
from git_contribution_analyzer.adapters.workspace.config import load_config
|
|
9
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_provider(path: Path) -> dict[str, Any]:
|
|
13
|
+
repository = discover_repository(path)
|
|
14
|
+
config = load_config(WorkspaceLayout.for_repository(repository.root).config)
|
|
15
|
+
provider = build_provider(config.llm)
|
|
16
|
+
healthy = provider.health_check()
|
|
17
|
+
return {
|
|
18
|
+
"provider": provider.provider_id,
|
|
19
|
+
"model": provider.model,
|
|
20
|
+
"healthy": healthy,
|
|
21
|
+
"localExecution": provider.capabilities.local_execution,
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
7
|
+
from git_contribution_analyzer.adapters.workspace.git_exclude import remove_workspace_exclusion
|
|
8
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
9
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def uninit_project(path: Path) -> bool:
|
|
13
|
+
repository = discover_repository(path)
|
|
14
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
15
|
+
if layout.root.parent != repository.root or layout.root.name != ".gca":
|
|
16
|
+
raise WorkspaceError(f"Refusing to delete unsafe workspace path: {layout.root}")
|
|
17
|
+
if layout.root.is_symlink():
|
|
18
|
+
raise WorkspaceError(f"Refusing to delete symlink workspace: {layout.root}")
|
|
19
|
+
existed = layout.root.exists()
|
|
20
|
+
if existed:
|
|
21
|
+
shutil.rmtree(layout.root)
|
|
22
|
+
remove_workspace_exclusion(repository.root)
|
|
23
|
+
return existed
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from collections.abc import Set as AbstractSet
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer.adapters.storage.sqlite.analysis import SqliteAnalysisStore
|
|
10
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
11
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
12
|
+
from git_contribution_analyzer.domain.errors import ReportError
|
|
13
|
+
from git_contribution_analyzer.domain.models.portfolio import PortfolioVerificationIssue
|
|
14
|
+
from git_contribution_analyzer.domain.services.portfolio_verifier import (
|
|
15
|
+
verify_portfolio_markdown_references,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _check_summary_internal_consistency(
|
|
20
|
+
payload: dict[str, Any],
|
|
21
|
+
) -> list[PortfolioVerificationIssue]:
|
|
22
|
+
issues: list[PortfolioVerificationIssue] = []
|
|
23
|
+
repos = payload.get("repositories", [])
|
|
24
|
+
totals = payload.get("totals", {})
|
|
25
|
+
groups = payload.get("groups", [])
|
|
26
|
+
scope = payload.get("scope", {})
|
|
27
|
+
|
|
28
|
+
if int(scope.get("matchedRepositories", -1)) != len(repos):
|
|
29
|
+
issues.append(
|
|
30
|
+
PortfolioVerificationIssue(
|
|
31
|
+
code="MATCHED_REPO_COUNT_MISMATCH",
|
|
32
|
+
message="scope.matchedRepositories does not equal len(repositories)",
|
|
33
|
+
location="scope.matchedRepositories",
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
for total_key, repo_key in (
|
|
38
|
+
("commits", "commits"),
|
|
39
|
+
("deliveredCommits", "delivered"),
|
|
40
|
+
("authoredOnlyCommits", "authoredOnly"),
|
|
41
|
+
("completedItems", "completedItems"),
|
|
42
|
+
("pendingItems", "pendingItems"),
|
|
43
|
+
):
|
|
44
|
+
expected = sum(int(item.get(repo_key, 0)) for item in repos)
|
|
45
|
+
actual = int(totals.get(total_key, -1))
|
|
46
|
+
if actual != expected:
|
|
47
|
+
issues.append(
|
|
48
|
+
PortfolioVerificationIssue(
|
|
49
|
+
code="TOTAL_METRIC_MISMATCH",
|
|
50
|
+
message=(
|
|
51
|
+
f"totals.{total_key}={actual} != "
|
|
52
|
+
f"sum(repositories.{repo_key})={expected}"
|
|
53
|
+
),
|
|
54
|
+
location=f"totals.{total_key}",
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
for group in groups:
|
|
59
|
+
g_name = str(group.get("name", ""))
|
|
60
|
+
members = [item for item in repos if item.get("group") == g_name]
|
|
61
|
+
if int(group.get("commits", -1)) != sum(int(item.get("commits", 0)) for item in members):
|
|
62
|
+
issues.append(
|
|
63
|
+
PortfolioVerificationIssue(
|
|
64
|
+
code="GROUP_METRIC_MISMATCH",
|
|
65
|
+
message=f"groups.{g_name}.commits mismatch",
|
|
66
|
+
location=f"groups.{g_name}",
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
structural = payload.get("structuralObservation", {})
|
|
71
|
+
if structural.get("affectsDifficultyRankingOrResume") is not False:
|
|
72
|
+
issues.append(
|
|
73
|
+
PortfolioVerificationIssue(
|
|
74
|
+
code="STRUCTURAL_OBSERVATION_VIOLATION",
|
|
75
|
+
message="structuralObservation.affectsDifficultyRankingOrResume must be false",
|
|
76
|
+
location="structuralObservation",
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
return issues
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _collect_evidence_index(portfolio_dir: Path) -> dict[str, set[str]]:
|
|
83
|
+
store = FilePortfolioStore(portfolio_dir)
|
|
84
|
+
manifest = store.load_manifest()
|
|
85
|
+
index: dict[str, set[str]] = {}
|
|
86
|
+
for repo in manifest.repositories:
|
|
87
|
+
repo_path = store.resolve_repo_path(repo)
|
|
88
|
+
layout = WorkspaceLayout.for_repository(repo_path)
|
|
89
|
+
ev_set: set[str] = set()
|
|
90
|
+
if layout.database.is_file():
|
|
91
|
+
analysis_store = SqliteAnalysisStore(layout.database, str(repo_path.resolve()))
|
|
92
|
+
for run in analysis_store.list_runs():
|
|
93
|
+
try:
|
|
94
|
+
run_payload = analysis_store.get_report(str(run["id"]))
|
|
95
|
+
except ReportError:
|
|
96
|
+
continue
|
|
97
|
+
for entry in run_payload.get("evidence", []):
|
|
98
|
+
raw_id = str(entry.get("id") or "")
|
|
99
|
+
if raw_id:
|
|
100
|
+
ev_set.add(raw_id.split(":")[-1])
|
|
101
|
+
index[repo.repo_key] = ev_set
|
|
102
|
+
return index
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def verify_portfolio(
|
|
106
|
+
portfolio_dir: Path,
|
|
107
|
+
*,
|
|
108
|
+
run_id: str = "latest",
|
|
109
|
+
resume_markdown_path: Path | None = None,
|
|
110
|
+
evidence_index_override: Mapping[str, AbstractSet[str]] | None = None,
|
|
111
|
+
) -> dict[str, Any]:
|
|
112
|
+
"""离线校验持久化 Portfolio 运行记录的账实一致性及衍生简历的 `<repoKey>:EV-xxx` 回溯."""
|
|
113
|
+
store = FilePortfolioStore(portfolio_dir)
|
|
114
|
+
payload = store.load_run(run_id)
|
|
115
|
+
report_type = str(payload.get("reportType") or "")
|
|
116
|
+
|
|
117
|
+
issues: list[PortfolioVerificationIssue] = []
|
|
118
|
+
checked_repos = 0
|
|
119
|
+
checked_refs = 0
|
|
120
|
+
|
|
121
|
+
if report_type == "PORTFOLIO_SUMMARY":
|
|
122
|
+
checked_repos = len(payload.get("repositories", []))
|
|
123
|
+
issues.extend(_check_summary_internal_consistency(payload))
|
|
124
|
+
elif report_type == "PORTFOLIO_RESUME":
|
|
125
|
+
checked_repos = sum(
|
|
126
|
+
int(group.get("repositories", 0)) for group in payload.get("projectGroups", [])
|
|
127
|
+
)
|
|
128
|
+
# 检查简历 JSON 中每条 bullet 是否带 <repoKey>:EV-xxx
|
|
129
|
+
rendered = json.dumps(payload, ensure_ascii=False)
|
|
130
|
+
evidence_index = (
|
|
131
|
+
evidence_index_override
|
|
132
|
+
if evidence_index_override is not None
|
|
133
|
+
else _collect_evidence_index(portfolio_dir)
|
|
134
|
+
)
|
|
135
|
+
md_check = verify_portfolio_markdown_references(rendered, evidence_index)
|
|
136
|
+
issues.extend(md_check.issues)
|
|
137
|
+
checked_refs += md_check.checked_evidence_references
|
|
138
|
+
else:
|
|
139
|
+
raise ReportError(f"Unsupported portfolio run reportType: {report_type!r}")
|
|
140
|
+
|
|
141
|
+
if resume_markdown_path is not None:
|
|
142
|
+
if not resume_markdown_path.is_file():
|
|
143
|
+
raise ReportError(f"Resume markdown file not found: {resume_markdown_path}")
|
|
144
|
+
evidence_index = (
|
|
145
|
+
evidence_index_override
|
|
146
|
+
if evidence_index_override is not None
|
|
147
|
+
else _collect_evidence_index(portfolio_dir)
|
|
148
|
+
)
|
|
149
|
+
md_report = verify_portfolio_markdown_references(
|
|
150
|
+
resume_markdown_path.read_text(encoding="utf-8"),
|
|
151
|
+
evidence_index,
|
|
152
|
+
)
|
|
153
|
+
issues.extend(md_report.issues)
|
|
154
|
+
checked_refs += md_report.checked_evidence_references
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
"ok": not issues,
|
|
158
|
+
"reportType": report_type,
|
|
159
|
+
"checkedRepositories": checked_repos,
|
|
160
|
+
"checkedEvidenceReferences": checked_refs,
|
|
161
|
+
"issues": [
|
|
162
|
+
{"code": i.code, "message": i.message, "location": i.location}
|
|
163
|
+
for i in issues
|
|
164
|
+
],
|
|
165
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command-line interface."""
|