Skip to content

Commit 56be76d

Browse files
committed
wip: updated tests and pre commit
1 parent 3c306e2 commit 56be76d

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ exclude: |
33
(?x)^(
44
docs
55
)$
6-
files: ^api/
76
repos:
8-
- repo: local
7+
- repo: api
98
hooks:
109
- id: black
1110
name: black
@@ -27,4 +26,9 @@ repos:
2726
name: pytest
2827
entry: cd api/ && ./run-tests.sh
2928
language: system
30-
types: [bash]
29+
types: [bash]
30+
- repo: frontend
31+
hooks:
32+
- id: lint
33+
name: lint
34+
entry: cd webapp/ && npm run lint

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ You should see an output something like the following:
4444
Python 3.11.0
4545
```
4646

47+
### Install pre commit hooks
48+
49+
In the root of the repository, you will find a file named `.pre-commit-config.yaml`. This file contains the configuration for pre-commit hooks that will automatically run checks and formatting before you commit your changes. To install the pre-commit hooks, run the following command:
50+
51+
```bash
52+
pip install pre-commit
53+
```
54+
4755
### Install dependencies
4856

4957
Change directory to the cloned repository and install the dependencies using poetry:

api/src/software_metrics_machine/apps/rest/main.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from fastapi.responses import JSONResponse, Response, FileResponse
99
from fastapi.middleware.cors import CORSMiddleware
1010
from fastapi.staticfiles import StaticFiles
11-
from typing import Callable
12-
13-
from typing import Optional
11+
from typing import Optional, Callable, cast
1412

1513
from software_metrics_machine.core.infrastructure.repository_factory import (
1614
create_codemaat_repository,
@@ -156,7 +154,7 @@ def entity_churn(
156154
"""
157155
viewer = EntityChurnViewer(repository=create_codemaat_repository())
158156
result = viewer.render(
159-
top_n=top or 0,
157+
top_n=cast(int, top),
160158
ignore_files=ignore_files,
161159
include_only=include_only,
162160
start_date=start_date,
@@ -190,7 +188,7 @@ def code_coupling(
190188
Return coupling pairs ranked by coupling degree.
191189
"""
192190
result = CouplingViewer(repository=create_codemaat_repository()).render(
193-
ignore_files=ignore_files, include_only=include_only, top=top or 20
191+
ignore_files=ignore_files, include_only=include_only, top=cast(int, top)
194192
)
195193
return JSONResponse(convert_result_data(result.data))
196194

@@ -224,7 +222,7 @@ def entity_ownership(
224222
"""
225223
viewer = EntityOnershipViewer(repository=create_codemaat_repository())
226224
result = viewer.render(
227-
top_n=top or 0,
225+
top_n=cast(int, top),
228226
ignore_files=ignore_files,
229227
authors=authors,
230228
include_only=include_only,
@@ -263,10 +261,10 @@ def pipeline_jobs_by_status(
263261
"""
264262
view = ViewJobsByStatus(repository=create_pipelines_repository())
265263
result = view.main(
266-
job_name=job_name or "",
264+
job_name=cast(str, job_name),
267265
workflow_path=workflow_path,
268-
with_pipeline=with_pipeline or False,
269-
aggregate_by_week=aggregate_by_week or False,
266+
with_pipeline=cast(bool, with_pipeline),
267+
aggregate_by_week=cast(bool, aggregate_by_week),
270268
pipeline_raw_filters=raw_filters,
271269
start_date=start_date,
272270
end_date=end_date,
@@ -283,7 +281,6 @@ def pipeline_summary(
283281
"""
284282
view = WorkflowRunSummary(repository=create_pipelines_repository())
285283
result = view.print_summary(
286-
max_workflows=100,
287284
start_date=start_date,
288285
end_date=end_date,
289286
output_format="json",
@@ -307,7 +304,7 @@ def pipeline_runs_duration(
307304
workflow_path=workflow_path,
308305
start_date=start_date,
309306
end_date=end_date,
310-
max_runs=max_runs or 100,
307+
max_runs=cast(int, max_runs),
311308
raw_filters=raw_filters,
312309
)
313310
return JSONResponse(convert_result_data(result.data))
@@ -325,9 +322,11 @@ def pipeline_deployment_frequency(
325322
"""
326323
pipelines_repository = create_pipelines_repository()
327324
view = ViewDeploymentFrequency(repository=pipelines_repository)
325+
target_pipeline = pipelines_repository.configuration.deployment_frequency_target_pipeline or workflow_path
326+
target_job = pipelines_repository.configuration.deployment_frequency_target_job or job_name
328327
result = view.plot(
329-
workflow_path=pipelines_repository.configuration.deployment_frequency_target_pipeline or workflow_path or "",
330-
job_name=pipelines_repository.configuration.deployment_frequency_target_job or job_name or "",
328+
workflow_path=cast(str, target_pipeline),
329+
job_name=cast(str, target_job),
331330
start_date=start_date,
332331
end_date=end_date,
333332
)
@@ -348,7 +347,7 @@ def pipeline_runs_by(
348347
"""
349348
view = ViewWorkflowRunsByWeekOrMonth(repository=create_pipelines_repository())
350349
result = view.main(
351-
aggregate_by=aggregate_by or "week",
350+
aggregate_by=cast(str, aggregate_by),
352351
workflow_path=workflow_path,
353352
start_date=start_date,
354353
end_date=end_date,

api/tests/apps/rest/test_rest_parameter_passing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def test_pipeline_summary_parameters(self, mock_view_class, cli):
8484
client.get("/pipelines/summary?start_date=2023-01-01&end_date=2023-12-31")
8585

8686
mock_view.print_summary.assert_called_once_with(
87-
max_workflows=None,
8887
start_date="2023-01-01",
8988
end_date="2023-12-31",
9089
output_format="json",

0 commit comments

Comments
 (0)