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,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from enum import StrEnum
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SizeBand(StrEnum):
|
|
8
|
+
SMALL = "SMALL"
|
|
9
|
+
MEDIUM = "MEDIUM"
|
|
10
|
+
LARGE = "LARGE"
|
|
11
|
+
XLARGE = "XLARGE"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DifficultyLevel(StrEnum):
|
|
15
|
+
ROUTINE = "ROUTINE"
|
|
16
|
+
STANDARD = "STANDARD"
|
|
17
|
+
COMPLEX = "COMPLEX"
|
|
18
|
+
HIGH_RISK = "HIGH_RISK"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CompletionBucket(StrEnum):
|
|
22
|
+
COMPLETED = "COMPLETED"
|
|
23
|
+
PENDING = "PENDING"
|
|
24
|
+
REWORK = "REWORK"
|
|
25
|
+
INTEGRATION = "INTEGRATION"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class WorkItemSizeAssessment:
|
|
30
|
+
band: SizeBand
|
|
31
|
+
effective_files: int
|
|
32
|
+
effective_churn: int
|
|
33
|
+
module_span: int
|
|
34
|
+
baseline_sample_size: int
|
|
35
|
+
baseline_mode: str
|
|
36
|
+
rule_version: str
|
|
37
|
+
evidence_ids: tuple[str, ...]
|
|
38
|
+
excluded_changes: tuple[str, ...] = ()
|
|
39
|
+
confidence: str = "MEDIUM"
|
|
40
|
+
gaps: tuple[str, ...] = ()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True, slots=True)
|
|
44
|
+
class WorkloadBaseline:
|
|
45
|
+
sample_size: int
|
|
46
|
+
churn_percentiles: tuple[int, int, int]
|
|
47
|
+
file_percentiles: tuple[int, int, int]
|
|
48
|
+
module_percentiles: tuple[int, int, int]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True, slots=True)
|
|
52
|
+
class DimensionSignal:
|
|
53
|
+
dimension: str
|
|
54
|
+
code: str
|
|
55
|
+
severity: str
|
|
56
|
+
description: str
|
|
57
|
+
evidence_ids: tuple[str, ...]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True, slots=True)
|
|
61
|
+
class DifficultyAssessment:
|
|
62
|
+
level: DifficultyLevel
|
|
63
|
+
dimension_signals: tuple[DimensionSignal, ...]
|
|
64
|
+
rule_version: str
|
|
65
|
+
evidence_ids: tuple[str, ...]
|
|
66
|
+
confidence: str
|
|
67
|
+
gaps: tuple[str, ...]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True, slots=True)
|
|
71
|
+
class WorkItemAssessment:
|
|
72
|
+
contribution_item_id: str
|
|
73
|
+
person_id: str
|
|
74
|
+
completion_bucket: CompletionBucket
|
|
75
|
+
delivery_statuses: tuple[str, ...]
|
|
76
|
+
work_type: str
|
|
77
|
+
size: WorkItemSizeAssessment
|
|
78
|
+
difficulty: DifficultyAssessment
|
|
79
|
+
engineering_support: tuple[str, ...]
|
|
80
|
+
evidence_ids: tuple[str, ...]
|
|
81
|
+
warnings: tuple[str, ...] = ()
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
from decimal import Decimal
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
SUPPORTED_PERIODS = ("week", "month", "quarter")
|
|
9
|
+
TREND_METRICS = (
|
|
10
|
+
"completedItems",
|
|
11
|
+
"pendingItems",
|
|
12
|
+
"reworkItems",
|
|
13
|
+
"integrationItems",
|
|
14
|
+
"workloadPoints",
|
|
15
|
+
"difficultyPoints",
|
|
16
|
+
)
|
|
17
|
+
SIZE_POINTS = {"SMALL": 1, "MEDIUM": 3, "LARGE": 6, "XLARGE": 10}
|
|
18
|
+
DIFFICULTY_POINTS = {"ROUTINE": 1, "STANDARD": 2, "COMPLEX": 4, "HIGH_RISK": 6}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True, slots=True)
|
|
22
|
+
class AssessmentPeriod:
|
|
23
|
+
label: str
|
|
24
|
+
since: datetime
|
|
25
|
+
until: datetime
|
|
26
|
+
partial: bool
|
|
27
|
+
comparison_key: tuple[int, int]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def split_periods(
|
|
31
|
+
since: datetime,
|
|
32
|
+
until: datetime,
|
|
33
|
+
period: str,
|
|
34
|
+
*,
|
|
35
|
+
use_system_timezone: bool = False,
|
|
36
|
+
) -> tuple[AssessmentPeriod, ...]:
|
|
37
|
+
normalized = period.casefold()
|
|
38
|
+
if normalized not in SUPPORTED_PERIODS:
|
|
39
|
+
raise ValueError(f"Unsupported assessment period: {period}")
|
|
40
|
+
if since > until:
|
|
41
|
+
raise ValueError("since must be earlier than or equal to until")
|
|
42
|
+
|
|
43
|
+
periods: list[AssessmentPeriod] = []
|
|
44
|
+
cursor = since
|
|
45
|
+
while cursor <= until:
|
|
46
|
+
start, next_start, label, comparison_key = _calendar_bounds(
|
|
47
|
+
cursor, normalized, use_system_timezone=use_system_timezone
|
|
48
|
+
)
|
|
49
|
+
natural_until = _period_end(
|
|
50
|
+
next_start, use_system_timezone=use_system_timezone
|
|
51
|
+
)
|
|
52
|
+
period_since = max(cursor, start)
|
|
53
|
+
period_until = min(until, natural_until)
|
|
54
|
+
periods.append(
|
|
55
|
+
AssessmentPeriod(
|
|
56
|
+
label=label,
|
|
57
|
+
since=period_since,
|
|
58
|
+
until=period_until,
|
|
59
|
+
partial=(
|
|
60
|
+
period_since != start
|
|
61
|
+
or period_until != natural_until
|
|
62
|
+
),
|
|
63
|
+
comparison_key=comparison_key,
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
cursor = next_start
|
|
67
|
+
return tuple(periods)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def build_period_comparison(
|
|
71
|
+
current: dict[str, int],
|
|
72
|
+
previous: dict[str, int] | None,
|
|
73
|
+
previous_year: dict[str, int] | None,
|
|
74
|
+
) -> dict[str, Any]:
|
|
75
|
+
return {
|
|
76
|
+
"periodOverPeriod": _metric_changes(current, previous),
|
|
77
|
+
"yearOverYear": _metric_changes(current, previous_year),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def summarize_assessment(report: dict[str, Any]) -> dict[str, int]:
|
|
82
|
+
workload = report["workloadSummary"]
|
|
83
|
+
completed = [
|
|
84
|
+
item
|
|
85
|
+
for subject in report["subjects"]
|
|
86
|
+
for item in subject["itemAssessments"]
|
|
87
|
+
if item["completionBucket"] == "COMPLETED"
|
|
88
|
+
]
|
|
89
|
+
return {
|
|
90
|
+
"completedItems": int(workload["completedItems"]),
|
|
91
|
+
"pendingItems": int(workload["pendingItems"]),
|
|
92
|
+
"reworkItems": int(workload["reworkItems"]),
|
|
93
|
+
"integrationItems": int(workload["integrationItems"]),
|
|
94
|
+
"workloadPoints": sum(SIZE_POINTS[item["size"]["band"]] for item in completed),
|
|
95
|
+
"difficultyPoints": sum(
|
|
96
|
+
DIFFICULTY_POINTS[item["difficulty"]["level"]] for item in completed
|
|
97
|
+
),
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _metric_changes(
|
|
102
|
+
current: dict[str, int], previous: dict[str, int] | None
|
|
103
|
+
) -> dict[str, dict[str, int | str | None]] | None:
|
|
104
|
+
if previous is None:
|
|
105
|
+
return None
|
|
106
|
+
result: dict[str, dict[str, int | str | None]] = {}
|
|
107
|
+
for metric in TREND_METRICS:
|
|
108
|
+
current_value = current[metric]
|
|
109
|
+
previous_value = previous[metric]
|
|
110
|
+
percent = None
|
|
111
|
+
if previous_value != 0:
|
|
112
|
+
percent = str(
|
|
113
|
+
((Decimal(current_value - previous_value) / Decimal(previous_value)) * 100)
|
|
114
|
+
.quantize(Decimal("0.0001"))
|
|
115
|
+
)
|
|
116
|
+
elif current_value == 0:
|
|
117
|
+
percent = "0.0000"
|
|
118
|
+
result[metric] = {
|
|
119
|
+
"absolute": current_value - previous_value,
|
|
120
|
+
"percent": percent,
|
|
121
|
+
}
|
|
122
|
+
return result
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _calendar_bounds(
|
|
126
|
+
value: datetime, period: str, *, use_system_timezone: bool
|
|
127
|
+
) -> tuple[datetime, datetime, str, tuple[int, int]]:
|
|
128
|
+
local_value = value.replace(tzinfo=None) if use_system_timezone else value
|
|
129
|
+
midnight = local_value.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
130
|
+
if period == "week":
|
|
131
|
+
start = midnight - timedelta(days=local_value.weekday())
|
|
132
|
+
next_start = start + timedelta(days=7)
|
|
133
|
+
iso_year, iso_week, _weekday = start.isocalendar()
|
|
134
|
+
return (
|
|
135
|
+
_calendar_time(start, use_system_timezone),
|
|
136
|
+
_calendar_time(next_start, use_system_timezone),
|
|
137
|
+
f"{iso_year}-W{iso_week:02d}",
|
|
138
|
+
(iso_year, iso_week),
|
|
139
|
+
)
|
|
140
|
+
if period == "month":
|
|
141
|
+
start = midnight.replace(day=1)
|
|
142
|
+
next_start = (
|
|
143
|
+
start.replace(year=start.year + 1, month=1)
|
|
144
|
+
if start.month == 12
|
|
145
|
+
else start.replace(month=start.month + 1)
|
|
146
|
+
)
|
|
147
|
+
return (
|
|
148
|
+
_calendar_time(start, use_system_timezone),
|
|
149
|
+
_calendar_time(next_start, use_system_timezone),
|
|
150
|
+
f"{start.year}-{start.month:02d}",
|
|
151
|
+
(start.year, start.month),
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
quarter = (local_value.month - 1) // 3 + 1
|
|
155
|
+
start_month = (quarter - 1) * 3 + 1
|
|
156
|
+
start = midnight.replace(month=start_month, day=1)
|
|
157
|
+
next_start = (
|
|
158
|
+
start.replace(year=start.year + 1, month=1)
|
|
159
|
+
if start_month == 10
|
|
160
|
+
else start.replace(month=start_month + 3)
|
|
161
|
+
)
|
|
162
|
+
return (
|
|
163
|
+
_calendar_time(start, use_system_timezone),
|
|
164
|
+
_calendar_time(next_start, use_system_timezone),
|
|
165
|
+
f"{start.year}-Q{quarter}",
|
|
166
|
+
(start.year, quarter),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _period_end(next_start: datetime, *, use_system_timezone: bool) -> datetime:
|
|
171
|
+
if not use_system_timezone:
|
|
172
|
+
return next_start - timedelta(microseconds=1)
|
|
173
|
+
naive_end = next_start.replace(tzinfo=None) - timedelta(microseconds=1)
|
|
174
|
+
return _localize_system_time(naive_end)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _calendar_time(value: datetime, use_system_timezone: bool) -> datetime:
|
|
178
|
+
return _localize_system_time(value) if use_system_timezone else value
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _localize_system_time(value: datetime) -> datetime:
|
|
182
|
+
return value.astimezone()
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from datetime import UTC, datetime, timedelta
|
|
7
|
+
from typing import Final
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError
|
|
10
|
+
from git_contribution_analyzer.domain.models.brag import (
|
|
11
|
+
BragDeliveredItem,
|
|
12
|
+
BragDocumentReport,
|
|
13
|
+
BragOutcomeRecord,
|
|
14
|
+
BragPeriod,
|
|
15
|
+
BragScope,
|
|
16
|
+
BragSection,
|
|
17
|
+
BragSummary,
|
|
18
|
+
)
|
|
19
|
+
from git_contribution_analyzer.domain.models.resume import VerifiedOutcome
|
|
20
|
+
|
|
21
|
+
BRAG_RULE_VERSION: Final[str] = "brag-rules-v1"
|
|
22
|
+
|
|
23
|
+
_QUARTER_RE = re.compile(r"^(\d{4})-Q([1-4])$", re.IGNORECASE)
|
|
24
|
+
_DIFFICULTY_RANK: dict[str, int] = {
|
|
25
|
+
"HIGH_RISK": 4,
|
|
26
|
+
"COMPLEX": 3,
|
|
27
|
+
"STANDARD": 2,
|
|
28
|
+
"ROUTINE": 1,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DEFAULT_BRAG_DISCLAIMERS: tuple[str, ...] = (
|
|
32
|
+
"Git delivery status (LANDED/RELEASED) reflects repository integration, not automatic "
|
|
33
|
+
"production deployment or business outcome.",
|
|
34
|
+
"Pure Git evidence never unlocks LED claims; quantitative metrics must cite verified "
|
|
35
|
+
"entries in outcomes.yml.",
|
|
36
|
+
"Raw author emails, team rankings, and comparative performance scores are intentionally "
|
|
37
|
+
"omitted.",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def resolve_brag_period(
|
|
42
|
+
*,
|
|
43
|
+
year: int | None = None,
|
|
44
|
+
quarter: str | None = None,
|
|
45
|
+
since: datetime | None = None,
|
|
46
|
+
until: datetime | None = None,
|
|
47
|
+
reference_now: datetime | None = None,
|
|
48
|
+
) -> BragPeriod:
|
|
49
|
+
"""确定性解析 Brag Document 统计周期(支持 --year, --quarter YYYY-Q[1-4] 或 --since/--until)."""
|
|
50
|
+
now = reference_now if reference_now is not None else datetime.now().astimezone()
|
|
51
|
+
tz = now.tzinfo or UTC
|
|
52
|
+
|
|
53
|
+
modes_used = sum(
|
|
54
|
+
1 for flag in (year is not None, bool(quarter), since is not None or until is not None)
|
|
55
|
+
if flag
|
|
56
|
+
)
|
|
57
|
+
if modes_used > 1:
|
|
58
|
+
raise ConfigurationError(
|
|
59
|
+
"Specify only one period selector: --year, --quarter, or --since/--until"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if since is not None or until is not None:
|
|
63
|
+
if since is None or until is None:
|
|
64
|
+
raise ConfigurationError("Both --since and --until are required for a custom range")
|
|
65
|
+
start = since if since.tzinfo is not None else since.replace(tzinfo=tz)
|
|
66
|
+
end = until if until.tzinfo is not None else until.replace(tzinfo=tz)
|
|
67
|
+
if end < start:
|
|
68
|
+
raise ConfigurationError("--until must be on or after --since")
|
|
69
|
+
return BragPeriod(
|
|
70
|
+
label=f"{start.date().isoformat()}..{end.date().isoformat()}",
|
|
71
|
+
since=start,
|
|
72
|
+
until=end,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if quarter:
|
|
76
|
+
match = _QUARTER_RE.match(quarter.strip())
|
|
77
|
+
if not match:
|
|
78
|
+
raise ConfigurationError(
|
|
79
|
+
f"Invalid --quarter value {quarter!r}; expected YYYY-Q1..YYYY-Q4"
|
|
80
|
+
)
|
|
81
|
+
q_year = int(match.group(1))
|
|
82
|
+
q_num = int(match.group(2))
|
|
83
|
+
start_month = (q_num - 1) * 3 + 1
|
|
84
|
+
start_dt = datetime(q_year, start_month, 1, 0, 0, 0, tzinfo=tz)
|
|
85
|
+
if start_month == 10:
|
|
86
|
+
next_start = datetime(q_year + 1, 1, 1, 0, 0, 0, tzinfo=tz)
|
|
87
|
+
else:
|
|
88
|
+
next_start = datetime(q_year, start_month + 3, 1, 0, 0, 0, tzinfo=tz)
|
|
89
|
+
end_dt = next_start - timedelta(microseconds=1)
|
|
90
|
+
return BragPeriod(label=f"{q_year}-Q{q_num}", since=start_dt, until=end_dt)
|
|
91
|
+
|
|
92
|
+
target_year = year if year is not None else now.year
|
|
93
|
+
if target_year < 1970 or target_year > 2100:
|
|
94
|
+
raise ConfigurationError(f"Year out of supported range: {target_year}")
|
|
95
|
+
start_dt = datetime(target_year, 1, 1, 0, 0, 0, tzinfo=tz)
|
|
96
|
+
end_dt = datetime(target_year + 1, 1, 1, 0, 0, 0, tzinfo=tz) - timedelta(microseconds=1)
|
|
97
|
+
return BragPeriod(label=str(target_year), since=start_dt, until=end_dt)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _normalize_ev(ev: str, repo_key: str, *, qualify: bool) -> str:
|
|
101
|
+
cleaned = ev.strip()
|
|
102
|
+
if qualify and ":" not in cleaned:
|
|
103
|
+
return f"{repo_key}:{cleaned}"
|
|
104
|
+
return cleaned
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _evidence_matches(outcome_ev: str, item_ev_set: set[str]) -> bool:
|
|
108
|
+
low = outcome_ev.strip().lower()
|
|
109
|
+
if not low:
|
|
110
|
+
return False
|
|
111
|
+
for candidate in item_ev_set:
|
|
112
|
+
c_low = candidate.lower()
|
|
113
|
+
if c_low == low or c_low.endswith(f":{low}") or low.endswith(f":{c_low}"):
|
|
114
|
+
return True
|
|
115
|
+
return False
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def build_brag_document(
|
|
119
|
+
*,
|
|
120
|
+
report_type: str,
|
|
121
|
+
period: BragPeriod,
|
|
122
|
+
scope: BragScope,
|
|
123
|
+
person_name: str,
|
|
124
|
+
commits: int,
|
|
125
|
+
delivered_commits: int,
|
|
126
|
+
delivered_items: Sequence[BragDeliveredItem],
|
|
127
|
+
outcomes: Sequence[VerifiedOutcome],
|
|
128
|
+
warnings: Sequence[str] = (),
|
|
129
|
+
generated_at: datetime | None = None,
|
|
130
|
+
) -> BragDocumentReport:
|
|
131
|
+
"""确定性组装个人年度/季度 Brag Document, 自动关联 VerifiedOutcome 与证据 ID."""
|
|
132
|
+
qualify = scope.mode == "PORTFOLIO"
|
|
133
|
+
period_start_date = period.since.date()
|
|
134
|
+
period_end_date = period.until.date()
|
|
135
|
+
|
|
136
|
+
# Filter outcomes whose verified_at falls inside period OR explicitly linked to delivered items
|
|
137
|
+
normalized_items: list[BragDeliveredItem] = []
|
|
138
|
+
item_ev_sets: list[set[str]] = []
|
|
139
|
+
for raw_item in delivered_items:
|
|
140
|
+
ev_tuple = tuple(
|
|
141
|
+
dict.fromkeys(
|
|
142
|
+
_normalize_ev(ev, raw_item.repo_key, qualify=qualify)
|
|
143
|
+
for ev in raw_item.evidence_ids
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
if not ev_tuple:
|
|
147
|
+
continue
|
|
148
|
+
normalized_items.append(
|
|
149
|
+
BragDeliveredItem(
|
|
150
|
+
repo_key=raw_item.repo_key,
|
|
151
|
+
group=raw_item.group,
|
|
152
|
+
item_id=raw_item.item_id,
|
|
153
|
+
title=raw_item.title,
|
|
154
|
+
commits=max(1, raw_item.commits),
|
|
155
|
+
evidence_ids=ev_tuple,
|
|
156
|
+
difficulty=raw_item.difficulty,
|
|
157
|
+
size=raw_item.size,
|
|
158
|
+
outcome_ids=(),
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
item_ev_sets.append(set(ev_tuple))
|
|
162
|
+
|
|
163
|
+
item_outcome_ids: list[list[str]] = [[] for _ in normalized_items]
|
|
164
|
+
outcome_records: list[BragOutcomeRecord] = []
|
|
165
|
+
linked_outcome_count = 0
|
|
166
|
+
|
|
167
|
+
for outcome in outcomes:
|
|
168
|
+
matched_any = False
|
|
169
|
+
if outcome.evidence_ids:
|
|
170
|
+
for idx, ev_set in enumerate(item_ev_sets):
|
|
171
|
+
if any(_evidence_matches(ev, ev_set) for ev in outcome.evidence_ids):
|
|
172
|
+
item_outcome_ids[idx].append(outcome.id)
|
|
173
|
+
matched_any = True
|
|
174
|
+
in_period = period_start_date <= outcome.verified_at <= period_end_date
|
|
175
|
+
if not in_period and not matched_any:
|
|
176
|
+
continue
|
|
177
|
+
if matched_any:
|
|
178
|
+
linked_outcome_count += 1
|
|
179
|
+
outcome_records.append(
|
|
180
|
+
BragOutcomeRecord(
|
|
181
|
+
id=outcome.id,
|
|
182
|
+
text=outcome.text,
|
|
183
|
+
source=outcome.source,
|
|
184
|
+
verified_by=outcome.verified_by,
|
|
185
|
+
verified_at=outcome.verified_at.isoformat(),
|
|
186
|
+
kind=outcome.kind.upper(),
|
|
187
|
+
evidence_ids=outcome.evidence_ids,
|
|
188
|
+
tags=outcome.tags,
|
|
189
|
+
linked=matched_any,
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
enriched_items: list[BragDeliveredItem] = []
|
|
194
|
+
for idx, item in enumerate(normalized_items):
|
|
195
|
+
enriched_items.append(
|
|
196
|
+
BragDeliveredItem(
|
|
197
|
+
repo_key=item.repo_key,
|
|
198
|
+
group=item.group,
|
|
199
|
+
item_id=item.item_id,
|
|
200
|
+
title=item.title,
|
|
201
|
+
commits=item.commits,
|
|
202
|
+
evidence_ids=item.evidence_ids,
|
|
203
|
+
difficulty=item.difficulty,
|
|
204
|
+
size=item.size,
|
|
205
|
+
outcome_ids=tuple(dict.fromkeys(item_outcome_ids[idx])),
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
grouped: dict[str, list[BragDeliveredItem]] = defaultdict(list)
|
|
210
|
+
for item in enriched_items:
|
|
211
|
+
grouped[item.group].append(item)
|
|
212
|
+
|
|
213
|
+
sections: list[BragSection] = []
|
|
214
|
+
for group_name in sorted(grouped):
|
|
215
|
+
ordered = sorted(
|
|
216
|
+
grouped[group_name],
|
|
217
|
+
key=lambda it: (
|
|
218
|
+
-len(it.outcome_ids),
|
|
219
|
+
-_DIFFICULTY_RANK.get(it.difficulty or "", 0),
|
|
220
|
+
-it.commits,
|
|
221
|
+
it.repo_key,
|
|
222
|
+
it.item_id,
|
|
223
|
+
),
|
|
224
|
+
)
|
|
225
|
+
sections.append(BragSection(group=group_name, items=tuple(ordered)))
|
|
226
|
+
|
|
227
|
+
high_diff = sum(
|
|
228
|
+
1 for item in enriched_items if item.difficulty in {"COMPLEX", "HIGH_RISK"}
|
|
229
|
+
)
|
|
230
|
+
gen_ts = (generated_at or datetime.now(UTC)).isoformat()
|
|
231
|
+
|
|
232
|
+
return BragDocumentReport(
|
|
233
|
+
report_type=report_type,
|
|
234
|
+
generated_at=gen_ts,
|
|
235
|
+
period=period,
|
|
236
|
+
scope=scope,
|
|
237
|
+
person_name=person_name,
|
|
238
|
+
summary=BragSummary(
|
|
239
|
+
commits=commits,
|
|
240
|
+
delivered_commits=delivered_commits,
|
|
241
|
+
completed_items=len(enriched_items),
|
|
242
|
+
high_difficulty_items=high_diff,
|
|
243
|
+
verified_outcomes=len(outcome_records),
|
|
244
|
+
linked_outcomes=linked_outcome_count,
|
|
245
|
+
),
|
|
246
|
+
verified_outcomes=tuple(outcome_records),
|
|
247
|
+
delivered_sections=tuple(sections),
|
|
248
|
+
disclaimers=DEFAULT_BRAG_DISCLAIMERS,
|
|
249
|
+
warnings=tuple(dict.fromkeys(warnings)),
|
|
250
|
+
)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
5
|
+
from git_contribution_analyzer.domain.models.assessment import CapabilityAssessment
|
|
6
|
+
from git_contribution_analyzer.domain.models.contribution import ContributionItem, Evidence
|
|
7
|
+
|
|
8
|
+
PathRule = Callable[[str], bool]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def assess_capabilities(
|
|
12
|
+
items: tuple[ContributionItem, ...],
|
|
13
|
+
evidence: tuple[Evidence, ...],
|
|
14
|
+
) -> tuple[CapabilityAssessment, ...]:
|
|
15
|
+
evidence_ids = {entry.id for entry in evidence}
|
|
16
|
+
rules: tuple[tuple[str, PathRule, str], ...] = (
|
|
17
|
+
("API_DESIGN", _is_api, "API or controller changes are present"),
|
|
18
|
+
("TESTING", _is_test, "Automated test changes are present"),
|
|
19
|
+
("DATABASE", _is_database, "Database or persistence changes are present"),
|
|
20
|
+
("PERFORMANCE", _is_performance, "Performance or caching changes are present"),
|
|
21
|
+
("DELIVERY", _is_delivery, "Build or delivery configuration changes are present"),
|
|
22
|
+
("DOCUMENTATION", _is_documentation, "Documentation changes are present"),
|
|
23
|
+
)
|
|
24
|
+
assessments: list[CapabilityAssessment] = []
|
|
25
|
+
for capability, rule, rationale in rules:
|
|
26
|
+
supporting = tuple(
|
|
27
|
+
item
|
|
28
|
+
for item in items
|
|
29
|
+
if any(rule(path.casefold().replace("\\", "/")) for path in item.paths)
|
|
30
|
+
)
|
|
31
|
+
if supporting:
|
|
32
|
+
assessments.append(_assessment(capability, rationale, supporting, evidence_ids))
|
|
33
|
+
cross_module = tuple(item for item in items if len(item.modules) >= 3)
|
|
34
|
+
if cross_module:
|
|
35
|
+
assessments.append(
|
|
36
|
+
_assessment(
|
|
37
|
+
"CROSS_MODULE",
|
|
38
|
+
"Changes span at least three top-level modules",
|
|
39
|
+
cross_module,
|
|
40
|
+
evidence_ids,
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
return tuple(assessments)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _assessment(
|
|
47
|
+
capability: str,
|
|
48
|
+
rationale: str,
|
|
49
|
+
items: tuple[ContributionItem, ...],
|
|
50
|
+
evidence_ids: set[str],
|
|
51
|
+
) -> CapabilityAssessment:
|
|
52
|
+
supporting_ids = tuple(
|
|
53
|
+
evidence_id
|
|
54
|
+
for item in items
|
|
55
|
+
for evidence_id in item.evidence_ids
|
|
56
|
+
if evidence_id in evidence_ids
|
|
57
|
+
)
|
|
58
|
+
commit_count = sum(len(item.commits) for item in items)
|
|
59
|
+
return CapabilityAssessment(
|
|
60
|
+
capability=capability,
|
|
61
|
+
confidence="HIGH" if commit_count >= 3 else "MEDIUM",
|
|
62
|
+
rationale=rationale,
|
|
63
|
+
evidence_ids=tuple(dict.fromkeys(supporting_ids)),
|
|
64
|
+
gaps=("Git evidence does not prove business outcome or sole ownership",),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _is_api(path: str) -> bool:
|
|
69
|
+
return "controller" in path or path.startswith("api/") or "/api/" in path
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _is_test(path: str) -> bool:
|
|
73
|
+
return path.startswith("test") or "/test" in path or path.endswith("_test.py")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _is_database(path: str) -> bool:
|
|
77
|
+
return path.endswith(".sql") or any(
|
|
78
|
+
token in path for token in ("migration", "mapper", "repository")
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _is_performance(path: str) -> bool:
|
|
83
|
+
return any(token in path for token in ("cache", "redis", "benchmark", "concurrent"))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _is_delivery(path: str) -> bool:
|
|
87
|
+
return any(token in path for token in (".github/", "docker", "k8s", "terraform", "ci/"))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _is_documentation(path: str) -> bool:
|
|
91
|
+
return path.startswith("doc") or path.endswith((".md", ".rst"))
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.domain.models.contribution import (
|
|
8
|
+
ContributionCommit,
|
|
9
|
+
ContributionItem,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
ISSUE_PATTERN = re.compile(r"\b([A-Z][A-Z0-9]+-\d+)\b|(?<!\w)(#\d+)\b")
|
|
13
|
+
SCOPE_PATTERN = re.compile(r"^[a-zA-Z]+\(([^)]+)\)!?:")
|
|
14
|
+
CLUSTER_WINDOW = timedelta(days=14)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(slots=True)
|
|
18
|
+
class _Cluster:
|
|
19
|
+
key: str
|
|
20
|
+
signal: str
|
|
21
|
+
confidence: str
|
|
22
|
+
commits: list[ContributionCommit] = field(default_factory=list)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def cluster_contributions(
|
|
26
|
+
commits: tuple[ContributionCommit, ...],
|
|
27
|
+
) -> tuple[ContributionItem, ...]:
|
|
28
|
+
clusters: list[_Cluster] = []
|
|
29
|
+
for commit in sorted(commits, key=lambda value: (value.authored_at, value.hash)):
|
|
30
|
+
issue = _issue_key(commit.subject)
|
|
31
|
+
scope = _scope(commit.subject)
|
|
32
|
+
if issue:
|
|
33
|
+
cluster = next((value for value in clusters if value.signal == f"issue:{issue}"), None)
|
|
34
|
+
if cluster is None:
|
|
35
|
+
cluster = _Cluster(f"issue:{issue}", f"issue:{issue}", "HIGH")
|
|
36
|
+
clusters.append(cluster)
|
|
37
|
+
else:
|
|
38
|
+
module = commit.modules[0] if commit.modules else "root"
|
|
39
|
+
signal = f"scope:{scope}" if scope else f"module:{module}:{commit.commit_type}"
|
|
40
|
+
cluster = _recent_cluster(clusters, signal, commit)
|
|
41
|
+
if cluster is None:
|
|
42
|
+
sequence = 1 + sum(value.signal == signal for value in clusters)
|
|
43
|
+
cluster = _Cluster(
|
|
44
|
+
key=f"{signal}:{sequence}",
|
|
45
|
+
signal=signal,
|
|
46
|
+
confidence="MEDIUM" if scope else "LOW",
|
|
47
|
+
)
|
|
48
|
+
clusters.append(cluster)
|
|
49
|
+
cluster.commits.append(commit)
|
|
50
|
+
|
|
51
|
+
items: list[ContributionItem] = []
|
|
52
|
+
for index, cluster in enumerate(clusters, start=1):
|
|
53
|
+
commits_in_cluster = tuple(cluster.commits)
|
|
54
|
+
items.append(
|
|
55
|
+
ContributionItem(
|
|
56
|
+
id=f"CI-{index:03d}",
|
|
57
|
+
group_key=cluster.key,
|
|
58
|
+
title=_title(cluster, commits_in_cluster[0].subject),
|
|
59
|
+
confidence=cluster.confidence,
|
|
60
|
+
commits=commits_in_cluster,
|
|
61
|
+
evidence_ids=(f"EV-{index:03d}",),
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
return tuple(items)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _recent_cluster(
|
|
68
|
+
clusters: list[_Cluster],
|
|
69
|
+
signal: str,
|
|
70
|
+
commit: ContributionCommit,
|
|
71
|
+
) -> _Cluster | None:
|
|
72
|
+
return next(
|
|
73
|
+
(
|
|
74
|
+
cluster
|
|
75
|
+
for cluster in reversed(clusters)
|
|
76
|
+
if cluster.signal == signal
|
|
77
|
+
and commit.authored_at - cluster.commits[-1].authored_at <= CLUSTER_WINDOW
|
|
78
|
+
),
|
|
79
|
+
None,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _issue_key(subject: str) -> str | None:
|
|
84
|
+
match = ISSUE_PATTERN.search(subject)
|
|
85
|
+
return next((group for group in match.groups() if group), None) if match else None
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _scope(subject: str) -> str | None:
|
|
89
|
+
match = SCOPE_PATTERN.match(subject.strip())
|
|
90
|
+
return match.group(1).casefold() if match else None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _title(cluster: _Cluster, subject: str) -> str:
|
|
94
|
+
if cluster.signal.startswith("issue:"):
|
|
95
|
+
return f"{cluster.signal.removeprefix('issue:')}: {subject}"
|
|
96
|
+
if cluster.signal.startswith("scope:"):
|
|
97
|
+
return f"{cluster.signal.removeprefix('scope:')}: {subject}"
|
|
98
|
+
return subject
|