Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pgcommitfest/commitfest/apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions pgcommitfest/commitfest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
67 changes: 67 additions & 0 deletions pgcommitfest/commitfest/tests/test_apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -30,20 +94,23 @@ 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",
},
"in_progress": {
"id": commitfests["in_progress"].id,
"name": "2024-11",
"status": "In Progress",
"draft": False,
"startdate": "2024-11-01",
"enddate": "2024-11-30",
},
"draft": {
"id": commitfests["draft"].id,
"name": "2025-03-draft",
"status": "Open",
"draft": True,
"startdate": "2025-03-01",
"enddate": "2025-03-31",
},
Expand Down
1 change: 1 addition & 0 deletions pgcommitfest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading