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,708 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from sqlalchemy import Connection, and_, delete, 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.models import (
|
|
14
|
+
analysis_runs,
|
|
15
|
+
capability_assessments,
|
|
16
|
+
commit_delivery,
|
|
17
|
+
commits,
|
|
18
|
+
contribution_items,
|
|
19
|
+
evidence,
|
|
20
|
+
file_changes,
|
|
21
|
+
identity_aliases,
|
|
22
|
+
persons,
|
|
23
|
+
refs,
|
|
24
|
+
repositories,
|
|
25
|
+
)
|
|
26
|
+
from git_contribution_analyzer.domain.errors import (
|
|
27
|
+
IdentityResolutionError,
|
|
28
|
+
ReportError,
|
|
29
|
+
WorkspaceError,
|
|
30
|
+
)
|
|
31
|
+
from git_contribution_analyzer.domain.models.analysis import AnalysisFilters
|
|
32
|
+
from git_contribution_analyzer.domain.models.contribution import ContributionCommit
|
|
33
|
+
from git_contribution_analyzer.domain.models.run import RunType
|
|
34
|
+
from git_contribution_analyzer.domain.services.contribution_rules import (
|
|
35
|
+
classify_commit,
|
|
36
|
+
is_generated_path,
|
|
37
|
+
module_from_path,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class SqliteAnalysisStore:
|
|
42
|
+
def __init__(self, database_path: Path, repository_root: str) -> None:
|
|
43
|
+
self.database_path = database_path
|
|
44
|
+
self.repository_root = repository_root
|
|
45
|
+
|
|
46
|
+
def _repository(self, connection: Connection) -> dict[str, Any]:
|
|
47
|
+
row = connection.execute(
|
|
48
|
+
select(repositories).where(repositories.c.root_path == self.repository_root)
|
|
49
|
+
).mappings().one_or_none()
|
|
50
|
+
if row is None:
|
|
51
|
+
raise WorkspaceError(f"Repository is not registered: {self.repository_root}")
|
|
52
|
+
return dict(row)
|
|
53
|
+
|
|
54
|
+
def resolve_confirmed_person(self, selector: str) -> dict[str, Any]:
|
|
55
|
+
return self.resolve_people((selector,), require_confirmed=True)[0]
|
|
56
|
+
|
|
57
|
+
def count_commits_by_email(
|
|
58
|
+
self,
|
|
59
|
+
person_id: str,
|
|
60
|
+
*,
|
|
61
|
+
commit_hashes: tuple[str, ...] | None = None,
|
|
62
|
+
) -> dict[str, int]:
|
|
63
|
+
engine = create_database_engine(self.database_path)
|
|
64
|
+
try:
|
|
65
|
+
with engine.connect() as connection:
|
|
66
|
+
repository = self._repository(connection)
|
|
67
|
+
statement = (
|
|
68
|
+
select(identity_aliases.c.email)
|
|
69
|
+
.select_from(
|
|
70
|
+
commits.join(
|
|
71
|
+
identity_aliases,
|
|
72
|
+
commits.c.author_alias_id == identity_aliases.c.id,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
.where(
|
|
76
|
+
commits.c.repository_id == repository["id"],
|
|
77
|
+
identity_aliases.c.person_id == person_id,
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
if commit_hashes is not None:
|
|
81
|
+
if not commit_hashes:
|
|
82
|
+
return {}
|
|
83
|
+
statement = statement.where(commits.c.hash.in_(commit_hashes))
|
|
84
|
+
counts: dict[str, int] = defaultdict(int)
|
|
85
|
+
for row in connection.execute(statement).all():
|
|
86
|
+
counts[str(row[0]).lower()] += 1
|
|
87
|
+
return dict(sorted(counts.items()))
|
|
88
|
+
finally:
|
|
89
|
+
engine.dispose()
|
|
90
|
+
|
|
91
|
+
def resolve_people(
|
|
92
|
+
self,
|
|
93
|
+
selectors: tuple[str, ...],
|
|
94
|
+
*,
|
|
95
|
+
require_confirmed: bool,
|
|
96
|
+
) -> list[dict[str, Any]]:
|
|
97
|
+
if not selectors:
|
|
98
|
+
return []
|
|
99
|
+
engine = create_database_engine(self.database_path)
|
|
100
|
+
try:
|
|
101
|
+
with engine.connect() as connection:
|
|
102
|
+
repository = self._repository(connection)
|
|
103
|
+
person_rows = list(
|
|
104
|
+
connection.execute(
|
|
105
|
+
select(persons).where(persons.c.repository_id == repository["id"])
|
|
106
|
+
).mappings()
|
|
107
|
+
)
|
|
108
|
+
people_by_id = {str(row["id"]): dict(row) for row in person_rows}
|
|
109
|
+
aliases_by_person: dict[str, list[tuple[str, str]]] = {}
|
|
110
|
+
for person_row in person_rows:
|
|
111
|
+
aliases = connection.execute(
|
|
112
|
+
select(identity_aliases.c.name, identity_aliases.c.email).where(
|
|
113
|
+
identity_aliases.c.person_id == person_row["id"]
|
|
114
|
+
)
|
|
115
|
+
).all()
|
|
116
|
+
aliases_by_person[str(person_row["id"])] = [
|
|
117
|
+
(str(name), str(email)) for name, email in aliases
|
|
118
|
+
]
|
|
119
|
+
finally:
|
|
120
|
+
engine.dispose()
|
|
121
|
+
resolved: list[dict[str, Any]] = []
|
|
122
|
+
for selector in selectors:
|
|
123
|
+
needle = selector.strip().casefold()
|
|
124
|
+
matches = []
|
|
125
|
+
for person_row in person_rows:
|
|
126
|
+
person_id = str(person_row["id"])
|
|
127
|
+
values = {
|
|
128
|
+
person_id.casefold(),
|
|
129
|
+
str(person_row["canonical_name"]).casefold(),
|
|
130
|
+
str(person_row["canonical_email"]).casefold(),
|
|
131
|
+
*(
|
|
132
|
+
value.casefold()
|
|
133
|
+
for alias in aliases_by_person[person_id]
|
|
134
|
+
for value in alias
|
|
135
|
+
),
|
|
136
|
+
}
|
|
137
|
+
if needle in values:
|
|
138
|
+
matches.append(dict(person_row))
|
|
139
|
+
unique = {str(person["id"]): person for person in matches}
|
|
140
|
+
if len(unique) != 1:
|
|
141
|
+
raise IdentityResolutionError(
|
|
142
|
+
f"Person selector must match exactly one identity: {selector}"
|
|
143
|
+
)
|
|
144
|
+
selected = next(iter(unique.values()))
|
|
145
|
+
visited: set[str] = set()
|
|
146
|
+
while not bool(selected["active"]):
|
|
147
|
+
selected_id = str(selected["id"])
|
|
148
|
+
if selected_id in visited:
|
|
149
|
+
raise IdentityResolutionError(
|
|
150
|
+
f"Identity redirect cycle detected: {selector}"
|
|
151
|
+
)
|
|
152
|
+
visited.add(selected_id)
|
|
153
|
+
redirect_id = selected["merged_into_person_id"]
|
|
154
|
+
if redirect_id is None or str(redirect_id) not in people_by_id:
|
|
155
|
+
raise IdentityResolutionError(
|
|
156
|
+
f"Inactive identity has no valid redirect: {selector}"
|
|
157
|
+
)
|
|
158
|
+
selected = people_by_id[str(redirect_id)]
|
|
159
|
+
if require_confirmed and not bool(selected["confirmed"]):
|
|
160
|
+
raise IdentityResolutionError(
|
|
161
|
+
f"Identity is not confirmed: {selected['canonical_name']} "
|
|
162
|
+
f"<{selected['canonical_email']}>"
|
|
163
|
+
)
|
|
164
|
+
resolved.append(
|
|
165
|
+
{
|
|
166
|
+
"id": str(selected["id"]),
|
|
167
|
+
"name": str(selected["canonical_name"]),
|
|
168
|
+
"email": str(selected["canonical_email"]),
|
|
169
|
+
"kind": str(selected["kind"]),
|
|
170
|
+
"confirmed": bool(selected["confirmed"]),
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
return resolved
|
|
174
|
+
|
|
175
|
+
def list_people_for_analysis(self) -> list[dict[str, Any]]:
|
|
176
|
+
engine = create_database_engine(self.database_path)
|
|
177
|
+
try:
|
|
178
|
+
with engine.connect() as connection:
|
|
179
|
+
repository = self._repository(connection)
|
|
180
|
+
rows = connection.execute(
|
|
181
|
+
select(persons)
|
|
182
|
+
.where(
|
|
183
|
+
persons.c.repository_id == repository["id"],
|
|
184
|
+
persons.c.active.is_(True),
|
|
185
|
+
)
|
|
186
|
+
.order_by(persons.c.canonical_name, persons.c.canonical_email)
|
|
187
|
+
).mappings()
|
|
188
|
+
result = []
|
|
189
|
+
for row in rows:
|
|
190
|
+
aliases = connection.execute(
|
|
191
|
+
select(identity_aliases.c.name, identity_aliases.c.email)
|
|
192
|
+
.where(identity_aliases.c.person_id == row["id"])
|
|
193
|
+
.order_by(identity_aliases.c.name, identity_aliases.c.email)
|
|
194
|
+
).all()
|
|
195
|
+
result.append(
|
|
196
|
+
{
|
|
197
|
+
"id": str(row["id"]),
|
|
198
|
+
"name": str(row["canonical_name"]),
|
|
199
|
+
"email": str(row["canonical_email"]),
|
|
200
|
+
"kind": str(row["kind"]),
|
|
201
|
+
"confirmed": bool(row["confirmed"]),
|
|
202
|
+
"active": bool(row["active"]),
|
|
203
|
+
"mergedIntoPersonId": row["merged_into_person_id"],
|
|
204
|
+
"aliases": [
|
|
205
|
+
{"name": str(name), "email": str(email)}
|
|
206
|
+
for name, email in aliases
|
|
207
|
+
],
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
return result
|
|
211
|
+
finally:
|
|
212
|
+
engine.dispose()
|
|
213
|
+
|
|
214
|
+
def baseline_commit(self) -> str | None:
|
|
215
|
+
engine = create_database_engine(self.database_path)
|
|
216
|
+
try:
|
|
217
|
+
with engine.connect() as connection:
|
|
218
|
+
repository = self._repository(connection)
|
|
219
|
+
target_ref = f"refs/heads/{repository['default_branch']}"
|
|
220
|
+
return connection.execute(
|
|
221
|
+
select(refs.c.commit_hash).where(
|
|
222
|
+
refs.c.repository_id == repository["id"],
|
|
223
|
+
refs.c.ref_name == target_ref,
|
|
224
|
+
)
|
|
225
|
+
).scalar_one_or_none()
|
|
226
|
+
finally:
|
|
227
|
+
engine.dispose()
|
|
228
|
+
|
|
229
|
+
def load_commits(
|
|
230
|
+
self,
|
|
231
|
+
person_id: str | None,
|
|
232
|
+
filters: AnalysisFilters,
|
|
233
|
+
*,
|
|
234
|
+
allowed_hashes: set[str] | None = None,
|
|
235
|
+
integration_times: dict[str, tuple[datetime, datetime | None]] | None = None,
|
|
236
|
+
release_times: dict[str, datetime] | None = None,
|
|
237
|
+
) -> tuple[ContributionCommit, ...]:
|
|
238
|
+
engine = create_database_engine(self.database_path)
|
|
239
|
+
try:
|
|
240
|
+
with engine.connect() as connection:
|
|
241
|
+
repository = self._repository(connection)
|
|
242
|
+
target_ref = f"refs/heads/{repository['default_branch']}"
|
|
243
|
+
statement = (
|
|
244
|
+
select(
|
|
245
|
+
commits.c.hash,
|
|
246
|
+
commits.c.subject,
|
|
247
|
+
commits.c.authored_at,
|
|
248
|
+
commits.c.committed_at,
|
|
249
|
+
commits.c.insertions,
|
|
250
|
+
commits.c.deletions,
|
|
251
|
+
commits.c.files_changed,
|
|
252
|
+
commits.c.is_merge,
|
|
253
|
+
commits.c.patch_id,
|
|
254
|
+
commits.c.reverts_hash,
|
|
255
|
+
commit_delivery.c.status,
|
|
256
|
+
commit_delivery.c.release_ref,
|
|
257
|
+
)
|
|
258
|
+
.join(
|
|
259
|
+
identity_aliases,
|
|
260
|
+
commits.c.author_alias_id == identity_aliases.c.id,
|
|
261
|
+
)
|
|
262
|
+
.outerjoin(
|
|
263
|
+
commit_delivery,
|
|
264
|
+
and_(
|
|
265
|
+
commit_delivery.c.repository_id == commits.c.repository_id,
|
|
266
|
+
commit_delivery.c.commit_hash == commits.c.hash,
|
|
267
|
+
commit_delivery.c.target_ref == target_ref,
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
.where(
|
|
271
|
+
commits.c.repository_id == repository["id"],
|
|
272
|
+
identity_aliases.c.person_id == person_id,
|
|
273
|
+
)
|
|
274
|
+
.order_by(commits.c.authored_at, commits.c.hash)
|
|
275
|
+
)
|
|
276
|
+
time_column = {
|
|
277
|
+
"AUTHORED": commits.c.authored_at,
|
|
278
|
+
"COMMITTED": commits.c.committed_at,
|
|
279
|
+
}.get(filters.time_basis)
|
|
280
|
+
if filters.since and time_column is not None:
|
|
281
|
+
statement = statement.where(time_column >= _aware_utc(filters.since))
|
|
282
|
+
if filters.until and time_column is not None:
|
|
283
|
+
statement = statement.where(time_column <= _aware_utc(filters.until))
|
|
284
|
+
if filters.release:
|
|
285
|
+
release_ref = (
|
|
286
|
+
filters.release
|
|
287
|
+
if filters.release.startswith("refs/tags/")
|
|
288
|
+
else f"refs/tags/{filters.release}"
|
|
289
|
+
)
|
|
290
|
+
statement = statement.where(commit_delivery.c.release_ref == release_ref)
|
|
291
|
+
if filters.delivery:
|
|
292
|
+
delivery = filters.delivery.upper()
|
|
293
|
+
if delivery == "DELIVERED":
|
|
294
|
+
statement = statement.where(
|
|
295
|
+
commit_delivery.c.status.in_(("LANDED", "RELEASED", "REVERTED"))
|
|
296
|
+
)
|
|
297
|
+
else:
|
|
298
|
+
statement = statement.where(commit_delivery.c.status == delivery)
|
|
299
|
+
rows = [
|
|
300
|
+
dict(row)
|
|
301
|
+
for row in connection.execute(statement).mappings()
|
|
302
|
+
if allowed_hashes is None or str(row["hash"]) in allowed_hashes
|
|
303
|
+
]
|
|
304
|
+
changes_by_commit = self._load_changes(
|
|
305
|
+
connection,
|
|
306
|
+
str(repository["id"]),
|
|
307
|
+
tuple(str(row["hash"]) for row in rows),
|
|
308
|
+
)
|
|
309
|
+
finally:
|
|
310
|
+
engine.dispose()
|
|
311
|
+
|
|
312
|
+
facts: list[ContributionCommit] = []
|
|
313
|
+
scope = filters.scope.replace("\\", "/").strip("/") if filters.scope else None
|
|
314
|
+
for row in rows:
|
|
315
|
+
event_at = _event_time(
|
|
316
|
+
row,
|
|
317
|
+
filters.time_basis,
|
|
318
|
+
integration_times or {},
|
|
319
|
+
release_times or {},
|
|
320
|
+
)
|
|
321
|
+
if event_at is None:
|
|
322
|
+
continue
|
|
323
|
+
if filters.since and event_at < filters.since:
|
|
324
|
+
continue
|
|
325
|
+
if filters.until and event_at > filters.until:
|
|
326
|
+
continue
|
|
327
|
+
changes = changes_by_commit.get(str(row["hash"]), ())
|
|
328
|
+
paths = tuple(path for path, _binary, _excluded, _insertions, _deletions in changes)
|
|
329
|
+
if scope and not any(path == scope or path.startswith(f"{scope}/") for path in paths):
|
|
330
|
+
continue
|
|
331
|
+
facts.append(
|
|
332
|
+
ContributionCommit(
|
|
333
|
+
hash=str(row["hash"]),
|
|
334
|
+
subject=str(row["subject"]),
|
|
335
|
+
authored_at=row["authored_at"],
|
|
336
|
+
commit_type=classify_commit(str(row["subject"])),
|
|
337
|
+
delivery_status=str(row["status"] or "AUTHORED_ONLY"),
|
|
338
|
+
paths=paths,
|
|
339
|
+
modules=tuple(sorted({module_from_path(path) for path in paths})),
|
|
340
|
+
insertions=int(row["insertions"]),
|
|
341
|
+
deletions=int(row["deletions"]),
|
|
342
|
+
files_changed=int(row["files_changed"]),
|
|
343
|
+
merge=bool(row["is_merge"]),
|
|
344
|
+
binary_files=sum(
|
|
345
|
+
binary
|
|
346
|
+
for _path, binary, _excluded, _insertions, _deletions in changes
|
|
347
|
+
),
|
|
348
|
+
generated_files=sum(is_generated_path(path) for path in paths),
|
|
349
|
+
patch_id=str(row["patch_id"]) if row["patch_id"] else None,
|
|
350
|
+
reverts_hash=(
|
|
351
|
+
str(row["reverts_hash"]) if row["reverts_hash"] else None
|
|
352
|
+
),
|
|
353
|
+
effective_insertions=sum(
|
|
354
|
+
insertions
|
|
355
|
+
for path, binary, excluded, insertions, _deletions in changes
|
|
356
|
+
if not binary and not excluded and not is_generated_path(path)
|
|
357
|
+
),
|
|
358
|
+
effective_deletions=sum(
|
|
359
|
+
deletions
|
|
360
|
+
for path, binary, excluded, _insertions, deletions in changes
|
|
361
|
+
if not binary and not excluded and not is_generated_path(path)
|
|
362
|
+
),
|
|
363
|
+
effective_files_changed=sum(
|
|
364
|
+
1
|
|
365
|
+
for path, binary, excluded, _insertions, _deletions in changes
|
|
366
|
+
if not binary and not excluded and not is_generated_path(path)
|
|
367
|
+
),
|
|
368
|
+
period_at=event_at,
|
|
369
|
+
)
|
|
370
|
+
)
|
|
371
|
+
return tuple(facts)
|
|
372
|
+
|
|
373
|
+
def _load_changes(
|
|
374
|
+
self,
|
|
375
|
+
connection: Connection,
|
|
376
|
+
repository_id: str,
|
|
377
|
+
commit_hashes: tuple[str, ...],
|
|
378
|
+
) -> dict[str, tuple[tuple[str, bool, bool, int, int], ...]]:
|
|
379
|
+
grouped: defaultdict[str, list[tuple[str, bool, bool, int, int]]] = defaultdict(list)
|
|
380
|
+
for start in range(0, len(commit_hashes), 500):
|
|
381
|
+
batch = commit_hashes[start : start + 500]
|
|
382
|
+
if not batch:
|
|
383
|
+
continue
|
|
384
|
+
rows = connection.execute(
|
|
385
|
+
select(
|
|
386
|
+
file_changes.c.commit_hash,
|
|
387
|
+
file_changes.c.old_path,
|
|
388
|
+
file_changes.c.new_path,
|
|
389
|
+
file_changes.c.is_binary,
|
|
390
|
+
file_changes.c.is_excluded,
|
|
391
|
+
file_changes.c.insertions,
|
|
392
|
+
file_changes.c.deletions,
|
|
393
|
+
).where(
|
|
394
|
+
file_changes.c.repository_id == repository_id,
|
|
395
|
+
file_changes.c.commit_hash.in_(batch),
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
for commit_hash, old_path, new_path, binary, excluded, insertions, deletions in rows:
|
|
399
|
+
path = str(new_path or old_path or "")
|
|
400
|
+
if path:
|
|
401
|
+
grouped[str(commit_hash)].append(
|
|
402
|
+
(
|
|
403
|
+
path.replace("\\", "/"),
|
|
404
|
+
bool(binary),
|
|
405
|
+
bool(excluded),
|
|
406
|
+
int(insertions),
|
|
407
|
+
int(deletions),
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
return {key: tuple(value) for key, value in grouped.items()}
|
|
411
|
+
|
|
412
|
+
def start_run(
|
|
413
|
+
self,
|
|
414
|
+
*,
|
|
415
|
+
run_id: str,
|
|
416
|
+
person_id: str | None,
|
|
417
|
+
parameters: dict[str, Any],
|
|
418
|
+
baseline_commit: str | None,
|
|
419
|
+
started_at: datetime,
|
|
420
|
+
run_type: RunType = RunType.ANALYSIS,
|
|
421
|
+
parent_run_id: str | None = None,
|
|
422
|
+
) -> None:
|
|
423
|
+
engine = create_database_engine(self.database_path)
|
|
424
|
+
try:
|
|
425
|
+
with engine.begin() as connection:
|
|
426
|
+
repository = self._repository(connection)
|
|
427
|
+
if parent_run_id is not None:
|
|
428
|
+
parent = connection.execute(
|
|
429
|
+
select(
|
|
430
|
+
analysis_runs.c.repository_id,
|
|
431
|
+
analysis_runs.c.status,
|
|
432
|
+
).where(analysis_runs.c.id == parent_run_id)
|
|
433
|
+
).mappings().one_or_none()
|
|
434
|
+
if parent is None:
|
|
435
|
+
raise ReportError(f"Parent analysis run not found: {parent_run_id}")
|
|
436
|
+
if str(parent["repository_id"]) != str(repository["id"]):
|
|
437
|
+
raise ReportError("Parent analysis run belongs to another repository")
|
|
438
|
+
if str(parent["status"]) not in ("COMPLETED", "PARTIAL"):
|
|
439
|
+
raise ReportError("Parent analysis run is not completed")
|
|
440
|
+
for table in (capability_assessments, evidence, contribution_items):
|
|
441
|
+
connection.execute(delete(table).where(table.c.run_id == run_id))
|
|
442
|
+
statement = sqlite_insert(analysis_runs).values(
|
|
443
|
+
id=run_id,
|
|
444
|
+
repository_id=repository["id"],
|
|
445
|
+
status="RUNNING",
|
|
446
|
+
schema_version="1.0",
|
|
447
|
+
started_at=started_at,
|
|
448
|
+
completed_at=None,
|
|
449
|
+
person_id=person_id,
|
|
450
|
+
parameters_json=_json(parameters),
|
|
451
|
+
baseline_commit=baseline_commit,
|
|
452
|
+
rule_version="rules-v1",
|
|
453
|
+
provider_id="none",
|
|
454
|
+
run_type=run_type.value,
|
|
455
|
+
parent_run_id=parent_run_id,
|
|
456
|
+
result_json=None,
|
|
457
|
+
error_message=None,
|
|
458
|
+
)
|
|
459
|
+
connection.execute(
|
|
460
|
+
statement.on_conflict_do_update(
|
|
461
|
+
index_elements=[analysis_runs.c.id],
|
|
462
|
+
set_={
|
|
463
|
+
"repository_id": repository["id"],
|
|
464
|
+
"status": "RUNNING",
|
|
465
|
+
"schema_version": "1.0",
|
|
466
|
+
"started_at": started_at,
|
|
467
|
+
"completed_at": None,
|
|
468
|
+
"person_id": person_id,
|
|
469
|
+
"parameters_json": _json(parameters),
|
|
470
|
+
"baseline_commit": baseline_commit,
|
|
471
|
+
"rule_version": "rules-v1",
|
|
472
|
+
"provider_id": "none",
|
|
473
|
+
"run_type": run_type.value,
|
|
474
|
+
"parent_run_id": parent_run_id,
|
|
475
|
+
"result_json": None,
|
|
476
|
+
"error_message": None,
|
|
477
|
+
},
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
finally:
|
|
481
|
+
engine.dispose()
|
|
482
|
+
|
|
483
|
+
def complete_run(
|
|
484
|
+
self,
|
|
485
|
+
*,
|
|
486
|
+
run_id: str,
|
|
487
|
+
completed_at: datetime,
|
|
488
|
+
report: dict[str, Any],
|
|
489
|
+
status: str = "COMPLETED",
|
|
490
|
+
provider_id: str = "none",
|
|
491
|
+
persist_details: bool = True,
|
|
492
|
+
) -> None:
|
|
493
|
+
engine = create_database_engine(self.database_path)
|
|
494
|
+
try:
|
|
495
|
+
with engine.begin() as connection:
|
|
496
|
+
connection.execute(
|
|
497
|
+
update(analysis_runs)
|
|
498
|
+
.where(analysis_runs.c.id == run_id)
|
|
499
|
+
.values(
|
|
500
|
+
status=status,
|
|
501
|
+
completed_at=completed_at,
|
|
502
|
+
provider_id=provider_id,
|
|
503
|
+
result_json=_json(report),
|
|
504
|
+
)
|
|
505
|
+
)
|
|
506
|
+
if persist_details:
|
|
507
|
+
self._insert_report_rows(connection, run_id, report)
|
|
508
|
+
finally:
|
|
509
|
+
engine.dispose()
|
|
510
|
+
|
|
511
|
+
def fail_run(self, run_id: str, completed_at: datetime, message: str) -> None:
|
|
512
|
+
engine = create_database_engine(self.database_path)
|
|
513
|
+
try:
|
|
514
|
+
with engine.begin() as connection:
|
|
515
|
+
connection.execute(
|
|
516
|
+
update(analysis_runs)
|
|
517
|
+
.where(analysis_runs.c.id == run_id)
|
|
518
|
+
.values(status="FAILED", completed_at=completed_at, error_message=message)
|
|
519
|
+
)
|
|
520
|
+
finally:
|
|
521
|
+
engine.dispose()
|
|
522
|
+
|
|
523
|
+
def cancel_run(self, run_id: str, completed_at: datetime) -> None:
|
|
524
|
+
engine = create_database_engine(self.database_path)
|
|
525
|
+
try:
|
|
526
|
+
with engine.begin() as connection:
|
|
527
|
+
connection.execute(
|
|
528
|
+
update(analysis_runs)
|
|
529
|
+
.where(analysis_runs.c.id == run_id)
|
|
530
|
+
.values(
|
|
531
|
+
status="CANCELLED",
|
|
532
|
+
completed_at=completed_at,
|
|
533
|
+
error_message="Operation cancelled",
|
|
534
|
+
)
|
|
535
|
+
)
|
|
536
|
+
finally:
|
|
537
|
+
engine.dispose()
|
|
538
|
+
|
|
539
|
+
def fail_running_runs(self, completed_at: datetime, message: str) -> int:
|
|
540
|
+
engine = create_database_engine(self.database_path)
|
|
541
|
+
try:
|
|
542
|
+
with engine.begin() as connection:
|
|
543
|
+
repository = self._repository(connection)
|
|
544
|
+
result = connection.execute(
|
|
545
|
+
update(analysis_runs)
|
|
546
|
+
.where(
|
|
547
|
+
analysis_runs.c.repository_id == repository["id"],
|
|
548
|
+
analysis_runs.c.status == "RUNNING",
|
|
549
|
+
)
|
|
550
|
+
.values(
|
|
551
|
+
status="FAILED",
|
|
552
|
+
completed_at=completed_at,
|
|
553
|
+
error_message=message,
|
|
554
|
+
)
|
|
555
|
+
)
|
|
556
|
+
return int(result.rowcount or 0)
|
|
557
|
+
finally:
|
|
558
|
+
engine.dispose()
|
|
559
|
+
|
|
560
|
+
def _insert_report_rows(
|
|
561
|
+
self, connection: Connection, run_id: str, report: dict[str, Any]
|
|
562
|
+
) -> None:
|
|
563
|
+
item_rows = [
|
|
564
|
+
{
|
|
565
|
+
"run_id": run_id,
|
|
566
|
+
"item_id": item["id"],
|
|
567
|
+
"item_order": index,
|
|
568
|
+
"group_key": item["groupKey"],
|
|
569
|
+
"title": item["title"],
|
|
570
|
+
"confidence": item["confidence"],
|
|
571
|
+
"commits_json": _json(item["commitHashes"]),
|
|
572
|
+
"evidence_ids_json": _json(item["evidenceIds"]),
|
|
573
|
+
}
|
|
574
|
+
for index, item in enumerate(report["contributionItems"], start=1)
|
|
575
|
+
]
|
|
576
|
+
if item_rows:
|
|
577
|
+
connection.execute(insert(contribution_items), item_rows)
|
|
578
|
+
evidence_rows = [
|
|
579
|
+
{
|
|
580
|
+
"run_id": run_id,
|
|
581
|
+
"evidence_id": entry["id"],
|
|
582
|
+
"evidence_type": entry["type"],
|
|
583
|
+
"summary": entry["summary"],
|
|
584
|
+
"commit_hashes_json": _json(entry["commitHashes"]),
|
|
585
|
+
"paths_json": _json(entry["paths"]),
|
|
586
|
+
"metrics_json": _json(entry["metrics"]),
|
|
587
|
+
}
|
|
588
|
+
for entry in report["evidence"]
|
|
589
|
+
]
|
|
590
|
+
if evidence_rows:
|
|
591
|
+
connection.execute(insert(evidence), evidence_rows)
|
|
592
|
+
capability_rows = [
|
|
593
|
+
{
|
|
594
|
+
"run_id": run_id,
|
|
595
|
+
"capability": entry["capability"],
|
|
596
|
+
"confidence": entry["confidence"],
|
|
597
|
+
"rationale": entry["rationale"],
|
|
598
|
+
"evidence_ids_json": _json(entry["evidenceIds"]),
|
|
599
|
+
"gaps_json": _json(entry["gaps"]),
|
|
600
|
+
}
|
|
601
|
+
for entry in report["capabilities"]
|
|
602
|
+
]
|
|
603
|
+
if capability_rows:
|
|
604
|
+
connection.execute(insert(capability_assessments), capability_rows)
|
|
605
|
+
|
|
606
|
+
def list_runs(self) -> list[dict[str, Any]]:
|
|
607
|
+
engine = create_database_engine(self.database_path)
|
|
608
|
+
try:
|
|
609
|
+
with engine.connect() as connection:
|
|
610
|
+
repository = self._repository(connection)
|
|
611
|
+
rows = connection.execute(
|
|
612
|
+
select(analysis_runs)
|
|
613
|
+
.where(analysis_runs.c.repository_id == repository["id"])
|
|
614
|
+
.order_by(analysis_runs.c.started_at.desc(), analysis_runs.c.id.desc())
|
|
615
|
+
).mappings()
|
|
616
|
+
return [
|
|
617
|
+
{
|
|
618
|
+
"id": str(row["id"]),
|
|
619
|
+
"status": str(row["status"]),
|
|
620
|
+
"startedAt": _iso_utc(row["started_at"]),
|
|
621
|
+
"completedAt": (
|
|
622
|
+
_iso_utc(row["completed_at"]) if row["completed_at"] else None
|
|
623
|
+
),
|
|
624
|
+
"personId": row["person_id"],
|
|
625
|
+
"parameters": json.loads(str(row["parameters_json"])),
|
|
626
|
+
"baselineCommit": row["baseline_commit"],
|
|
627
|
+
"ruleVersion": str(row["rule_version"]),
|
|
628
|
+
"providerId": str(row["provider_id"]),
|
|
629
|
+
"runType": str(row["run_type"] or RunType.ANALYSIS.value),
|
|
630
|
+
"parentRunId": row["parent_run_id"],
|
|
631
|
+
"error": row["error_message"],
|
|
632
|
+
}
|
|
633
|
+
for row in rows
|
|
634
|
+
]
|
|
635
|
+
finally:
|
|
636
|
+
engine.dispose()
|
|
637
|
+
|
|
638
|
+
def get_report(self, run_id: str) -> dict[str, Any]:
|
|
639
|
+
engine = create_database_engine(self.database_path)
|
|
640
|
+
try:
|
|
641
|
+
with engine.connect() as connection:
|
|
642
|
+
repository = self._repository(connection)
|
|
643
|
+
actual_id = run_id
|
|
644
|
+
if run_id == "latest":
|
|
645
|
+
actual_id = str(
|
|
646
|
+
connection.execute(
|
|
647
|
+
select(analysis_runs.c.id)
|
|
648
|
+
.where(
|
|
649
|
+
analysis_runs.c.repository_id == repository["id"],
|
|
650
|
+
analysis_runs.c.status.in_(("COMPLETED", "PARTIAL")),
|
|
651
|
+
)
|
|
652
|
+
.order_by(
|
|
653
|
+
analysis_runs.c.completed_at.desc(), analysis_runs.c.id.desc()
|
|
654
|
+
)
|
|
655
|
+
.limit(1)
|
|
656
|
+
).scalar_one_or_none()
|
|
657
|
+
)
|
|
658
|
+
result_json = connection.execute(
|
|
659
|
+
select(analysis_runs.c.result_json).where(
|
|
660
|
+
analysis_runs.c.repository_id == repository["id"],
|
|
661
|
+
analysis_runs.c.id == actual_id,
|
|
662
|
+
)
|
|
663
|
+
).scalar_one_or_none()
|
|
664
|
+
finally:
|
|
665
|
+
engine.dispose()
|
|
666
|
+
if not result_json:
|
|
667
|
+
raise ReportError(f"Completed analysis run not found: {run_id}")
|
|
668
|
+
return dict(json.loads(str(result_json)))
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def _event_time(
|
|
672
|
+
row: dict[str, Any],
|
|
673
|
+
time_basis: str,
|
|
674
|
+
integration_times: dict[str, tuple[datetime, datetime | None]],
|
|
675
|
+
release_times: dict[str, datetime],
|
|
676
|
+
) -> datetime | None:
|
|
677
|
+
if time_basis == "AUTHORED":
|
|
678
|
+
return _aware_utc(row["authored_at"])
|
|
679
|
+
if time_basis == "COMMITTED":
|
|
680
|
+
return _aware_utc(row["committed_at"])
|
|
681
|
+
if time_basis == "LANDED":
|
|
682
|
+
integration_event = integration_times.get(str(row["hash"]))
|
|
683
|
+
return _aware_utc(integration_event[0]) if integration_event else None
|
|
684
|
+
if time_basis == "MERGED":
|
|
685
|
+
integration_event = integration_times.get(str(row["hash"]))
|
|
686
|
+
return (
|
|
687
|
+
_aware_utc(integration_event[1])
|
|
688
|
+
if integration_event and integration_event[1]
|
|
689
|
+
else None
|
|
690
|
+
)
|
|
691
|
+
if time_basis == "RELEASED":
|
|
692
|
+
release_ref = row["release_ref"]
|
|
693
|
+
release_event = release_times.get(str(release_ref)) if release_ref else None
|
|
694
|
+
return _aware_utc(release_event) if release_event else None
|
|
695
|
+
raise ValueError(f"Unsupported assessment time basis: {time_basis}")
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def _aware_utc(value: datetime) -> datetime:
|
|
699
|
+
return value.replace(tzinfo=UTC) if value.tzinfo is None else value.astimezone(UTC)
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def _json(value: Any) -> str:
|
|
703
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def _iso_utc(value: datetime) -> str:
|
|
707
|
+
aware = value.replace(tzinfo=UTC) if value.tzinfo is None else value.astimezone(UTC)
|
|
708
|
+
return aware.isoformat()
|