Skip to content

Commit 0cd17e7

Browse files
committed
Update filtering
1 parent 413da73 commit 0cd17e7

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def unhealthy_projects(
1919
*,
2020
is_contributors_requirement_compliant: bool | None = None,
2121
is_funding_requirements_compliant: bool | None = None,
22-
has_recent_commits: bool | None = None,
22+
has_no_recent_commits: bool | None = None,
2323
has_recent_releases: bool | None = None,
2424
is_leader_requirements_compliant: bool | None = None,
2525
limit: int = 20,
@@ -47,8 +47,8 @@ def unhealthy_projects(
4747
suffix = "__gte" if is_contributors_requirement_compliant else "__lt"
4848
filters[f"contributors_count{suffix}"] = CONTRIBUTORS_COUNT_REQUIREMENT
4949

50-
if has_recent_commits is not None:
51-
filters["has_recent_commits"] = has_recent_commits
50+
if has_no_recent_commits is not None:
51+
filters["has_no_recent_commits"] = has_no_recent_commits
5252

5353
if has_long_open_issues is not None:
5454
filters["has_long_open_issues"] = has_long_open_issues

backend/apps/owasp/management/commands/owasp_update_project_health_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def handle(self, *args, **options):
1414
"contributors_count": "contributors_count",
1515
"created_at": "created_at",
1616
"forks_count": "forks_count",
17-
"has_recent_commits": "has_recent_commits",
17+
"has_no_recent_commits": "has_no_recent_commits",
1818
"is_funding_requirements_compliant": "is_funding_requirements_compliant",
1919
"is_leader_requirements_compliant": "is_leader_requirements_compliant",
2020
"last_committed_at": "pushed_at",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 5.2.1 on 2025-06-13 07:44
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("owasp", "0042_remove_projecthealthmetrics_has_no_recent_commits_and_more"),
9+
]
10+
11+
operations = [
12+
migrations.RemoveField(
13+
model_name="projecthealthmetrics",
14+
name="has_recent_commits",
15+
),
16+
migrations.AddField(
17+
model_name="projecthealthmetrics",
18+
name="has_no_recent_commits",
19+
field=models.BooleanField(default=False, verbose_name="Has no recent commits"),
20+
),
21+
]

backend/apps/owasp/models/project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ def __str__(self) -> str:
133133
return f"{self.name or self.key}"
134134

135135
@property
136-
def has_recent_commits(self) -> bool:
137-
"""Indicate whether project has recent commits."""
136+
def has_no_recent_commits(self) -> bool:
137+
"""Indicate whether project has no recent commits."""
138138
recent_period = timezone.now() - datetime.timedelta(days=60)
139-
return self.pushed_at is not None and self.pushed_at >= recent_period
139+
return self.pushed_at is None or self.pushed_at < recent_period or self.commits_count == 0
140140

141141
@property
142142
def is_code_type(self) -> bool:

backend/apps/owasp/models/project_health_metrics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class Meta:
2525
forks_count = models.PositiveIntegerField(verbose_name="Forks", default=0)
2626

2727
# The next boolean fields are used for filtering
28-
has_recent_commits = models.BooleanField(verbose_name="Has recent commits", default=False)
28+
has_no_recent_commits = models.BooleanField(
29+
verbose_name="Has no recent commits", default=False
30+
)
2931
has_long_open_issues = models.BooleanField(verbose_name="Has long open issues", default=False)
3032
has_long_unanswered_issues = models.BooleanField(
3133
verbose_name="Has long unanswered issues", default=False

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_unhealthy_projects_field_configuration(self):
3434
expected_arg_names = [
3535
"is_contributors_requirement_compliant",
3636
"is_funding_requirements_compliant",
37-
"has_recent_commits",
37+
"has_no_recent_commits",
3838
"has_recent_releases",
3939
"is_leader_requirements_compliant",
4040
"limit",
@@ -92,7 +92,7 @@ def test_resolve_unhealthy_projects_with_filters(self):
9292
mock_metrics.contributors_count = 3
9393
mock_metrics.is_funding_requirements_compliant = False
9494
mock_metrics.is_leader_requirements_compliant = True
95-
mock_metrics.has_recent_commits = True
95+
mock_metrics.has_no_recent_commits = True
9696
mock_metrics.has_long_open_issues = True
9797
mock_metrics.has_long_unanswered_issues = True
9898
mock_metrics.has_long_unassigned_issues = True
@@ -129,7 +129,7 @@ def test_resolve_unhealthy_projects_with_filters(self):
129129
result = query_instance.unhealthy_projects(
130130
is_contributors_requirement_compliant=True,
131131
is_funding_requirements_compliant=False,
132-
has_recent_commits=True,
132+
has_no_recent_commits=True,
133133
has_recent_releases=True,
134134
is_leader_requirements_compliant=True,
135135
limit=10,
@@ -144,7 +144,7 @@ def test_resolve_unhealthy_projects_with_filters(self):
144144
mock_queryset.order_by.assert_called_with("project__key", "-nest_created_at")
145145
mock_queryset.filter.assert_called_with(
146146
contributors_count__gte=2,
147-
has_recent_commits=True,
147+
has_no_recent_commits=True,
148148
has_long_open_issues=True,
149149
has_long_unanswered_issues=True,
150150
has_long_unassigned_issues=True,

backend/tests/apps/owasp/models/project_health_metrics_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def test_default_score(self):
6969
("age_days", 0),
7070
("contributors_count", 0),
7171
("forks_count", 0),
72+
("has_no_recent_commits", False),
73+
("has_long_open_issues", False),
74+
("has_long_unanswered_issues", False),
75+
("has_long_unassigned_issues", False),
7276
("is_funding_requirements_compliant", False),
7377
("is_leader_requirements_compliant", False),
7478
("last_committed_at", None),

0 commit comments

Comments
 (0)