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,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
8
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import (
|
|
9
|
+
check_database,
|
|
10
|
+
initialize_database,
|
|
11
|
+
)
|
|
12
|
+
from git_contribution_analyzer.adapters.storage.sqlite.git_index import SqliteGitIndexStore
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.structural_baseline import (
|
|
14
|
+
SqliteStructuralBaselineStore,
|
|
15
|
+
)
|
|
16
|
+
from git_contribution_analyzer.adapters.workspace.config import load_config
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_status(path: Path) -> dict[str, Any]:
|
|
21
|
+
repository = discover_repository(path)
|
|
22
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
23
|
+
initialized = layout.root.is_dir()
|
|
24
|
+
metadata: dict[str, Any] = {}
|
|
25
|
+
default_branch: str | None = None
|
|
26
|
+
if initialized and layout.metadata.is_file():
|
|
27
|
+
metadata = json.loads(layout.metadata.read_text(encoding="utf-8"))
|
|
28
|
+
if initialized and layout.config.is_file():
|
|
29
|
+
default_branch = load_config(layout.config).default_branch
|
|
30
|
+
if initialized and layout.database.is_file():
|
|
31
|
+
initialize_database(layout.database)
|
|
32
|
+
stats = {
|
|
33
|
+
"indexedCommits": 0,
|
|
34
|
+
"identities": 0,
|
|
35
|
+
"unresolvedIdentities": 0,
|
|
36
|
+
"refs": 0,
|
|
37
|
+
}
|
|
38
|
+
database_healthy = check_database(layout.database) if initialized else False
|
|
39
|
+
if database_healthy:
|
|
40
|
+
store = SqliteGitIndexStore(layout.database, str(repository.root))
|
|
41
|
+
stats = store.stats()
|
|
42
|
+
structural = (
|
|
43
|
+
SqliteStructuralBaselineStore(layout.database, str(repository.root)).status()
|
|
44
|
+
if database_healthy
|
|
45
|
+
else {
|
|
46
|
+
"baselineCount": 0,
|
|
47
|
+
"latestBaselineId": None,
|
|
48
|
+
"processedCommits": 0,
|
|
49
|
+
"unhealthyBaselines": 0,
|
|
50
|
+
"orphanBaselines": 0,
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
return {
|
|
54
|
+
"repository": str(repository.root),
|
|
55
|
+
"gitDir": str(repository.git_dir),
|
|
56
|
+
"workspace": str(layout.root),
|
|
57
|
+
"workspaceInitialized": initialized,
|
|
58
|
+
"databaseHealthy": database_healthy,
|
|
59
|
+
"defaultBranch": default_branch,
|
|
60
|
+
"toolVersion": metadata.get("toolVersion"),
|
|
61
|
+
"schemaVersion": metadata.get("schemaVersion"),
|
|
62
|
+
"indexedCommit": metadata.get("indexedCommit"),
|
|
63
|
+
**stats,
|
|
64
|
+
"lastSync": metadata.get("lastSync"),
|
|
65
|
+
"indexStatus": metadata.get(
|
|
66
|
+
"indexStatus", "not-indexed" if initialized else "not-initialized"
|
|
67
|
+
),
|
|
68
|
+
"structural": structural,
|
|
69
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from datetime import UTC, datetime
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
from uuid import uuid4
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer import __version__
|
|
10
|
+
from git_contribution_analyzer.adapters.git.native_git import NativeGitHistory
|
|
11
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
12
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import initialize_database
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.git_index import SqliteGitIndexStore
|
|
14
|
+
from git_contribution_analyzer.adapters.storage.sqlite.structural_baseline import (
|
|
15
|
+
SqliteStructuralBaselineStore,
|
|
16
|
+
)
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.config import load_config
|
|
18
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
19
|
+
from git_contribution_analyzer.adapters.workspace.locks import workspace_lock
|
|
20
|
+
from git_contribution_analyzer.application.ports.cancellation import (
|
|
21
|
+
CancellationToken,
|
|
22
|
+
NeverCancelledToken,
|
|
23
|
+
)
|
|
24
|
+
from git_contribution_analyzer.application.ports.progress import (
|
|
25
|
+
NullProgressReporter,
|
|
26
|
+
ProgressEvent,
|
|
27
|
+
ProgressReporter,
|
|
28
|
+
)
|
|
29
|
+
from git_contribution_analyzer.application.ports.structural_baseline import (
|
|
30
|
+
StructuralBaselineStore,
|
|
31
|
+
)
|
|
32
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
33
|
+
from git_contribution_analyzer.domain.models.git_history import CommitDelivery, GitCommit
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def index_repository(
|
|
37
|
+
path: Path,
|
|
38
|
+
*,
|
|
39
|
+
full_rebuild: bool,
|
|
40
|
+
progress: ProgressReporter | None = None,
|
|
41
|
+
cancellation: CancellationToken | None = None,
|
|
42
|
+
) -> dict[str, Any]:
|
|
43
|
+
active_progress = progress or NullProgressReporter()
|
|
44
|
+
active_cancellation = cancellation or NeverCancelledToken()
|
|
45
|
+
active_cancellation.raise_if_cancelled()
|
|
46
|
+
repository = discover_repository(path)
|
|
47
|
+
task_id = str(uuid4())
|
|
48
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
49
|
+
if not layout.root.is_dir():
|
|
50
|
+
raise WorkspaceError("GCA workspace is not initialized; run 'gca init' first")
|
|
51
|
+
config = load_config(layout.config)
|
|
52
|
+
history = NativeGitHistory(repository.root)
|
|
53
|
+
|
|
54
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
55
|
+
initialize_database(layout.database)
|
|
56
|
+
store = SqliteGitIndexStore(layout.database, str(repository.root))
|
|
57
|
+
active_cancellation.raise_if_cancelled()
|
|
58
|
+
active_progress.report(
|
|
59
|
+
_event(task_id, repository.root, "reading_commits", "Reading Git commits")
|
|
60
|
+
)
|
|
61
|
+
all_hashes = history.list_commit_hashes()
|
|
62
|
+
existing = set() if full_rebuild else store.existing_commit_hashes()
|
|
63
|
+
new_hashes = tuple(commit_hash for commit_hash in all_hashes if commit_hash not in existing)
|
|
64
|
+
new_commits = history.read_commits(new_hashes)
|
|
65
|
+
|
|
66
|
+
active_cancellation.raise_if_cancelled()
|
|
67
|
+
active_progress.report(
|
|
68
|
+
_event(
|
|
69
|
+
task_id,
|
|
70
|
+
repository.root,
|
|
71
|
+
"resolving_delivery",
|
|
72
|
+
"Resolving delivery status",
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
existing_relations = [] if full_rebuild else store.relation_summaries()
|
|
76
|
+
relation_rows = existing_relations + [_relation_row(commit) for commit in new_commits]
|
|
77
|
+
deliveries = _resolve_delivery(history, relation_rows, config.default_branch)
|
|
78
|
+
git_refs = history.list_refs()
|
|
79
|
+
active_cancellation.raise_if_cancelled()
|
|
80
|
+
active_progress.report(
|
|
81
|
+
_event(task_id, repository.root, "writing_index", "Writing repository index")
|
|
82
|
+
)
|
|
83
|
+
store.write_index(
|
|
84
|
+
git_refs,
|
|
85
|
+
new_commits,
|
|
86
|
+
deliveries,
|
|
87
|
+
clear_existing=full_rebuild,
|
|
88
|
+
default_branch=config.default_branch,
|
|
89
|
+
)
|
|
90
|
+
structural_store: StructuralBaselineStore = SqliteStructuralBaselineStore(
|
|
91
|
+
layout.database, str(repository.root)
|
|
92
|
+
)
|
|
93
|
+
structural_stats = structural_store.sync_commit_facts(
|
|
94
|
+
new_commits,
|
|
95
|
+
clear_existing=full_rebuild,
|
|
96
|
+
)
|
|
97
|
+
stale_baselines = _mark_unreachable_structural_baselines(
|
|
98
|
+
history,
|
|
99
|
+
structural_store,
|
|
100
|
+
)
|
|
101
|
+
structural_stats = {**structural_stats, "staleBaselines": stale_baselines}
|
|
102
|
+
stats = store.stats()
|
|
103
|
+
_update_metadata(layout, stats, git_refs, config.default_branch)
|
|
104
|
+
|
|
105
|
+
result = {
|
|
106
|
+
**stats,
|
|
107
|
+
"newCommits": len(new_commits),
|
|
108
|
+
"targetRef": f"refs/heads/{config.default_branch}",
|
|
109
|
+
"indexStatus": "up-to-date",
|
|
110
|
+
"structuralFacts": structural_stats,
|
|
111
|
+
}
|
|
112
|
+
active_progress.report(
|
|
113
|
+
ProgressEvent(
|
|
114
|
+
task_id=task_id,
|
|
115
|
+
operation="index" if full_rebuild else "sync",
|
|
116
|
+
stage="completed",
|
|
117
|
+
repository=repository.root,
|
|
118
|
+
current=1,
|
|
119
|
+
total=1,
|
|
120
|
+
message="Repository index updated",
|
|
121
|
+
occurred_at=datetime.now(UTC),
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _mark_unreachable_structural_baselines(
|
|
128
|
+
history: NativeGitHistory,
|
|
129
|
+
store: StructuralBaselineStore,
|
|
130
|
+
) -> int:
|
|
131
|
+
stale_ids: list[str] = []
|
|
132
|
+
reachable_by_branch: dict[str, set[str]] = {}
|
|
133
|
+
for baseline in store.completed_baseline_refs():
|
|
134
|
+
baseline_commit = baseline["baselineCommit"]
|
|
135
|
+
if baseline_commit is None:
|
|
136
|
+
continue
|
|
137
|
+
branch = str(baseline["branch"])
|
|
138
|
+
reachable = reachable_by_branch.get(branch)
|
|
139
|
+
if reachable is None:
|
|
140
|
+
try:
|
|
141
|
+
reachable = set(history.reachable_commits(branch))
|
|
142
|
+
except WorkspaceError:
|
|
143
|
+
continue
|
|
144
|
+
reachable_by_branch[branch] = reachable
|
|
145
|
+
if baseline_commit not in reachable:
|
|
146
|
+
stale_ids.append(str(baseline["baselineId"]))
|
|
147
|
+
return store.mark_stale(stale_ids)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _event(task_id: str, repository: Path, stage: str, message: str) -> ProgressEvent:
|
|
151
|
+
return ProgressEvent(
|
|
152
|
+
task_id=task_id,
|
|
153
|
+
operation="index",
|
|
154
|
+
stage=stage,
|
|
155
|
+
repository=repository,
|
|
156
|
+
message=message,
|
|
157
|
+
occurred_at=datetime.now(UTC),
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _relation_row(commit: GitCommit) -> dict[str, Any]:
|
|
162
|
+
return {
|
|
163
|
+
"hash": commit.hash,
|
|
164
|
+
"patch_id": commit.patch_id,
|
|
165
|
+
"reverts_hash": commit.reverts_hash,
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _resolve_delivery(
|
|
170
|
+
history: NativeGitHistory,
|
|
171
|
+
relations: list[dict[str, Any]],
|
|
172
|
+
default_branch: str,
|
|
173
|
+
) -> tuple[CommitDelivery, ...]:
|
|
174
|
+
target_ref = f"refs/heads/{default_branch}"
|
|
175
|
+
hashes = tuple(str(row["hash"]) for row in relations)
|
|
176
|
+
landed_hashes = history.reachable_commits(target_ref).intersection(hashes)
|
|
177
|
+
release_tags = history.first_release_tags(landed_hashes)
|
|
178
|
+
deliveries: dict[str, CommitDelivery] = {}
|
|
179
|
+
for row in relations:
|
|
180
|
+
commit_hash = str(row["hash"])
|
|
181
|
+
landed = commit_hash in landed_hashes
|
|
182
|
+
release_ref = release_tags.get(commit_hash)
|
|
183
|
+
status = "RELEASED" if release_ref else "LANDED" if landed else "AUTHORED_ONLY"
|
|
184
|
+
deliveries[commit_hash] = CommitDelivery(
|
|
185
|
+
commit_hash=commit_hash,
|
|
186
|
+
target_ref=target_ref,
|
|
187
|
+
status=status,
|
|
188
|
+
release_ref=release_ref,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
delivered_by_patch: dict[str, str] = {}
|
|
192
|
+
for row in relations:
|
|
193
|
+
patch_id = row.get("patch_id")
|
|
194
|
+
delivery = deliveries[str(row["hash"])]
|
|
195
|
+
if patch_id and delivery.status in {"LANDED", "RELEASED"}:
|
|
196
|
+
delivered_by_patch.setdefault(str(patch_id), delivery.commit_hash)
|
|
197
|
+
for row in relations:
|
|
198
|
+
patch_id = row.get("patch_id")
|
|
199
|
+
commit_hash = str(row["hash"])
|
|
200
|
+
duplicate = delivered_by_patch.get(str(patch_id)) if patch_id else None
|
|
201
|
+
if (
|
|
202
|
+
duplicate
|
|
203
|
+
and duplicate != commit_hash
|
|
204
|
+
and deliveries[commit_hash].status == "AUTHORED_ONLY"
|
|
205
|
+
):
|
|
206
|
+
current = deliveries[commit_hash]
|
|
207
|
+
deliveries[commit_hash] = CommitDelivery(
|
|
208
|
+
commit_hash=commit_hash,
|
|
209
|
+
target_ref=target_ref,
|
|
210
|
+
status=current.status,
|
|
211
|
+
release_ref=current.release_ref,
|
|
212
|
+
related_commit_hash=duplicate,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
for row in relations:
|
|
216
|
+
reverted_prefix = row.get("reverts_hash")
|
|
217
|
+
revert_hash = str(row["hash"])
|
|
218
|
+
if not reverted_prefix or deliveries[revert_hash].status not in {"LANDED", "RELEASED"}:
|
|
219
|
+
continue
|
|
220
|
+
reverted_hash = next(
|
|
221
|
+
(commit_hash for commit_hash in hashes if commit_hash.startswith(str(reverted_prefix))),
|
|
222
|
+
None,
|
|
223
|
+
)
|
|
224
|
+
if reverted_hash is None:
|
|
225
|
+
continue
|
|
226
|
+
current = deliveries[reverted_hash]
|
|
227
|
+
deliveries[reverted_hash] = CommitDelivery(
|
|
228
|
+
commit_hash=reverted_hash,
|
|
229
|
+
target_ref=target_ref,
|
|
230
|
+
status="REVERTED",
|
|
231
|
+
release_ref=current.release_ref,
|
|
232
|
+
related_commit_hash=revert_hash,
|
|
233
|
+
)
|
|
234
|
+
return tuple(deliveries[commit_hash] for commit_hash in hashes)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _update_metadata(
|
|
238
|
+
layout: WorkspaceLayout,
|
|
239
|
+
stats: dict[str, int],
|
|
240
|
+
git_refs: tuple[Any, ...],
|
|
241
|
+
default_branch: str,
|
|
242
|
+
) -> None:
|
|
243
|
+
metadata = json.loads(layout.metadata.read_text(encoding="utf-8"))
|
|
244
|
+
target_ref = f"refs/heads/{default_branch}"
|
|
245
|
+
now = datetime.now(UTC).isoformat()
|
|
246
|
+
indexed_commit = next(
|
|
247
|
+
(git_ref.commit_hash for git_ref in git_refs if git_ref.name == target_ref),
|
|
248
|
+
None,
|
|
249
|
+
)
|
|
250
|
+
metadata.update(
|
|
251
|
+
{
|
|
252
|
+
"toolVersion": __version__,
|
|
253
|
+
"indexedCommit": indexed_commit,
|
|
254
|
+
"indexedCommits": stats["indexedCommits"],
|
|
255
|
+
"identities": stats["identities"],
|
|
256
|
+
"unresolvedIdentities": stats["unresolvedIdentities"],
|
|
257
|
+
"refs": stats["refs"],
|
|
258
|
+
"updatedAt": now,
|
|
259
|
+
"lastSync": now,
|
|
260
|
+
"indexStatus": "up-to-date",
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
layout.metadata.write_text(
|
|
264
|
+
json.dumps(metadata, ensure_ascii=False, indent=2) + "\n",
|
|
265
|
+
encoding="utf-8",
|
|
266
|
+
newline="\n",
|
|
267
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import (
|
|
9
|
+
FilePortfolioStore,
|
|
10
|
+
discover_git_repositories,
|
|
11
|
+
)
|
|
12
|
+
from git_contribution_analyzer.domain.models.portfolio import (
|
|
13
|
+
PortfolioIdentityRule,
|
|
14
|
+
PortfolioManifest,
|
|
15
|
+
PortfolioRepoSpec,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
SANITIZE_KEY_RE = re.compile(r"[^A-Za-z0-9_.-]+")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _sanitize_repo_key(raw_name: str) -> str:
|
|
22
|
+
cleaned = SANITIZE_KEY_RE.sub("-", raw_name.strip()).strip("-")
|
|
23
|
+
return cleaned or "repo"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _relative_or_posix(target: Path, base: Path) -> str:
|
|
27
|
+
try:
|
|
28
|
+
return Path(os.path.relpath(target.resolve(), base.resolve())).as_posix()
|
|
29
|
+
except ValueError:
|
|
30
|
+
return target.resolve().as_posix()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def init_portfolio(
|
|
34
|
+
portfolio_dir: Path,
|
|
35
|
+
*,
|
|
36
|
+
name: str | None = None,
|
|
37
|
+
scan_roots: tuple[Path, ...] = (),
|
|
38
|
+
group_name: str = "default",
|
|
39
|
+
identities: tuple[PortfolioIdentityRule, ...] = (),
|
|
40
|
+
exclude_patterns: tuple[str, ...] = (),
|
|
41
|
+
) -> dict[str, Any]:
|
|
42
|
+
"""初始化 `.gca-portfolio/` 工作区与声明式 `portfolio.yml` 清单."""
|
|
43
|
+
store = FilePortfolioStore(portfolio_dir)
|
|
44
|
+
portfolio_name = name or store.portfolio_root.name or "portfolio"
|
|
45
|
+
|
|
46
|
+
discovered_paths = discover_git_repositories(scan_roots, exclude_patterns=exclude_patterns)
|
|
47
|
+
used_keys: set[str] = set()
|
|
48
|
+
repo_specs: list[PortfolioRepoSpec] = []
|
|
49
|
+
|
|
50
|
+
for repo_path in discovered_paths:
|
|
51
|
+
base_key = _sanitize_repo_key(repo_path.name)
|
|
52
|
+
repo_key = base_key
|
|
53
|
+
if repo_key in used_keys:
|
|
54
|
+
parent_key = _sanitize_repo_key(repo_path.parent.name)
|
|
55
|
+
repo_key = f"{parent_key}--{base_key}"
|
|
56
|
+
suffix = 2
|
|
57
|
+
while repo_key in used_keys:
|
|
58
|
+
repo_key = f"{base_key}-{suffix}"
|
|
59
|
+
suffix += 1
|
|
60
|
+
used_keys.add(repo_key)
|
|
61
|
+
|
|
62
|
+
repo_specs.append(
|
|
63
|
+
PortfolioRepoSpec(
|
|
64
|
+
repo_key=repo_key,
|
|
65
|
+
group=group_name,
|
|
66
|
+
path=_relative_or_posix(repo_path, store.portfolio_root),
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
manifest = PortfolioManifest(
|
|
71
|
+
name=portfolio_name,
|
|
72
|
+
repositories=tuple(repo_specs),
|
|
73
|
+
identities=identities,
|
|
74
|
+
discovery_roots=tuple(
|
|
75
|
+
_relative_or_posix(root, store.portfolio_root) for root in scan_roots
|
|
76
|
+
),
|
|
77
|
+
exclude_patterns=exclude_patterns,
|
|
78
|
+
)
|
|
79
|
+
store.initialize(manifest)
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
"portfolioName": manifest.name,
|
|
83
|
+
"manifest": str(store.layout.manifest),
|
|
84
|
+
"workspace": str(store.layout.root),
|
|
85
|
+
"discoveredRepositories": len(repo_specs),
|
|
86
|
+
"repositories": [
|
|
87
|
+
{"repoKey": r.repo_key, "group": r.group, "path": r.path} for r in repo_specs
|
|
88
|
+
],
|
|
89
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from datetime import UTC, datetime
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer import __version__
|
|
8
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import (
|
|
9
|
+
detect_current_branch,
|
|
10
|
+
discover_repository,
|
|
11
|
+
)
|
|
12
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import (
|
|
13
|
+
initialize_database,
|
|
14
|
+
upsert_repository,
|
|
15
|
+
)
|
|
16
|
+
from git_contribution_analyzer.adapters.workspace.config import write_default_config
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.git_exclude import ensure_workspace_excluded
|
|
18
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
19
|
+
from git_contribution_analyzer.adapters.workspace.locks import workspace_lock
|
|
20
|
+
from git_contribution_analyzer.application.ports.cancellation import CancellationToken
|
|
21
|
+
from git_contribution_analyzer.application.ports.progress import ProgressReporter
|
|
22
|
+
from git_contribution_analyzer.application.use_cases.index_repository import index_repository
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def init_project(
|
|
26
|
+
path: Path,
|
|
27
|
+
*,
|
|
28
|
+
progress: ProgressReporter | None = None,
|
|
29
|
+
cancellation: CancellationToken | None = None,
|
|
30
|
+
) -> WorkspaceLayout:
|
|
31
|
+
repository = discover_repository(path)
|
|
32
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
33
|
+
layout.create_directories()
|
|
34
|
+
|
|
35
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
36
|
+
default_branch = detect_current_branch(repository)
|
|
37
|
+
write_default_config(layout.config, default_branch)
|
|
38
|
+
if not layout.identities.exists():
|
|
39
|
+
layout.identities.write_text("schemaVersion: '1.0'\nidentities: []\n", encoding="utf-8")
|
|
40
|
+
initialize_database(layout.database)
|
|
41
|
+
repository_id = upsert_repository(layout.database, repository, default_branch)
|
|
42
|
+
now = datetime.now(UTC).isoformat()
|
|
43
|
+
created_at = now
|
|
44
|
+
if layout.metadata.exists():
|
|
45
|
+
try:
|
|
46
|
+
existing = json.loads(layout.metadata.read_text(encoding="utf-8"))
|
|
47
|
+
created_at = str(existing.get("createdAt", now))
|
|
48
|
+
except (OSError, ValueError, TypeError):
|
|
49
|
+
created_at = now
|
|
50
|
+
metadata = {
|
|
51
|
+
"schemaVersion": "1.0",
|
|
52
|
+
"toolVersion": __version__,
|
|
53
|
+
"repository": str(repository.root),
|
|
54
|
+
"repositoryId": repository_id,
|
|
55
|
+
"gitDir": str(repository.git_dir),
|
|
56
|
+
"createdAt": created_at,
|
|
57
|
+
"updatedAt": now,
|
|
58
|
+
}
|
|
59
|
+
layout.metadata.write_text(
|
|
60
|
+
json.dumps(metadata, ensure_ascii=False, indent=2) + "\n",
|
|
61
|
+
encoding="utf-8",
|
|
62
|
+
newline="\n",
|
|
63
|
+
)
|
|
64
|
+
ensure_workspace_excluded(repository.root)
|
|
65
|
+
index_repository(
|
|
66
|
+
repository.root,
|
|
67
|
+
full_rebuild=False,
|
|
68
|
+
progress=progress,
|
|
69
|
+
cancellation=cancellation,
|
|
70
|
+
)
|
|
71
|
+
return layout
|
|
@@ -0,0 +1,16 @@
|
|
|
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.storage.sqlite.git_index import SqliteGitIndexStore
|
|
8
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def list_identities(path: Path, *, unresolved_only: bool = False) -> dict[str, Any]:
|
|
12
|
+
repository = discover_repository(path)
|
|
13
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
14
|
+
store = SqliteGitIndexStore(layout.database, str(repository.root))
|
|
15
|
+
persons = store.list_identities(unresolved_only=unresolved_only)
|
|
16
|
+
return {"persons": persons, "count": len(persons)}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 provider_descriptors
|
|
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 list_providers(path: Path) -> dict[str, Any]:
|
|
13
|
+
repository = discover_repository(path)
|
|
14
|
+
config = load_config(WorkspaceLayout.for_repository(repository.root).config)
|
|
15
|
+
providers = [
|
|
16
|
+
{
|
|
17
|
+
"id": descriptor.provider_id,
|
|
18
|
+
"localExecution": descriptor.local_execution,
|
|
19
|
+
"requiresApiKey": descriptor.requires_api_key,
|
|
20
|
+
"selected": descriptor.provider_id == config.llm.provider,
|
|
21
|
+
}
|
|
22
|
+
for descriptor in provider_descriptors()
|
|
23
|
+
]
|
|
24
|
+
return {
|
|
25
|
+
"selected": config.llm.provider,
|
|
26
|
+
"enabled": config.llm.enabled,
|
|
27
|
+
"apiKeyEnv": config.llm.api_key_env,
|
|
28
|
+
"providers": providers,
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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.storage.sqlite.analysis import SqliteAnalysisStore
|
|
8
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import initialize_database
|
|
9
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def list_runs(path: Path) -> dict[str, Any]:
|
|
13
|
+
repository = discover_repository(path)
|
|
14
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
15
|
+
initialize_database(layout.database)
|
|
16
|
+
runs = SqliteAnalysisStore(layout.database, str(repository.root)).list_runs()
|
|
17
|
+
return {"runs": runs, "count": len(runs)}
|
|
@@ -0,0 +1,48 @@
|
|
|
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.storage.sqlite.database import initialize_database
|
|
8
|
+
from git_contribution_analyzer.adapters.storage.sqlite.identity_merge import (
|
|
9
|
+
SqliteIdentityMergeStore,
|
|
10
|
+
)
|
|
11
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
12
|
+
from git_contribution_analyzer.adapters.workspace.locks import workspace_lock
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def preview_identity_merge(
|
|
16
|
+
path: Path, sources: tuple[str, ...], target: str
|
|
17
|
+
) -> dict[str, Any]:
|
|
18
|
+
store, _layout = _store(path)
|
|
19
|
+
return store.preview(sources, target)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def merge_identities(
|
|
23
|
+
path: Path, sources: tuple[str, ...], target: str
|
|
24
|
+
) -> dict[str, Any]:
|
|
25
|
+
store, layout = _store(path)
|
|
26
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
27
|
+
return store.merge(sources, target)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def list_identity_merges(path: Path, status: str) -> dict[str, Any]:
|
|
31
|
+
store, _layout = _store(path)
|
|
32
|
+
return {"merges": store.list_events(status)}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def unmerge_identities(path: Path, merge_id: str) -> dict[str, Any]:
|
|
36
|
+
store, layout = _store(path)
|
|
37
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
38
|
+
return store.unmerge(merge_id)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _store(path: Path) -> tuple[SqliteIdentityMergeStore, WorkspaceLayout]:
|
|
42
|
+
repository = discover_repository(path)
|
|
43
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
44
|
+
initialize_database(layout.database)
|
|
45
|
+
return (
|
|
46
|
+
SqliteIdentityMergeStore(layout.database, str(repository.root)),
|
|
47
|
+
layout,
|
|
48
|
+
)
|