Skip to content

Commit 03860a1

Browse files
committed
feature: added dict additional data
1 parent 57e4e58 commit 03860a1

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

git_analytics/engine.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import date, timezone
2-
from typing import Dict, Optional
2+
from typing import Any, Dict, Optional
33

44
from git_analytics.entities import AnalyticsResult
55
from git_analytics.interfaces import CommitSource
@@ -10,9 +10,11 @@ def __init__(
1010
self,
1111
source: CommitSource,
1212
analyzers_factory,
13+
additional_data: Optional[Dict[str, Any]] = None,
1314
) -> None:
1415
self._source = source
1516
self._analyzers_factory = analyzers_factory
17+
self._additional_data = additional_data
1618

1719
def run(
1820
self,
@@ -36,4 +38,7 @@ def run(
3638
for analyzer in analyzers:
3739
analyzer.process(commit)
3840

39-
return {analyzer.name: analyzer.result() for analyzer in analyzers}
41+
result = {analyzer.name: analyzer.result() for analyzer in analyzers}
42+
if self._additional_data:
43+
result["additional_data"] = self._additional_data
44+
return result

git_analytics/entities.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class AnalyticsCommit:
2525

2626
@dataclass
2727
class AnalyticsResult:
28-
def to_dict(self) -> Dict[str, Any]:
28+
def __iter__(self):
29+
return iter(self._to_dict().items())
30+
31+
def _to_dict(self) -> Dict[str, Any]:
2932
return self._make_json_safe(asdict(self))
3033

3134
@staticmethod

git_analytics/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ def make_analyzers():
2929
def run():
3030
try:
3131
repo = Repo()
32+
name_branch = repo.active_branch.name
3233
except InvalidGitRepositoryError:
3334
print("Error: Current directory is not a git repository.")
3435
return
3536

3637
engine = CommitAnalyticsEngine(
3738
source=GitCommitSource(repo),
3839
analyzers_factory=make_analyzers,
40+
additional_data={"name_branch": name_branch},
3941
)
4042

4143
web_app = create_web_app(engine=engine)

git_analytics/web_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def on_get_statistics(self, req, resp):
2424
raise falcon.HTTPBadRequest("Invalid date format", "Use YYYY-MM-DD")
2525

2626
data = self._engine.run(start_date=start_date, stop_date=stop_date)
27-
result = {key: value.to_dict() for key, value in data.items()}
27+
result = {key: dict(value) for key, value in data.items()}
2828

2929
resp.media = result
3030

0 commit comments

Comments
 (0)