From 2e0325c80e186cb241601a4ec0bdda3e26a37448 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:48:39 +0100 Subject: [PATCH 01/13] Add reviewers to the patch JSON --- pgcommitfest/commitfest/apiv1.py | 2 +- pgcommitfest/commitfest/models.py | 3 +++ pgcommitfest/commitfest/tests/test_apiv1.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 9d6109ad..8948bce3 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -77,7 +77,7 @@ def commitfest_patches(request, cfid): pocs = ( PatchOnCommitFest.objects.filter(commitfest=cf) .select_related("patch") - .prefetch_related("patch__authors") + .prefetch_related("patch__authors", "patch__reviewers") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index c7b8fb4f..53ba41fc 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -659,6 +659,9 @@ def to_json(self): "id": self.id, "name": self.name, "authors": [f"{a.first_name} {a.last_name}" for a in self.authors.all()], + "reviewers": [ + f"{r.first_name} {r.last_name}" for r in self.reviewers.all() + ], "last_email_time": self.lastmail, } diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 539f29e1..0eb6bc3a 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -129,6 +129,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): # Create test patches patch1 = Patch.objects.create(name="Add feature X") patch1.authors.add(alice) + patch1.reviewers.add(bob) patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.save() @@ -192,6 +193,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): assert p1["name"] == "Add feature X" assert p1["status"] == "Needs review" assert p1["authors"] == ["Alice Anderson"] + assert p1["reviewers"] == ["Bob Brown"] assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["enterdate"] == "2025-01-01T12:00:00+00:00" assert p1["leavedate"] is None @@ -201,6 +203,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): assert p2["name"] == "Fix bug Y" assert p2["status"] == "Committed" assert sorted(p2["authors"]) == ["Alice Anderson", "Bob Brown"] + assert p2["reviewers"] == [] assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From b9a7a7f07f1a3571add10fc14a9482e3257479b4 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:48:57 +0100 Subject: [PATCH 02/13] Add committer to the patch JSON --- pgcommitfest/commitfest/apiv1.py | 2 +- pgcommitfest/commitfest/models.py | 5 +++++ pgcommitfest/commitfest/tests/test_apiv1.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 8948bce3..6d506722 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -76,7 +76,7 @@ def commitfest_patches(request, cfid): pocs = ( PatchOnCommitFest.objects.filter(commitfest=cf) - .select_related("patch") + .select_related("patch__committer__user") .prefetch_related("patch__authors", "patch__reviewers") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 53ba41fc..6a16a962 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -662,6 +662,11 @@ def to_json(self): "reviewers": [ f"{r.first_name} {r.last_name}" for r in self.reviewers.all() ], + "committer": ( + f"{self.committer.user.first_name} {self.committer.user.last_name}" + if self.committer + else None + ), "last_email_time": self.lastmail, } diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 0eb6bc3a..c59b8b7b 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -7,6 +7,7 @@ import pytest from pgcommitfest.commitfest.models import ( + Committer, MailThread, MailThreadAttachment, Patch, @@ -124,7 +125,7 @@ def test_needs_ci_endpoint(client, commitfests): assert data == expected -def test_commitfest_patches_endpoint(client, open_cf, alice, bob): +def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): """Test the /api/v1/commitfests//patches endpoint.""" # Create test patches patch1 = Patch.objects.create(name="Add feature X") @@ -135,6 +136,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): patch2 = Patch.objects.create(name="Fix bug Y") patch2.authors.add(alice, bob) + patch2.committer = Committer.objects.create(user=charlie) patch2.save() # Link patches to commitfest @@ -194,6 +196,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): assert p1["status"] == "Needs review" assert p1["authors"] == ["Alice Anderson"] assert p1["reviewers"] == ["Bob Brown"] + assert p1["committer"] is None assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["enterdate"] == "2025-01-01T12:00:00+00:00" assert p1["leavedate"] is None @@ -204,6 +207,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob): assert p2["status"] == "Committed" assert sorted(p2["authors"]) == ["Alice Anderson", "Bob Brown"] assert p2["reviewers"] == [] + assert p2["committer"] == "Charlie Chen" assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From d00dd20028d6ee2365d388f9adfcad9c6c60f986 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:48:58 +0100 Subject: [PATCH 03/13] Add target_version to the patch JSON --- pgcommitfest/commitfest/apiv1.py | 2 +- pgcommitfest/commitfest/models.py | 3 +++ pgcommitfest/commitfest/tests/test_apiv1.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 6d506722..29066e06 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -76,7 +76,7 @@ def commitfest_patches(request, cfid): pocs = ( PatchOnCommitFest.objects.filter(commitfest=cf) - .select_related("patch__committer__user") + .select_related("patch__committer__user", "patch__targetversion") .prefetch_related("patch__authors", "patch__reviewers") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 6a16a962..ae204133 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -667,6 +667,9 @@ def to_json(self): if self.committer else None ), + "target_version": ( + self.targetversion.version if self.targetversion else None + ), "last_email_time": self.lastmail, } diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index c59b8b7b..76888356 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -12,6 +12,7 @@ MailThreadAttachment, Patch, PatchOnCommitFest, + TargetVersion, ) pytestmark = pytest.mark.django_db @@ -131,6 +132,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): patch1 = Patch.objects.create(name="Add feature X") patch1.authors.add(alice) patch1.reviewers.add(bob) + patch1.targetversion = TargetVersion.objects.create(version="19") patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.save() @@ -197,6 +199,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["authors"] == ["Alice Anderson"] assert p1["reviewers"] == ["Bob Brown"] assert p1["committer"] is None + assert p1["target_version"] == "19" assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["enterdate"] == "2025-01-01T12:00:00+00:00" assert p1["leavedate"] is None @@ -208,6 +211,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert sorted(p2["authors"]) == ["Alice Anderson", "Bob Brown"] assert p2["reviewers"] == [] assert p2["committer"] == "Charlie Chen" + assert p2["target_version"] is None assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From 9f5a408aab9111f3089986d36ff68cc9a934df8b Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:49:11 +0100 Subject: [PATCH 04/13] Add created and modified to the patch JSON --- pgcommitfest/commitfest/models.py | 2 ++ pgcommitfest/commitfest/tests/test_apiv1.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index ae204133..1c17faa9 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -671,6 +671,8 @@ def to_json(self): self.targetversion.version if self.targetversion else None ), "last_email_time": self.lastmail, + "created": self.created, + "modified": self.modified, } def __str__(self): diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 76888356..d9cf52b0 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -134,6 +134,8 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): patch1.reviewers.add(bob) patch1.targetversion = TargetVersion.objects.create(version="19") patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) + patch1.created = datetime(2024, 12, 20, 9, 0, 0, tzinfo=timezone.utc) + patch1.modified = datetime(2025, 1, 14, 17, 15, 0, tzinfo=timezone.utc) patch1.save() patch2 = Patch.objects.create(name="Fix bug Y") @@ -201,6 +203,8 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["committer"] is None assert p1["target_version"] == "19" assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" + assert p1["created"] == "2024-12-20T09:00:00+00:00" + assert p1["modified"] == "2025-01-14T17:15:00+00:00" assert p1["enterdate"] == "2025-01-01T12:00:00+00:00" assert p1["leavedate"] is None From 8c1e880dcf97861ec62f3fa1b2689551ca2d83cd Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:49:55 +0100 Subject: [PATCH 05/13] Add GET /api/v1/patches//history endpoint --- pgcommitfest/commitfest/apiv1.py | 27 ++++++++ pgcommitfest/commitfest/models.py | 10 +++ pgcommitfest/commitfest/tests/test_apiv1.py | 77 +++++++++++++++++++++ pgcommitfest/urls.py | 1 + 4 files changed, 115 insertions(+) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 29066e06..58ca58e9 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -1,5 +1,6 @@ from django.db.models import Prefetch, QuerySet from django.http import ( + Http404, HttpResponse, ) from django.shortcuts import get_object_or_404 @@ -11,6 +12,7 @@ CommitFest, MailThread, Patch, + PatchHistory, PatchOnCommitFest, ) @@ -121,3 +123,28 @@ def patch_threads(request, patch_id): "threads": threads, } ) + + +def patch_history(request, patch_id): + """Return the activity history of a patch, oldest first. + + This is the same history shown on the patch page, including the entries + made by cfbot. + """ + # Checking existence avoids loading the patch itself, which also loads + # all of its many-to-many relations. + if not Patch.objects.filter(pk=patch_id).exists(): + raise Http404("Patch not found") + + history = ( + PatchHistory.objects.filter(patch_id=patch_id) + .select_related("by") + .order_by("date", "id") + ) + + return api_response( + { + "patch_id": int(patch_id), + "history": history, + } + ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 1c17faa9..86cfb26c 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -809,6 +809,16 @@ def by_string(self): def __str__(self): return "%s - %s" % (self.patch.name, self.date) + def to_json(self): + return { + "id": self.id, + "patch_id": self.patch_id, + "date": self.date, + "by": f"{self.by.first_name} {self.by.last_name}" if self.by else None, + "by_cfbot": self.by_cfbot, + "what": self.what, + } + class Meta: ordering = ("-date",) constraints = [ diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index d9cf52b0..34249eca 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -11,6 +11,7 @@ MailThread, MailThreadAttachment, Patch, + PatchHistory, PatchOnCommitFest, TargetVersion, ) @@ -313,3 +314,79 @@ def test_patch_threads_endpoint_not_found(client, commitfests): """Test the threads endpoint returns 404 for non-existent patch.""" response = client.get("/api/v1/patches/99999/threads") assert response.status_code == 404 + + +def make_history(patch, date, what, by=None): + """Create a PatchHistory row at a fixed date (date is auto_now_add).""" + entry = PatchHistory.objects.create( + patch=patch, by=by, by_cfbot=by is None, what=what + ) + PatchHistory.objects.filter(pk=entry.pk).update(date=date) + return entry + + +def test_patch_history_endpoint(client, alice): + """Test the /api/v1/patches//history endpoint.""" + patch = Patch.objects.create(name="Test patch") + other = Patch.objects.create(name="Other patch") + + created = make_history( + patch, datetime(2025, 1, 1, 12, 0, 0, tzinfo=timezone.utc), "Created", alice + ) + rebase = make_history( + patch, + datetime(2025, 1, 3, 8, 0, 0, tzinfo=timezone.utc), + "Patch needs rebase", + ) + status = make_history( + patch, + datetime(2025, 1, 2, 9, 30, 0, tzinfo=timezone.utc), + "New status: Ready for Committer", + alice, + ) + make_history( + other, datetime(2025, 1, 2, 10, 0, 0, tzinfo=timezone.utc), "Created", alice + ) + + response = client.get(f"/api/v1/patches/{patch.id}/history") + + assert response.status_code == 200 + assert response["Content-Type"] == "application/json" + assert response["Access-Control-Allow-Origin"] == "*" + + # Oldest first, only this patch, cfbot entries included + assert json.loads(response.content) == { + "patch_id": patch.id, + "history": [ + { + "id": created.id, + "patch_id": patch.id, + "date": "2025-01-01T12:00:00+00:00", + "by": "Alice Anderson", + "by_cfbot": False, + "what": "Created", + }, + { + "id": status.id, + "patch_id": patch.id, + "date": "2025-01-02T09:30:00+00:00", + "by": "Alice Anderson", + "by_cfbot": False, + "what": "New status: Ready for Committer", + }, + { + "id": rebase.id, + "patch_id": patch.id, + "date": "2025-01-03T08:00:00+00:00", + "by": None, + "by_cfbot": True, + "what": "Patch needs rebase", + }, + ], + } + + +def test_patch_history_endpoint_not_found(client, commitfests): + """Test the history endpoint returns 404 for non-existent patch.""" + response = client.get("/api/v1/patches/99999/history") + assert response.status_code == 404 diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index de80e32c..f239ee32 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -20,6 +20,7 @@ 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), + re_path(r"^api/v1/patches/(\d+)/history$", apiv1.patch_history), re_path(r"^help/$", views.help), re_path(r"^commitfest_history/$", views.commitfest_history_legacy_redirect), re_path(r"^me/$", views.me_legacy_redirect), From 517dabb3245f7ccbf2a702fe050522f3de24acb7 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Fri, 6 Nov 2026 01:50:23 +0100 Subject: [PATCH 06/13] Add GET /api/v1/history feed with a keyset cursor --- pgcommitfest/commitfest/apiv1.py | 51 +++++++++++- pgcommitfest/commitfest/tests/test_apiv1.py | 88 +++++++++++++++++++++ pgcommitfest/urls.py | 1 + 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 58ca58e9..cf186e55 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -1,4 +1,4 @@ -from django.db.models import Prefetch, QuerySet +from django.db.models import Prefetch, Q, QuerySet from django.http import ( Http404, HttpResponse, @@ -7,6 +7,7 @@ import json from datetime import date, datetime, timedelta, timezone +from urllib.parse import urlencode from .models import ( CommitFest, @@ -43,6 +44,9 @@ def api_response(payload, status=200, content_type="application/json"): return response +HISTORY_PAGE_SIZE = 500 + + def all_commitfests(request): """Return all commitfests, including closed ones.""" return api_response({"commitfests": CommitFest.objects.order_by("id")}) @@ -148,3 +152,48 @@ def patch_history(request, patch_id): "history": history, } ) + + +def history(request): + """Return the activity history of all patches, oldest first. + + ?since= returns entries from that time on. Pages hold at most + HISTORY_PAGE_SIZE entries; when there are more, "next" is the URL of the + following page, otherwise it is null. Entries can share a timestamp, so + the cursor also carries the id of the last entry returned (?after=). + """ + since = request.GET.get("since") + after = request.GET.get("after") + + entries = PatchHistory.objects.select_related("by").order_by("date", "id") + + if since is not None: + try: + since = datetime.fromisoformat(since) + except ValueError: + return api_response({"error": "since must be an ISO 8601 date"}, 400) + # Dates are stored in UTC without a timezone + if since.tzinfo is not None: + since = since.astimezone(timezone.utc).replace(tzinfo=None) + entries = entries.filter(date__gte=since) + + if after is not None: + if since is None: + return api_response({"error": "after requires since"}, 400) + try: + after = int(after) + except ValueError: + return api_response({"error": "after must be an integer"}, 400) + entries = entries.filter(Q(date__gt=since) | Q(id__gt=after)) + + page = list(entries[: HISTORY_PAGE_SIZE + 1]) + next_url = None + if len(page) > HISTORY_PAGE_SIZE: + page = page[:HISTORY_PAGE_SIZE] + last = page[-1] + next_url = "{}?{}".format( + request.path, + urlencode({"since": datetime_serializer(last.date), "after": last.id}), + ) + + return api_response({"history": page, "next": next_url}) diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 34249eca..ab5e61d9 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -6,6 +6,7 @@ import pytest +from pgcommitfest.commitfest import apiv1 from pgcommitfest.commitfest.models import ( Committer, MailThread, @@ -390,3 +391,90 @@ def test_patch_history_endpoint_not_found(client, commitfests): """Test the history endpoint returns 404 for non-existent patch.""" response = client.get("/api/v1/patches/99999/history") assert response.status_code == 404 + + +def test_history_endpoint(client, alice): + """Test the /api/v1/history endpoint.""" + patch1 = Patch.objects.create(name="Add feature X") + patch2 = Patch.objects.create(name="Fix bug Y") + + first = make_history( + patch1, datetime(2025, 1, 1, 12, 0, 0, tzinfo=timezone.utc), "Created", alice + ) + rebase = make_history( + patch2, + datetime(2025, 1, 3, 8, 0, 0, tzinfo=timezone.utc), + "Patch needs rebase", + ) + status = make_history( + patch1, + datetime(2025, 1, 2, 9, 30, 0, tzinfo=timezone.utc), + "New status: Ready for Committer", + alice, + ) + + response = client.get("/api/v1/history") + + assert response.status_code == 200 + assert response["Content-Type"] == "application/json" + assert response["Access-Control-Allow-Origin"] == "*" + + # All patches, oldest first, cfbot entries included + data = json.loads(response.content) + assert data["next"] is None + assert [h["id"] for h in data["history"]] == [first.id, status.id, rebase.id] + assert data["history"][2] == { + "id": rebase.id, + "patch_id": patch2.id, + "date": "2025-01-03T08:00:00+00:00", + "by": None, + "by_cfbot": True, + "what": "Patch needs rebase", + } + + # since is inclusive and accepts any timezone + response = client.get("/api/v1/history", {"since": "2025-01-02T10:30:00+01:00"}) + data = json.loads(response.content) + assert [h["id"] for h in data["history"]] == [status.id, rebase.id] + + +def test_history_endpoint_pagination(client, alice, monkeypatch): + """Following next walks every entry once, even across shared timestamps.""" + monkeypatch.setattr(apiv1, "HISTORY_PAGE_SIZE", 2) + patch = Patch.objects.create(name="Add feature X") + + # A bulk move at commitfest close gives many entries the same timestamp + close = datetime(2025, 2, 1, 0, 0, 0, tzinfo=timezone.utc) + entries = [ + make_history(patch, datetime(2025, 1, 1, tzinfo=timezone.utc), "Created", alice) + ] + [make_history(patch, close, f"Moved {i}") for i in range(4)] + + seen = [] + url = "/api/v1/history" + pages = 0 + while url: + response = client.get(url) + assert response.status_code == 200 + data = json.loads(response.content) + assert len(data["history"]) <= 2 + seen.extend(h["id"] for h in data["history"]) + url = data["next"] + pages += 1 + + assert seen == [e.id for e in entries] + assert pages == 3 + + +@pytest.mark.parametrize( + "params", + [ + {"since": "yesterday"}, + {"after": "1"}, + {"since": "2025-01-01T00:00:00+00:00", "after": "x"}, + ], +) +def test_history_endpoint_bad_params(client, params): + """Test the history endpoint rejects malformed cursors.""" + response = client.get("/api/v1/history", params) + assert response.status_code == 400 + assert "error" in json.loads(response.content) diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index f239ee32..b3cbe730 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -21,6 +21,7 @@ re_path(r"^api/v1/commitfests/(\d+)/patches$", apiv1.commitfest_patches), re_path(r"^api/v1/patches/(\d+)/threads$", apiv1.patch_threads), re_path(r"^api/v1/patches/(\d+)/history$", apiv1.patch_history), + re_path(r"^api/v1/history$", apiv1.history), re_path(r"^help/$", views.help), re_path(r"^commitfest_history/$", views.commitfest_history_legacy_redirect), re_path(r"^me/$", views.me_legacy_redirect), From a6260a0a9905771ee94fd8bc2b87da564d0aa1ae Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 18:19:47 +0900 Subject: [PATCH 07/13] Tighten comments in the history endpoints --- pgcommitfest/commitfest/apiv1.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index cf186e55..0d89d1a6 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -130,13 +130,8 @@ def patch_threads(request, patch_id): def patch_history(request, patch_id): - """Return the activity history of a patch, oldest first. - - This is the same history shown on the patch page, including the entries - made by cfbot. - """ - # Checking existence avoids loading the patch itself, which also loads - # all of its many-to-many relations. + """Return the activity history of a patch, oldest first.""" + # Checking existence avoids loading relations. if not Patch.objects.filter(pk=patch_id).exists(): raise Http404("Patch not found") @@ -157,10 +152,10 @@ def patch_history(request, patch_id): def history(request): """Return the activity history of all patches, oldest first. - ?since= returns entries from that time on. Pages hold at most - HISTORY_PAGE_SIZE entries; when there are more, "next" is the URL of the - following page, otherwise it is null. Entries can share a timestamp, so - the cursor also carries the id of the last entry returned (?after=). + ?since= returns entries from that time on; ?after= breaks + ties between entries sharing a timestamp. "next" is the URL of the + following page, or null on the last one. Malformed parameters return + 400 with {"error": ""}. """ since = request.GET.get("since") after = request.GET.get("after") @@ -172,7 +167,7 @@ def history(request): since = datetime.fromisoformat(since) except ValueError: return api_response({"error": "since must be an ISO 8601 date"}, 400) - # Dates are stored in UTC without a timezone + # Dates are stored as naive UTC if since.tzinfo is not None: since = since.astimezone(timezone.utc).replace(tzinfo=None) entries = entries.filter(date__gte=since) From 7894f00696cb5a401641fbc390bafe377f748bf3 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 20:57:25 +0900 Subject: [PATCH 08/13] Add topic to the patch JSON --- pgcommitfest/commitfest/apiv1.py | 4 +++- pgcommitfest/commitfest/models.py | 1 + pgcommitfest/commitfest/tests/test_apiv1.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 0d89d1a6..eaf66af7 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -82,7 +82,9 @@ def commitfest_patches(request, cfid): pocs = ( PatchOnCommitFest.objects.filter(commitfest=cf) - .select_related("patch__committer__user", "patch__targetversion") + .select_related( + "patch__committer__user", "patch__targetversion", "patch__topic" + ) .prefetch_related("patch__authors", "patch__reviewers") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 86cfb26c..7653e8fe 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -670,6 +670,7 @@ def to_json(self): "target_version": ( self.targetversion.version if self.targetversion else None ), + "topic": self.topic.topic if self.topic else None, "last_email_time": self.lastmail, "created": self.created, "modified": self.modified, diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index ab5e61d9..12dc73c7 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -15,6 +15,7 @@ PatchHistory, PatchOnCommitFest, TargetVersion, + Topic, ) pytestmark = pytest.mark.django_db @@ -135,6 +136,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): patch1.authors.add(alice) patch1.reviewers.add(bob) patch1.targetversion = TargetVersion.objects.create(version="19") + patch1.topic = Topic.objects.create(topic="Performance") patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.created = datetime(2024, 12, 20, 9, 0, 0, tzinfo=timezone.utc) patch1.modified = datetime(2025, 1, 14, 17, 15, 0, tzinfo=timezone.utc) @@ -204,6 +206,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["reviewers"] == ["Bob Brown"] assert p1["committer"] is None assert p1["target_version"] == "19" + assert p1["topic"] == "Performance" assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["created"] == "2024-12-20T09:00:00+00:00" assert p1["modified"] == "2025-01-14T17:15:00+00:00" @@ -218,6 +221,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p2["reviewers"] == [] assert p2["committer"] == "Charlie Chen" assert p2["target_version"] is None + assert p2["topic"] is None assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From e5ad54c3b1bae23758a4f7c27915fbe0d1c408d0 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 20:57:26 +0900 Subject: [PATCH 09/13] Add tags to the patch JSON --- pgcommitfest/commitfest/apiv1.py | 2 +- pgcommitfest/commitfest/models.py | 1 + pgcommitfest/commitfest/tests/test_apiv1.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index eaf66af7..899a17ab 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -85,7 +85,7 @@ def commitfest_patches(request, cfid): .select_related( "patch__committer__user", "patch__targetversion", "patch__topic" ) - .prefetch_related("patch__authors", "patch__reviewers") + .prefetch_related("patch__authors", "patch__reviewers", "patch__tags") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 7653e8fe..cfddf4b1 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -671,6 +671,7 @@ def to_json(self): self.targetversion.version if self.targetversion else None ), "topic": self.topic.topic if self.topic else None, + "tags": [t.name for t in self.tags.all()], "last_email_time": self.lastmail, "created": self.created, "modified": self.modified, diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 12dc73c7..9a5a5234 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -14,6 +14,7 @@ Patch, PatchHistory, PatchOnCommitFest, + Tag, TargetVersion, Topic, ) @@ -137,6 +138,10 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): patch1.reviewers.add(bob) patch1.targetversion = TargetVersion.objects.create(version="19") patch1.topic = Topic.objects.create(topic="Performance") + patch1.tags.add( + Tag.objects.create(name="API tag A", color="#ff0000"), + Tag.objects.create(name="API tag B", color="#00ff00"), + ) patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.created = datetime(2024, 12, 20, 9, 0, 0, tzinfo=timezone.utc) patch1.modified = datetime(2025, 1, 14, 17, 15, 0, tzinfo=timezone.utc) @@ -207,6 +212,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["committer"] is None assert p1["target_version"] == "19" assert p1["topic"] == "Performance" + assert p1["tags"] == ["API tag A", "API tag B"] assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["created"] == "2024-12-20T09:00:00+00:00" assert p1["modified"] == "2025-01-14T17:15:00+00:00" @@ -222,6 +228,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p2["committer"] == "Charlie Chen" assert p2["target_version"] is None assert p2["topic"] is None + assert p2["tags"] == [] assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From e4758364b0517273f32873faf2ce6c8fe60e7551 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 20:57:28 +0900 Subject: [PATCH 10/13] Add wiki_link to the patch JSON --- pgcommitfest/commitfest/models.py | 1 + pgcommitfest/commitfest/tests/test_apiv1.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index cfddf4b1..03be5c89 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -672,6 +672,7 @@ def to_json(self): ), "topic": self.topic.topic if self.topic else None, "tags": [t.name for t in self.tags.all()], + "wiki_link": self.wikilink or None, "last_email_time": self.lastmail, "created": self.created, "modified": self.modified, diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 9a5a5234..36b55db9 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -142,6 +142,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): Tag.objects.create(name="API tag A", color="#ff0000"), Tag.objects.create(name="API tag B", color="#00ff00"), ) + patch1.wikilink = "https://wiki.postgresql.org/wiki/Feature_X" patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.created = datetime(2024, 12, 20, 9, 0, 0, tzinfo=timezone.utc) patch1.modified = datetime(2025, 1, 14, 17, 15, 0, tzinfo=timezone.utc) @@ -213,6 +214,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["target_version"] == "19" assert p1["topic"] == "Performance" assert p1["tags"] == ["API tag A", "API tag B"] + assert p1["wiki_link"] == "https://wiki.postgresql.org/wiki/Feature_X" assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["created"] == "2024-12-20T09:00:00+00:00" assert p1["modified"] == "2025-01-14T17:15:00+00:00" @@ -229,6 +231,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p2["target_version"] is None assert p2["topic"] is None assert p2["tags"] == [] + assert p2["wiki_link"] is None assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From f4dc0102643602e0542a49d11c5b7fbc29db877b Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 20:57:30 +0900 Subject: [PATCH 11/13] Add git_link to the patch JSON --- pgcommitfest/commitfest/models.py | 1 + pgcommitfest/commitfest/tests/test_apiv1.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 03be5c89..5e49510c 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -673,6 +673,7 @@ def to_json(self): "topic": self.topic.topic if self.topic else None, "tags": [t.name for t in self.tags.all()], "wiki_link": self.wikilink or None, + "git_link": self.gitlink or None, "last_email_time": self.lastmail, "created": self.created, "modified": self.modified, diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 36b55db9..24ff3cab 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -143,6 +143,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): Tag.objects.create(name="API tag B", color="#00ff00"), ) patch1.wikilink = "https://wiki.postgresql.org/wiki/Feature_X" + patch1.gitlink = "https://github.com/example/postgres/tree/feature-x" patch1.lastmail = datetime(2025, 1, 15, 10, 30, 0, tzinfo=timezone.utc) patch1.created = datetime(2024, 12, 20, 9, 0, 0, tzinfo=timezone.utc) patch1.modified = datetime(2025, 1, 14, 17, 15, 0, tzinfo=timezone.utc) @@ -215,6 +216,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["topic"] == "Performance" assert p1["tags"] == ["API tag A", "API tag B"] assert p1["wiki_link"] == "https://wiki.postgresql.org/wiki/Feature_X" + assert p1["git_link"] == "https://github.com/example/postgres/tree/feature-x" assert p1["last_email_time"] == "2025-01-15T10:30:00+00:00" assert p1["created"] == "2024-12-20T09:00:00+00:00" assert p1["modified"] == "2025-01-14T17:15:00+00:00" @@ -232,6 +234,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p2["topic"] is None assert p2["tags"] == [] assert p2["wiki_link"] is None + assert p2["git_link"] is None assert p2["last_email_time"] is None assert p2["enterdate"] == "2025-01-02T08:00:00+00:00" assert p2["leavedate"] == "2025-01-20T16:45:00+00:00" From c6e6d1197538dd09b6991d9dd8d500cf431a447d Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Mon, 16 Nov 2026 21:01:31 +0900 Subject: [PATCH 12/13] Revert "Add topic to the patch JSON" This reverts commit 7894f00696cb5a401641fbc390bafe377f748bf3. --- pgcommitfest/commitfest/apiv1.py | 4 +--- pgcommitfest/commitfest/models.py | 1 - pgcommitfest/commitfest/tests/test_apiv1.py | 4 ---- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index 899a17ab..b6edb6fb 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -82,9 +82,7 @@ def commitfest_patches(request, cfid): pocs = ( PatchOnCommitFest.objects.filter(commitfest=cf) - .select_related( - "patch__committer__user", "patch__targetversion", "patch__topic" - ) + .select_related("patch__committer__user", "patch__targetversion") .prefetch_related("patch__authors", "patch__reviewers", "patch__tags") .order_by("patch__id") ) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 5e49510c..eb903470 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -670,7 +670,6 @@ def to_json(self): "target_version": ( self.targetversion.version if self.targetversion else None ), - "topic": self.topic.topic if self.topic else None, "tags": [t.name for t in self.tags.all()], "wiki_link": self.wikilink or None, "git_link": self.gitlink or None, diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index 24ff3cab..a2d0eb6b 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -16,7 +16,6 @@ PatchOnCommitFest, Tag, TargetVersion, - Topic, ) pytestmark = pytest.mark.django_db @@ -137,7 +136,6 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): patch1.authors.add(alice) patch1.reviewers.add(bob) patch1.targetversion = TargetVersion.objects.create(version="19") - patch1.topic = Topic.objects.create(topic="Performance") patch1.tags.add( Tag.objects.create(name="API tag A", color="#ff0000"), Tag.objects.create(name="API tag B", color="#00ff00"), @@ -213,7 +211,6 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p1["reviewers"] == ["Bob Brown"] assert p1["committer"] is None assert p1["target_version"] == "19" - assert p1["topic"] == "Performance" assert p1["tags"] == ["API tag A", "API tag B"] assert p1["wiki_link"] == "https://wiki.postgresql.org/wiki/Feature_X" assert p1["git_link"] == "https://github.com/example/postgres/tree/feature-x" @@ -231,7 +228,6 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob, charlie): assert p2["reviewers"] == [] assert p2["committer"] == "Charlie Chen" assert p2["target_version"] is None - assert p2["topic"] is None assert p2["tags"] == [] assert p2["wiki_link"] is None assert p2["git_link"] is None From 631006fce26423dc4aac36ac7f01abb02f89bde8 Mon Sep 17 00:00:00 2001 From: Kevin Rocker Date: Tue, 17 Nov 2026 12:54:25 +0900 Subject: [PATCH 13/13] Add GET /api/v1/patches/ endpoint --- pgcommitfest/commitfest/apiv1.py | 22 ++++++ pgcommitfest/commitfest/tests/test_apiv1.py | 80 +++++++++++++++++++++ pgcommitfest/urls.py | 1 + 3 files changed, 103 insertions(+) diff --git a/pgcommitfest/commitfest/apiv1.py b/pgcommitfest/commitfest/apiv1.py index b6edb6fb..1b80c926 100644 --- a/pgcommitfest/commitfest/apiv1.py +++ b/pgcommitfest/commitfest/apiv1.py @@ -110,6 +110,28 @@ def commitfest_patches(request, cfid): ) +def patch(request, patch_id): + """Return a patch on its current commitfest, with its threads. + + The patch has the same shape as in /commitfests//patches. A missing + patch returns 404 with {"error": ""}. + """ + poc = ( + PatchOnCommitFest.objects.filter(patch_id=patch_id) + .exclude(status=PatchOnCommitFest.STATUS_MOVED) + .select_related("patch__committer__user", "patch__targetversion") + .prefetch_related("patch__authors", "patch__reviewers", "patch__tags") + .first() + ) + if poc is None: + return api_response({"error": "Patch not found"}, 404) + + entry = poc.to_json() + entry["threads"] = poc.patch.mailthread_set.with_has_attachment() + + return api_response({"commitfest_id": poc.commitfest_id, "patch": entry}) + + def patch_threads(request, patch_id): """Return thread information for a patch. diff --git a/pgcommitfest/commitfest/tests/test_apiv1.py b/pgcommitfest/commitfest/tests/test_apiv1.py index a2d0eb6b..ca3c452a 100644 --- a/pgcommitfest/commitfest/tests/test_apiv1.py +++ b/pgcommitfest/commitfest/tests/test_apiv1.py @@ -280,6 +280,86 @@ def test_commitfest_patches_endpoint_not_found(client, commitfests): assert response.status_code == 404 +def test_patch_endpoint(client, commitfests, alice, bob): + """Test the /api/v1/patches/ endpoint.""" + patch = Patch.objects.create(name="Add feature X") + patch.authors.add(alice) + patch.reviewers.add(bob) + patch.tags.add(Tag.objects.create(name="API tag A", color="#ff0000")) + + # An earlier commitfest the patch moved out of + PatchOnCommitFest.objects.create( + patch=patch, + commitfest=commitfests["in_progress"], + enterdate=datetime(2024, 11, 1, 12, 0, 0, tzinfo=timezone.utc), + leavedate=datetime(2024, 11, 30, 12, 0, 0, tzinfo=timezone.utc), + status=PatchOnCommitFest.STATUS_MOVED, + ) + PatchOnCommitFest.objects.create( + patch=patch, + commitfest=commitfests["open"], + enterdate=datetime(2025, 1, 1, 12, 0, 0, tzinfo=timezone.utc), + status=PatchOnCommitFest.STATUS_AUTHOR, + ) + + thread = MailThread.objects.create( + messageid="abc123@example.com", + subject="[PATCH] Add feature X", + firstmessage=datetime(2025, 1, 10, 9, 0, 0, tzinfo=timezone.utc), + firstauthor="alice@example.com", + latestmessage=datetime(2025, 1, 12, 14, 30, 0, tzinfo=timezone.utc), + latestauthor="bob@example.com", + latestsubject="Re: [PATCH] Add feature X", + latestmsgid="def456@example.com", + ) + patch.mailthread_set.add(thread) + MailThreadAttachment.objects.create( + mailthread=thread, + messageid="abc123@example.com", + attachmentid=1, + filename="v1.patch", + date=datetime(2025, 1, 10, 9, 0, 0, tzinfo=timezone.utc), + author="alice@example.com", + ispatch=True, + ) + + response = client.get(f"/api/v1/patches/{patch.id}") + + assert response.status_code == 200 + assert response["Content-Type"] == "application/json" + assert response["Access-Control-Allow-Origin"] == "*" + + data = json.loads(response.content) + + assert data["commitfest_id"] == commitfests["open"].id + p = data["patch"] + assert p["id"] == patch.id + assert p["name"] == "Add feature X" + assert p["status"] == "Waiting on Author" + assert p["authors"] == ["Alice Anderson"] + assert p["reviewers"] == ["Bob Brown"] + assert p["tags"] == ["API tag A"] + assert p["enterdate"] == "2025-01-01T12:00:00+00:00" + assert p["leavedate"] is None + assert p["threads"] == [ + { + "messageid": "abc123@example.com", + "subject": "[PATCH] Add feature X", + "latest_message_id": "def456@example.com", + "latest_message_time": "2025-01-12T14:30:00+00:00", + "has_attachment": True, + } + ] + + +def test_patch_endpoint_not_found(client, commitfests): + """Test the patch endpoint returns a JSON 404 for non-existent patch.""" + response = client.get("/api/v1/patches/99999") + assert response.status_code == 404 + assert response["Content-Type"] == "application/json" + assert json.loads(response.content) == {"error": "Patch not found"} + + def test_patch_threads_endpoint(client, open_cf, alice): """Test the /api/v1/patches//threads endpoint.""" patch = Patch.objects.create(name="Test patch") diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index b3cbe730..3f4666d2 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -19,6 +19,7 @@ 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+)$", apiv1.patch), re_path(r"^api/v1/patches/(\d+)/threads$", apiv1.patch_threads), re_path(r"^api/v1/patches/(\d+)/history$", apiv1.patch_history), re_path(r"^api/v1/history$", apiv1.history),