diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 232eb040..b8cebe4f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,10 +14,13 @@ jobs: - name: Run ruff check uses: astral-sh/ruff-action@v2 + with: + version: 0.15.20 - name: Run ruff format --check uses: astral-sh/ruff-action@v2 with: + version: 0.15.20 args: "format --check" - name: Setup Biome diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 86a53062..a0efea18 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -36,6 +36,11 @@ def api_response(payload, status=200, content_type="application/json"): return response +def all_commitfests(request): + """Return all commitfests, including closed ones.""" + return api_response({"commitfests": list(CommitFest.objects.order_by("id"))}) + + def commitfestst_that_need_ci(request): cfs = CommitFest.relevant_commitfests() diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index b343a213..2d21a1ec 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -106,6 +106,7 @@ def to_json(self): "id": self.id, "name": self.name, "status": self.statusstring, + "draft": self.draft, "startdate": self.startdate.isoformat(), "enddate": self.enddate.isoformat(), } diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 10e1b718..5454da8a 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -12,6 +12,70 @@ pytestmark = pytest.mark.django_db +def test_commitfests_endpoint(client, commitfests): + """Test the /api/v1/commitfests endpoint returns all commitfests.""" + response = client.get("/api/v1/commitfests") + + assert response.status_code == 200 + assert response["Content-Type"] == "application/json" + assert response["Access-Control-Allow-Origin"] == "*" + + data = json.loads(response.content) + + expected = [ + { + "id": commitfests["open"].id, + "name": "2025-01", + "status": "Open", + "draft": False, + "startdate": "2025-01-01", + "enddate": "2025-01-31", + }, + { + "id": commitfests["in_progress"].id, + "name": "2024-11", + "status": "In Progress", + "draft": False, + "startdate": "2024-11-01", + "enddate": "2024-11-30", + }, + { + "id": commitfests["recent_previous"].id, + "name": "2024-09", + "status": "Closed", + "draft": False, + "startdate": "2024-09-01", + "enddate": "2024-09-30", + }, + { + "id": commitfests["old_previous"].id, + "name": "2024-07", + "status": "Closed", + "draft": False, + "startdate": "2024-07-01", + "enddate": "2024-07-31", + }, + { + "id": commitfests["draft"].id, + "name": "2025-03-draft", + "status": "Open", + "draft": True, + "startdate": "2025-03-01", + "enddate": "2025-03-31", + }, + ] + + assert data == {"commitfests": sorted(expected, key=lambda cf: cf["id"])} + + +def test_commitfests_endpoint_empty(client): + """Test the /api/v1/commitfests endpoint with no commitfests.""" + response = client.get("/api/v1/commitfests") + + assert response.status_code == 200 + assert json.loads(response.content) == {"commitfests": []} + + def test_needs_ci_endpoint(client, commitfests): """Test the /api/v1/commitfests/needs_ci endpoint returns correct data.""" response = client.get("/api/v1/commitfests/needs_ci") @@ -30,6 +94,7 @@ def test_needs_ci_endpoint(client, commitfests): "id": commitfests["open"].id, "name": "2025-01", "status": "Open", + "draft": False, "startdate": "2025-01-01", "enddate": "2025-01-31", }, @@ -37,6 +102,7 @@ def test_needs_ci_endpoint(client, commitfests): "id": commitfests["in_progress"].id, "name": "2024-11", "status": "In Progress", + "draft": False, "startdate": "2024-11-01", "enddate": "2024-11-30", }, @@ -44,6 +110,7 @@ def test_needs_ci_endpoint(client, commitfests): "id": commitfests["draft"].id, "name": "2025-03-draft", "status": "Open", + "draft": True, "startdate": "2025-03-01", "enddate": "2025-03-31", }, diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index 61b0941b..f6953347 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -16,6 +16,7 @@ urlpatterns = [ re_path(r"^$", views.home), + re_path(r"^api/v1/commitfests$", apiv1.all_commitfests), re_path(r"^api/v1/commitfests/needs_ci$", apiv1.commitfestst_that_need_ci), re_path(r"^api/v1/commitfests/(\d+)/patches$", apiv1.commitfest_patches), re_path(r"^api/v1/patches/(\d+)/threads$", apiv1.patch_threads),