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,98 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from threading import Lock
|
|
5
|
+
from uuid import NAMESPACE_URL, uuid5
|
|
6
|
+
|
|
7
|
+
from alembic import command
|
|
8
|
+
from alembic.config import Config
|
|
9
|
+
from sqlalchemy import Engine, create_engine, event, text
|
|
10
|
+
from sqlalchemy.dialects.sqlite import insert
|
|
11
|
+
|
|
12
|
+
from git_contribution_analyzer.adapters.storage.sqlite.models import repositories
|
|
13
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
14
|
+
from git_contribution_analyzer.domain.models.repository import DiscoveredRepository
|
|
15
|
+
|
|
16
|
+
_ALEMBIC_MIGRATION_LOCK = Lock()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def database_url(path: Path) -> str:
|
|
20
|
+
return f"sqlite:///{path.as_posix()}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def create_database_engine(path: Path) -> Engine:
|
|
24
|
+
engine = create_engine(database_url(path), future=True)
|
|
25
|
+
|
|
26
|
+
@event.listens_for(engine, "connect")
|
|
27
|
+
def configure_sqlite(dbapi_connection: object, _connection_record: object) -> None:
|
|
28
|
+
cursor = dbapi_connection.cursor() # type: ignore[attr-defined]
|
|
29
|
+
cursor.execute("PRAGMA foreign_keys=ON")
|
|
30
|
+
cursor.execute("PRAGMA journal_mode=WAL")
|
|
31
|
+
cursor.execute("PRAGMA busy_timeout=5000")
|
|
32
|
+
cursor.close()
|
|
33
|
+
|
|
34
|
+
return engine
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _alembic_config(path: Path) -> Config:
|
|
38
|
+
config = Config()
|
|
39
|
+
migrations = Path(__file__).with_name("migrations")
|
|
40
|
+
config.set_main_option("script_location", str(migrations))
|
|
41
|
+
config.set_main_option("sqlalchemy.url", database_url(path))
|
|
42
|
+
return config
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def initialize_database(path: Path) -> None:
|
|
46
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
try:
|
|
48
|
+
with _ALEMBIC_MIGRATION_LOCK:
|
|
49
|
+
command.upgrade(_alembic_config(path), "head")
|
|
50
|
+
except Exception as exc:
|
|
51
|
+
raise WorkspaceError(f"Unable to initialize database: {path}") from exc
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def upsert_repository(
|
|
55
|
+
path: Path,
|
|
56
|
+
repository: DiscoveredRepository,
|
|
57
|
+
default_branch: str,
|
|
58
|
+
) -> str:
|
|
59
|
+
repository_id = str(uuid5(NAMESPACE_URL, repository.root.as_uri()))
|
|
60
|
+
engine = create_database_engine(path)
|
|
61
|
+
statement = insert(repositories).values(
|
|
62
|
+
id=repository_id,
|
|
63
|
+
root_path=str(repository.root),
|
|
64
|
+
git_dir=str(repository.git_dir),
|
|
65
|
+
default_branch=default_branch,
|
|
66
|
+
)
|
|
67
|
+
statement = statement.on_conflict_do_update(
|
|
68
|
+
index_elements=[repositories.c.root_path],
|
|
69
|
+
set_={
|
|
70
|
+
"git_dir": str(repository.git_dir),
|
|
71
|
+
"default_branch": default_branch,
|
|
72
|
+
"updated_at": text("CURRENT_TIMESTAMP"),
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
try:
|
|
76
|
+
with engine.begin() as connection:
|
|
77
|
+
connection.execute(statement)
|
|
78
|
+
except Exception as exc:
|
|
79
|
+
raise WorkspaceError(f"Unable to register repository: {repository.root}") from exc
|
|
80
|
+
finally:
|
|
81
|
+
engine.dispose()
|
|
82
|
+
return repository_id
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def check_database(path: Path) -> bool:
|
|
86
|
+
if not path.is_file():
|
|
87
|
+
return False
|
|
88
|
+
try:
|
|
89
|
+
engine = create_database_engine(path)
|
|
90
|
+
with engine.connect() as connection:
|
|
91
|
+
quick_check = connection.execute(text("PRAGMA quick_check")).scalar_one()
|
|
92
|
+
revision = connection.execute(
|
|
93
|
+
text("SELECT version_num FROM alembic_version")
|
|
94
|
+
).scalar_one()
|
|
95
|
+
engine.dispose()
|
|
96
|
+
return quick_check == "ok" and bool(revision)
|
|
97
|
+
except Exception:
|
|
98
|
+
return False
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from typing import Any
|
|
7
|
+
from uuid import NAMESPACE_URL, uuid5
|
|
8
|
+
|
|
9
|
+
from sqlalchemy import Connection, delete, func, insert, select, update
|
|
10
|
+
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
|
11
|
+
|
|
12
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import create_database_engine
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.identity_merge import reassign_alias
|
|
14
|
+
from git_contribution_analyzer.adapters.storage.sqlite.models import (
|
|
15
|
+
commit_delivery,
|
|
16
|
+
commit_parents,
|
|
17
|
+
commits,
|
|
18
|
+
file_changes,
|
|
19
|
+
identity_aliases,
|
|
20
|
+
identity_merge_events,
|
|
21
|
+
persons,
|
|
22
|
+
refs,
|
|
23
|
+
repositories,
|
|
24
|
+
)
|
|
25
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
26
|
+
from git_contribution_analyzer.domain.models.git_history import (
|
|
27
|
+
CommitDelivery,
|
|
28
|
+
GitCommit,
|
|
29
|
+
GitIdentity,
|
|
30
|
+
GitRef,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class SqliteGitIndexStore:
|
|
35
|
+
def __init__(self, database_path: Any, repository_root: str) -> None:
|
|
36
|
+
self.database_path = database_path
|
|
37
|
+
self.repository_root = repository_root
|
|
38
|
+
|
|
39
|
+
def _repository_id(self, connection: Connection) -> str:
|
|
40
|
+
repository_id = connection.execute(
|
|
41
|
+
select(repositories.c.id).where(repositories.c.root_path == self.repository_root)
|
|
42
|
+
).scalar_one_or_none()
|
|
43
|
+
if repository_id is None:
|
|
44
|
+
raise WorkspaceError(f"Repository is not registered: {self.repository_root}")
|
|
45
|
+
return str(repository_id)
|
|
46
|
+
|
|
47
|
+
def existing_commit_hashes(self) -> set[str]:
|
|
48
|
+
engine = create_database_engine(self.database_path)
|
|
49
|
+
try:
|
|
50
|
+
with engine.connect() as connection:
|
|
51
|
+
repository_id = self._repository_id(connection)
|
|
52
|
+
return set(
|
|
53
|
+
connection.execute(
|
|
54
|
+
select(commits.c.hash).where(commits.c.repository_id == repository_id)
|
|
55
|
+
).scalars()
|
|
56
|
+
)
|
|
57
|
+
finally:
|
|
58
|
+
engine.dispose()
|
|
59
|
+
|
|
60
|
+
def write_index(
|
|
61
|
+
self,
|
|
62
|
+
git_refs: Iterable[GitRef],
|
|
63
|
+
git_commits: Iterable[GitCommit],
|
|
64
|
+
deliveries: Iterable[CommitDelivery],
|
|
65
|
+
*,
|
|
66
|
+
clear_existing: bool,
|
|
67
|
+
default_branch: str | None = None,
|
|
68
|
+
) -> None:
|
|
69
|
+
engine = create_database_engine(self.database_path)
|
|
70
|
+
try:
|
|
71
|
+
with engine.begin() as connection:
|
|
72
|
+
repository_id = self._repository_id(connection)
|
|
73
|
+
if default_branch is not None:
|
|
74
|
+
connection.execute(
|
|
75
|
+
update(repositories)
|
|
76
|
+
.where(repositories.c.id == repository_id)
|
|
77
|
+
.values(default_branch=default_branch, updated_at=datetime.now(UTC))
|
|
78
|
+
)
|
|
79
|
+
if clear_existing:
|
|
80
|
+
self._clear(connection, repository_id)
|
|
81
|
+
protected_alias_ids = self._active_moved_alias_ids(
|
|
82
|
+
connection, repository_id
|
|
83
|
+
)
|
|
84
|
+
self._replace_refs(connection, repository_id, git_refs)
|
|
85
|
+
for commit in git_commits:
|
|
86
|
+
self._insert_commit(
|
|
87
|
+
connection,
|
|
88
|
+
repository_id,
|
|
89
|
+
commit,
|
|
90
|
+
protected_alias_ids,
|
|
91
|
+
)
|
|
92
|
+
self._replace_delivery(connection, repository_id, deliveries)
|
|
93
|
+
except Exception as exc:
|
|
94
|
+
if isinstance(exc, WorkspaceError):
|
|
95
|
+
raise
|
|
96
|
+
raise WorkspaceError("Unable to persist Git index") from exc
|
|
97
|
+
finally:
|
|
98
|
+
engine.dispose()
|
|
99
|
+
|
|
100
|
+
def _clear(self, connection: Connection, repository_id: str) -> None:
|
|
101
|
+
indexed_tables = (
|
|
102
|
+
commit_delivery,
|
|
103
|
+
file_changes,
|
|
104
|
+
commit_parents,
|
|
105
|
+
commits,
|
|
106
|
+
refs,
|
|
107
|
+
)
|
|
108
|
+
for table in indexed_tables:
|
|
109
|
+
connection.execute(delete(table).where(table.c.repository_id == repository_id))
|
|
110
|
+
|
|
111
|
+
def _active_moved_alias_ids(
|
|
112
|
+
self,
|
|
113
|
+
connection: Connection,
|
|
114
|
+
repository_id: str,
|
|
115
|
+
) -> set[str]:
|
|
116
|
+
rows = connection.execute(
|
|
117
|
+
select(identity_merge_events.c.moved_alias_ids_json).where(
|
|
118
|
+
identity_merge_events.c.repository_id == repository_id,
|
|
119
|
+
identity_merge_events.c.status == "ACTIVE",
|
|
120
|
+
)
|
|
121
|
+
).scalars()
|
|
122
|
+
return {
|
|
123
|
+
str(alias_id)
|
|
124
|
+
for payload in rows
|
|
125
|
+
for alias_id in json.loads(str(payload))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
def _replace_refs(
|
|
129
|
+
self,
|
|
130
|
+
connection: Connection,
|
|
131
|
+
repository_id: str,
|
|
132
|
+
git_refs: Iterable[GitRef],
|
|
133
|
+
) -> None:
|
|
134
|
+
connection.execute(
|
|
135
|
+
update(refs).where(refs.c.repository_id == repository_id).values(active=False)
|
|
136
|
+
)
|
|
137
|
+
for git_ref in git_refs:
|
|
138
|
+
statement = sqlite_insert(refs).values(
|
|
139
|
+
repository_id=repository_id,
|
|
140
|
+
ref_name=git_ref.name,
|
|
141
|
+
commit_hash=git_ref.commit_hash,
|
|
142
|
+
ref_type=git_ref.ref_type,
|
|
143
|
+
active=True,
|
|
144
|
+
observed_at=datetime.now(UTC),
|
|
145
|
+
)
|
|
146
|
+
connection.execute(
|
|
147
|
+
statement.on_conflict_do_update(
|
|
148
|
+
index_elements=[refs.c.repository_id, refs.c.ref_name],
|
|
149
|
+
set_={
|
|
150
|
+
"commit_hash": git_ref.commit_hash,
|
|
151
|
+
"ref_type": git_ref.ref_type,
|
|
152
|
+
"active": True,
|
|
153
|
+
"observed_at": datetime.now(UTC),
|
|
154
|
+
},
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def _insert_commit(
|
|
159
|
+
self,
|
|
160
|
+
connection: Connection,
|
|
161
|
+
repository_id: str,
|
|
162
|
+
commit: GitCommit,
|
|
163
|
+
protected_alias_ids: set[str],
|
|
164
|
+
) -> None:
|
|
165
|
+
alias_id = self._resolve_alias(
|
|
166
|
+
connection,
|
|
167
|
+
repository_id,
|
|
168
|
+
commit.author,
|
|
169
|
+
protected_alias_ids,
|
|
170
|
+
)
|
|
171
|
+
commit_statement = sqlite_insert(commits).values(
|
|
172
|
+
repository_id=repository_id,
|
|
173
|
+
hash=commit.hash,
|
|
174
|
+
author_alias_id=alias_id,
|
|
175
|
+
committer_name=commit.committer_name,
|
|
176
|
+
committer_email=commit.committer_email,
|
|
177
|
+
authored_at=commit.authored_at.astimezone(UTC),
|
|
178
|
+
committed_at=commit.committed_at.astimezone(UTC),
|
|
179
|
+
subject=commit.subject,
|
|
180
|
+
body=commit.body,
|
|
181
|
+
is_merge=commit.is_merge,
|
|
182
|
+
tree_hash=commit.tree_hash,
|
|
183
|
+
patch_id=commit.patch_id,
|
|
184
|
+
reverts_hash=commit.reverts_hash,
|
|
185
|
+
insertions=commit.insertions,
|
|
186
|
+
deletions=commit.deletions,
|
|
187
|
+
files_changed=len(commit.changes),
|
|
188
|
+
)
|
|
189
|
+
result = connection.execute(
|
|
190
|
+
commit_statement.on_conflict_do_nothing(
|
|
191
|
+
index_elements=[commits.c.repository_id, commits.c.hash]
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
if result.rowcount == 0:
|
|
195
|
+
return
|
|
196
|
+
for parent_index, parent_hash in enumerate(commit.parents):
|
|
197
|
+
connection.execute(
|
|
198
|
+
insert(commit_parents).values(
|
|
199
|
+
repository_id=repository_id,
|
|
200
|
+
commit_hash=commit.hash,
|
|
201
|
+
parent_index=parent_index,
|
|
202
|
+
parent_hash=parent_hash,
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
if commit.changes:
|
|
206
|
+
connection.execute(
|
|
207
|
+
insert(file_changes),
|
|
208
|
+
[
|
|
209
|
+
{
|
|
210
|
+
"repository_id": repository_id,
|
|
211
|
+
"commit_hash": commit.hash,
|
|
212
|
+
"old_path": change.old_path,
|
|
213
|
+
"new_path": change.new_path,
|
|
214
|
+
"change_type": change.change_type,
|
|
215
|
+
"is_binary": change.is_binary,
|
|
216
|
+
"is_excluded": False,
|
|
217
|
+
"insertions": change.insertions,
|
|
218
|
+
"deletions": change.deletions,
|
|
219
|
+
}
|
|
220
|
+
for change in commit.changes
|
|
221
|
+
],
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
def _resolve_alias(
|
|
225
|
+
self,
|
|
226
|
+
connection: Connection,
|
|
227
|
+
repository_id: str,
|
|
228
|
+
identity: GitIdentity,
|
|
229
|
+
protected_alias_ids: set[str],
|
|
230
|
+
) -> str:
|
|
231
|
+
alias_id = str(
|
|
232
|
+
uuid5(
|
|
233
|
+
NAMESPACE_URL,
|
|
234
|
+
f"{repository_id}:alias:{identity.name}:{identity.email.lower()}",
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
person_id = str(
|
|
238
|
+
uuid5(
|
|
239
|
+
NAMESPACE_URL,
|
|
240
|
+
f"{repository_id}:person:{identity.canonical_email.lower()}",
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
person_statement = sqlite_insert(persons).values(
|
|
244
|
+
id=person_id,
|
|
245
|
+
repository_id=repository_id,
|
|
246
|
+
canonical_name=identity.canonical_name,
|
|
247
|
+
canonical_email=identity.canonical_email.lower(),
|
|
248
|
+
kind="HUMAN",
|
|
249
|
+
confirmed=identity.confirmed,
|
|
250
|
+
)
|
|
251
|
+
connection.execute(
|
|
252
|
+
person_statement.on_conflict_do_update(
|
|
253
|
+
index_elements=[persons.c.repository_id, persons.c.canonical_email],
|
|
254
|
+
set_={"confirmed": persons.c.confirmed | identity.confirmed},
|
|
255
|
+
)
|
|
256
|
+
)
|
|
257
|
+
person_id = str(
|
|
258
|
+
connection.execute(
|
|
259
|
+
select(persons.c.id).where(
|
|
260
|
+
persons.c.repository_id == repository_id,
|
|
261
|
+
persons.c.canonical_email == identity.canonical_email.lower(),
|
|
262
|
+
)
|
|
263
|
+
).scalar_one()
|
|
264
|
+
)
|
|
265
|
+
alias_statement = sqlite_insert(identity_aliases).values(
|
|
266
|
+
id=alias_id,
|
|
267
|
+
repository_id=repository_id,
|
|
268
|
+
person_id=person_id,
|
|
269
|
+
name=identity.name,
|
|
270
|
+
email=identity.email,
|
|
271
|
+
normalized_email=identity.email.lower(),
|
|
272
|
+
source=identity.source,
|
|
273
|
+
confidence=1.0 if identity.confirmed else 0.95,
|
|
274
|
+
confirmed=identity.confirmed,
|
|
275
|
+
rationale="Resolved by .mailmap" if identity.confirmed else "Exact normalized email",
|
|
276
|
+
)
|
|
277
|
+
alias_updates = {
|
|
278
|
+
"source": identity.source,
|
|
279
|
+
"confirmed": identity.confirmed,
|
|
280
|
+
}
|
|
281
|
+
if alias_id not in protected_alias_ids:
|
|
282
|
+
alias_updates["person_id"] = person_id
|
|
283
|
+
connection.execute(
|
|
284
|
+
alias_statement.on_conflict_do_update(
|
|
285
|
+
# Alias IDs normalize email case, so case-only Git author variants
|
|
286
|
+
# must resolve through the same primary key as well. Active manual
|
|
287
|
+
# mappings keep ownership while Git history is synchronized.
|
|
288
|
+
index_elements=[identity_aliases.c.id],
|
|
289
|
+
set_=alias_updates,
|
|
290
|
+
)
|
|
291
|
+
)
|
|
292
|
+
return alias_id
|
|
293
|
+
|
|
294
|
+
def _replace_delivery(
|
|
295
|
+
self,
|
|
296
|
+
connection: Connection,
|
|
297
|
+
repository_id: str,
|
|
298
|
+
deliveries: Iterable[CommitDelivery],
|
|
299
|
+
) -> None:
|
|
300
|
+
connection.execute(
|
|
301
|
+
delete(commit_delivery).where(commit_delivery.c.repository_id == repository_id)
|
|
302
|
+
)
|
|
303
|
+
values = [
|
|
304
|
+
{
|
|
305
|
+
"repository_id": repository_id,
|
|
306
|
+
"commit_hash": delivery.commit_hash,
|
|
307
|
+
"target_ref": delivery.target_ref,
|
|
308
|
+
"status": delivery.status,
|
|
309
|
+
"release_ref": delivery.release_ref,
|
|
310
|
+
"related_commit_hash": delivery.related_commit_hash,
|
|
311
|
+
}
|
|
312
|
+
for delivery in deliveries
|
|
313
|
+
]
|
|
314
|
+
if values:
|
|
315
|
+
connection.execute(insert(commit_delivery), values)
|
|
316
|
+
|
|
317
|
+
def relation_summaries(self) -> list[dict[str, Any]]:
|
|
318
|
+
engine = create_database_engine(self.database_path)
|
|
319
|
+
try:
|
|
320
|
+
with engine.connect() as connection:
|
|
321
|
+
repository_id = self._repository_id(connection)
|
|
322
|
+
rows = connection.execute(
|
|
323
|
+
select(
|
|
324
|
+
commits.c.hash,
|
|
325
|
+
commits.c.patch_id,
|
|
326
|
+
commits.c.reverts_hash,
|
|
327
|
+
).where(commits.c.repository_id == repository_id)
|
|
328
|
+
).mappings()
|
|
329
|
+
return [dict(row) for row in rows]
|
|
330
|
+
finally:
|
|
331
|
+
engine.dispose()
|
|
332
|
+
|
|
333
|
+
def stats(self) -> dict[str, int]:
|
|
334
|
+
engine = create_database_engine(self.database_path)
|
|
335
|
+
try:
|
|
336
|
+
with engine.connect() as connection:
|
|
337
|
+
repository_id = self._repository_id(connection)
|
|
338
|
+
commit_count = connection.execute(
|
|
339
|
+
select(func.count()).select_from(commits).where(
|
|
340
|
+
commits.c.repository_id == repository_id
|
|
341
|
+
)
|
|
342
|
+
).scalar_one()
|
|
343
|
+
identity_count = connection.execute(
|
|
344
|
+
select(func.count()).select_from(persons).where(
|
|
345
|
+
persons.c.repository_id == repository_id
|
|
346
|
+
)
|
|
347
|
+
).scalar_one()
|
|
348
|
+
unresolved_count = connection.execute(
|
|
349
|
+
select(func.count()).select_from(persons).where(
|
|
350
|
+
persons.c.repository_id == repository_id,
|
|
351
|
+
persons.c.confirmed.is_(False),
|
|
352
|
+
)
|
|
353
|
+
).scalar_one()
|
|
354
|
+
active_ref_count = connection.execute(
|
|
355
|
+
select(func.count()).select_from(refs).where(
|
|
356
|
+
refs.c.repository_id == repository_id,
|
|
357
|
+
refs.c.active.is_(True),
|
|
358
|
+
)
|
|
359
|
+
).scalar_one()
|
|
360
|
+
return {
|
|
361
|
+
"indexedCommits": int(commit_count),
|
|
362
|
+
"identities": int(identity_count),
|
|
363
|
+
"unresolvedIdentities": int(unresolved_count),
|
|
364
|
+
"refs": int(active_ref_count),
|
|
365
|
+
}
|
|
366
|
+
finally:
|
|
367
|
+
engine.dispose()
|
|
368
|
+
|
|
369
|
+
def list_identities(self, *, unresolved_only: bool = False) -> list[dict[str, Any]]:
|
|
370
|
+
engine = create_database_engine(self.database_path)
|
|
371
|
+
try:
|
|
372
|
+
with engine.connect() as connection:
|
|
373
|
+
repository_id = self._repository_id(connection)
|
|
374
|
+
statement = select(persons).where(persons.c.repository_id == repository_id)
|
|
375
|
+
if unresolved_only:
|
|
376
|
+
statement = statement.where(persons.c.confirmed.is_(False))
|
|
377
|
+
person_rows = connection.execute(statement).mappings().all()
|
|
378
|
+
result: list[dict[str, Any]] = []
|
|
379
|
+
for person in person_rows:
|
|
380
|
+
aliases = connection.execute(
|
|
381
|
+
select(identity_aliases).where(
|
|
382
|
+
identity_aliases.c.person_id == person["id"]
|
|
383
|
+
)
|
|
384
|
+
).mappings()
|
|
385
|
+
result.append(
|
|
386
|
+
{
|
|
387
|
+
"id": person["id"],
|
|
388
|
+
"name": person["canonical_name"],
|
|
389
|
+
"email": person["canonical_email"],
|
|
390
|
+
"kind": person["kind"],
|
|
391
|
+
"confirmed": bool(person["confirmed"]),
|
|
392
|
+
"active": bool(person["active"]),
|
|
393
|
+
"mergedIntoPersonId": person["merged_into_person_id"],
|
|
394
|
+
"aliases": [
|
|
395
|
+
{
|
|
396
|
+
"id": alias["id"],
|
|
397
|
+
"name": alias["name"],
|
|
398
|
+
"email": alias["email"],
|
|
399
|
+
"source": alias["source"],
|
|
400
|
+
"confirmed": bool(alias["confirmed"]),
|
|
401
|
+
}
|
|
402
|
+
for alias in aliases
|
|
403
|
+
],
|
|
404
|
+
}
|
|
405
|
+
)
|
|
406
|
+
return result
|
|
407
|
+
finally:
|
|
408
|
+
engine.dispose()
|
|
409
|
+
|
|
410
|
+
def map_identity(
|
|
411
|
+
self,
|
|
412
|
+
*,
|
|
413
|
+
name: str,
|
|
414
|
+
email: str,
|
|
415
|
+
person_name: str,
|
|
416
|
+
person_email: str,
|
|
417
|
+
) -> dict[str, Any]:
|
|
418
|
+
engine = create_database_engine(self.database_path)
|
|
419
|
+
try:
|
|
420
|
+
with engine.begin() as connection:
|
|
421
|
+
repository_id = self._repository_id(connection)
|
|
422
|
+
alias = connection.execute(
|
|
423
|
+
select(identity_aliases).where(
|
|
424
|
+
identity_aliases.c.repository_id == repository_id,
|
|
425
|
+
identity_aliases.c.name == name,
|
|
426
|
+
identity_aliases.c.email == email,
|
|
427
|
+
)
|
|
428
|
+
).mappings().one_or_none()
|
|
429
|
+
if alias is None:
|
|
430
|
+
raise WorkspaceError(f"Identity alias not found: {name} <{email}>")
|
|
431
|
+
person_id = str(
|
|
432
|
+
uuid5(
|
|
433
|
+
NAMESPACE_URL,
|
|
434
|
+
f"{repository_id}:person:{person_email.lower()}",
|
|
435
|
+
)
|
|
436
|
+
)
|
|
437
|
+
statement = sqlite_insert(persons).values(
|
|
438
|
+
id=person_id,
|
|
439
|
+
repository_id=repository_id,
|
|
440
|
+
canonical_name=person_name,
|
|
441
|
+
canonical_email=person_email.lower(),
|
|
442
|
+
kind="HUMAN",
|
|
443
|
+
confirmed=True,
|
|
444
|
+
)
|
|
445
|
+
connection.execute(
|
|
446
|
+
statement.on_conflict_do_update(
|
|
447
|
+
index_elements=[persons.c.repository_id, persons.c.canonical_email],
|
|
448
|
+
set_={"canonical_name": person_name, "confirmed": True},
|
|
449
|
+
)
|
|
450
|
+
)
|
|
451
|
+
person_id = str(
|
|
452
|
+
connection.execute(
|
|
453
|
+
select(persons.c.id).where(
|
|
454
|
+
persons.c.repository_id == repository_id,
|
|
455
|
+
persons.c.canonical_email == person_email.lower(),
|
|
456
|
+
)
|
|
457
|
+
).scalar_one()
|
|
458
|
+
)
|
|
459
|
+
reassign_alias(
|
|
460
|
+
connection,
|
|
461
|
+
repository_id,
|
|
462
|
+
str(alias["id"]),
|
|
463
|
+
person_id,
|
|
464
|
+
)
|
|
465
|
+
connection.execute(
|
|
466
|
+
update(identity_aliases)
|
|
467
|
+
.where(identity_aliases.c.id == alias["id"])
|
|
468
|
+
.values(
|
|
469
|
+
source="MANUAL",
|
|
470
|
+
confidence=1.0,
|
|
471
|
+
confirmed=True,
|
|
472
|
+
rationale="Confirmed by user",
|
|
473
|
+
)
|
|
474
|
+
)
|
|
475
|
+
return {
|
|
476
|
+
"id": person_id,
|
|
477
|
+
"name": person_name,
|
|
478
|
+
"email": person_email.lower(),
|
|
479
|
+
"confirmed": True,
|
|
480
|
+
}
|
|
481
|
+
finally:
|
|
482
|
+
engine.dispose()
|