Skip to content

Commit a3da33c

Browse files
JelteFFennemAI
andauthored
Allow marking an already closed patch as committed (#129)
When a patch in the open commitfest was already closed, for example as "Returned with feedback", and a committer then marked it as committed, this crashed with `UserInputError: Patch in state Returned with feedback cannot be moved.`. The "committed" action first moves the patch to the in progress commitfest (or from the draft to the regular open commitfest) so that it gets recorded in the commitfest it was actually committed in, but `Patch.move()` refused to move closed patches. `Patch.move()` now takes an `allow_move_closed` argument, which the commit action passes. Because closed statuses require a leavedate, the new `PatchOnCommitFest` gets one when the patch it was moved from was closed. Co-authored-by: Jelterminator FennemAI-Neo <fennemai@jeltef.nl>
1 parent 33f7288 commit a3da33c

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

‎pgcommitfest/commitfest/models.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,13 @@ def update_lastmail(self):
598598
self.lastmail = max(threads, key=lambda t: t.latestmessage).latestmessage
599599

600600
def move(
601-
self, from_cf, to_cf, by_user, allow_move_to_in_progress=False, by_cfbot=False
601+
self,
602+
from_cf,
603+
to_cf,
604+
by_user,
605+
allow_move_to_in_progress=False,
606+
allow_move_closed=False,
607+
by_cfbot=False,
602608
):
603609
"""Returns the new PatchOnCommitFest object, or raises UserInputError"""
604610

@@ -609,11 +615,7 @@ def move(
609615
if from_cf.id == to_cf.id:
610616
raise UserInputError("Source and target commitfest are the same.")
611617

612-
if current_poc.status not in (
613-
PatchOnCommitFest.STATUS_REVIEW,
614-
PatchOnCommitFest.STATUS_AUTHOR,
615-
PatchOnCommitFest.STATUS_COMMITTER,
616-
):
618+
if current_poc.is_closed and not allow_move_closed:
617619
raise UserInputError(
618620
f"Patch in state {current_poc.statusstring} cannot be moved."
619621
)
@@ -625,16 +627,18 @@ def move(
625627
raise UserInputError("Patch can only be moved to an open commitfest")
626628

627629
old_status = current_poc.status
630+
was_closed = current_poc.is_closed
628631

629632
current_poc.set_status(PatchOnCommitFest.STATUS_MOVED)
630633

634+
now = datetime.now()
631635
new_poc, _ = PatchOnCommitFest.objects.update_or_create(
632636
patch=current_poc.patch,
633637
commitfest=to_cf,
634638
defaults=dict(
635639
status=old_status,
636-
enterdate=datetime.now(),
637-
leavedate=None,
640+
enterdate=now,
641+
leavedate=now if was_closed else None,
638642
),
639643
)
640644
new_poc.save()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from datetime import datetime
2+
3+
import pytest
4+
5+
from pgcommitfest.commitfest.models import Committer, Patch, PatchOnCommitFest
6+
7+
pytestmark = pytest.mark.django_db
8+
9+
10+
@pytest.mark.parametrize(
11+
"status",
12+
[PatchOnCommitFest.STATUS_REVIEW, PatchOnCommitFest.STATUS_RETURNED],
13+
)
14+
def test_commit_moves_patch_to_in_progress_cf(
15+
client, open_cf, in_progress_cf, alice, status
16+
):
17+
Committer.objects.create(user=alice)
18+
patch = Patch.objects.create(name="Test patch")
19+
poc = PatchOnCommitFest.objects.create(
20+
patch=patch,
21+
commitfest=open_cf,
22+
enterdate=datetime.now(),
23+
status=PatchOnCommitFest.STATUS_REVIEW,
24+
)
25+
poc.set_status(status)
26+
27+
client.force_login(alice)
28+
response = client.post(f"/patch/{patch.id}/close/committed/?c={alice.username}")
29+
assert response.status_code == 302
30+
31+
old_poc = PatchOnCommitFest.objects.get(patch=patch, commitfest=open_cf)
32+
assert old_poc.status == PatchOnCommitFest.STATUS_MOVED
33+
new_poc = PatchOnCommitFest.objects.get(patch=patch, commitfest=in_progress_cf)
34+
assert new_poc.status == PatchOnCommitFest.STATUS_COMMITTED
35+
patch.refresh_from_db()
36+
assert patch.committer.user == alice

‎pgcommitfest/commitfest/views.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,20 +1179,26 @@ def close(request, patchid, status):
11791179
if poc.commitfest.is_open:
11801180
# Needs to be done before the next if condition, so the committer
11811181
# that's set there is set on the correct poc.
1182+
#
1183+
# A patch that was already closed (e.g. returned with feedback)
1184+
# might still get committed later, and then it should also end up
1185+
# in the commitfest it was committed in.
11821186
in_progress_cf = CommitFest.get_in_progress()
11831187
if in_progress_cf is not None:
11841188
poc = patch.move(
11851189
poc.commitfest,
11861190
in_progress_cf,
11871191
request.user,
11881192
allow_move_to_in_progress=True,
1193+
allow_move_closed=True,
11891194
)
11901195
elif poc.commitfest.draft:
11911196
open_cf = CommitFest.get_open_regular()
11921197
poc = patch.move(
11931198
poc.commitfest,
11941199
open_cf,
11951200
request.user,
1201+
allow_move_closed=True,
11961202
)
11971203

11981204
committer_username = request.GET.get("c")

0 commit comments

Comments
 (0)