Skip to content

Commit 88954e9

Browse files
committed
Add health field to the ProjectNode that represents sll ProjectHealthMetrics objects of the project
1 parent 55ee9c2 commit 88954e9

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

backend/apps/owasp/graphql/nodes/project.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from apps.github.graphql.nodes.release import ReleaseNode
1010
from apps.github.graphql.nodes.repository import RepositoryNode
1111
from apps.owasp.graphql.nodes.common import GenericEntityNode
12+
from apps.owasp.graphql.nodes.project_health_metrics import ProjectHealthMetricsNode
1213
from apps.owasp.models.project import Project
14+
from apps.owasp.models.project_health_metrics import ProjectHealthMetrics
1315

1416
RECENT_ISSUES_LIMIT = 5
1517
RECENT_RELEASES_LIMIT = 5
@@ -34,6 +36,11 @@
3436
class ProjectNode(GenericEntityNode):
3537
"""Project node."""
3638

39+
@strawberry.field
40+
def health(self) -> list[ProjectHealthMetricsNode]:
41+
"""Resolve project health metrics."""
42+
return ProjectHealthMetrics.objects.filter(project=self).order_by("-nest_created_at")
43+
3744
@strawberry.field
3845
def issues_count(self) -> int:
3946
"""Resolve issues count."""
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
"""OWASP Project Health Metrics Node."""
22

33
import strawberry
4+
import strawberry_django
45

5-
from apps.owasp.graphql.nodes.project import ProjectNode
6+
from apps.owasp.models.project_health_metrics import ProjectHealthMetrics
67

78

8-
@strawberry.type
9+
@strawberry_django.type(
10+
ProjectHealthMetrics,
11+
fields=[
12+
"age_days",
13+
"contributors_count",
14+
"forks_count",
15+
"is_funding_requirements_compliant",
16+
"is_project_leaders_requirements_compliant",
17+
"last_commit_days",
18+
"last_pull_request_days",
19+
"last_release_days",
20+
"open_issues_count",
21+
"owasp_page_last_update_days",
22+
"recent_releases_count",
23+
"score",
24+
"stars_count",
25+
"unanswered_issues_count",
26+
"unassigned_issues_count",
27+
],
28+
)
929
class ProjectHealthMetricsNode:
1030
"""Project health metrics node."""
1131

12-
age_days: int = strawberry.field(description="Project age in days")
13-
contributors_count: int = strawberry.field(description="Number of contributors")
14-
last_commit_days: int = strawberry.field(description="Days since last commit")
15-
last_pull_request_days: int = strawberry.field(description="Days since last pull request")
16-
last_release_days: int = strawberry.field(description="Days since last release")
17-
recent_issues_count: int = strawberry.field(description="Recent issues count")
18-
recent_pull_requests_count: int = strawberry.field(description="Recent pull requests count")
19-
recent_releases_count: int = strawberry.field(description="Recent releases count")
20-
score: float = strawberry.field(description="Project health score (0-100)")
21-
forks_count: int = strawberry.field(description="Number of forks")
22-
stars_count: int = strawberry.field(description="Number of stars")
23-
is_project_leaders_requirements_compliant: bool = strawberry.field(
24-
description="Is leaders requirement compliant"
25-
)
26-
is_funding_requirements_compliant: bool = strawberry.field(
27-
description="Is funding policy requirements compliant"
28-
)
29-
open_issues_count: int = strawberry.field(description="Open issues count")
30-
unanswered_issues_count: int = strawberry.field(description="Unanswered issues count")
31-
3232
@strawberry.field
33-
def project(self) -> ProjectNode:
33+
def project_name(self) -> str:
3434
"""Resolve project node."""
35-
return self.project
35+
return self.project.name

backend/apps/owasp/graphql/queries/project_health_metrics.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ def unhealthy_projects(
2828
no_recent_commits: bool = False,
2929
no_recent_releases: bool = False,
3030
leaders_requirement_compliant: bool = True,
31+
limit: int = 20,
3132
long_open_issues: bool = False,
3233
long_unanswered_issues: bool = False,
3334
long_unassigned_issues: bool = False,
34-
low_score: bool = False,
35+
low_score: bool = True,
3536
) -> list[ProjectHealthMetricsNode]:
3637
"""Resolve unhealthy projects."""
3738
filters = {}
@@ -61,7 +62,7 @@ def unhealthy_projects(
6162
# Get the last created metrics (one for each project)
6263
queryset = (
6364
ProjectHealthMetrics.objects.select_related("project")
64-
.order_by("project__key", "-created_at")
65+
.order_by("project__key", "-nest_created_at", "-score")
6566
.distinct("project__key")
6667
)
6768

@@ -80,4 +81,4 @@ def unhealthy_projects(
8081
)
8182
queryset = queryset.filter(no_commits_filter)
8283

83-
return queryset
84+
return queryset.select_related("project")[:limit]

0 commit comments

Comments
 (0)