Skip to content

Commit 4c4a2c6

Browse files
committed
Automatically move patches in open CF to in progress CF if they get committed
1 parent a29aa00 commit 4c4a2c6

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

pgcommitfest/commitfest/models.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ def next_draft_cf(start_date):
265265
draft=True,
266266
)
267267

268+
@classmethod
269+
def get_in_progress(cls):
270+
return cls.objects.filter(status=CommitFest.STATUS_INPROGRESS).first()
271+
268272
def __str__(self):
269273
return self.name
270274

@@ -406,7 +410,9 @@ def update_lastmail(self):
406410
else:
407411
self.lastmail = max(threads, key=lambda t: t.latestmessage).latestmessage
408412

409-
def move(self, from_cf, to_cf):
413+
def move(self, from_cf, to_cf, by_user, allow_move_to_in_progress=False):
414+
"""Returns the new PatchOnCommitFest object, or raises UserInputError"""
415+
410416
current_poc = self.current_patch_on_commitfest()
411417
if from_cf.id != current_poc.commitfest.id:
412418
raise UserInputError("Patch not in source commitfest.")
@@ -423,7 +429,10 @@ def move(self, from_cf, to_cf):
423429
f"Patch in state {current_poc.statusstring} cannot be moved."
424430
)
425431

426-
if not to_cf.is_open:
432+
if to_cf.is_in_progress:
433+
if not allow_move_to_in_progress:
434+
raise UserInputError("Patch can only be moved to an open commitfest")
435+
elif not to_cf.is_open:
427436
raise UserInputError("Patch can only be moved to an open commitfest")
428437

429438
old_status = current_poc.status
@@ -443,6 +452,14 @@ def move(self, from_cf, to_cf):
443452
self.set_modified()
444453
self.save()
445454

455+
PatchHistory(
456+
patch=self,
457+
by=by_user,
458+
what=f"Moved from CF {from_cf} to CF {to_cf}",
459+
).save_and_notify()
460+
461+
return new_poc
462+
446463
def __str__(self):
447464
return self.name
448465

pgcommitfest/commitfest/views.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,17 @@ def close(request, patchid, status):
10531053
by=request.user,
10541054
what="Changed committer to %s" % committer,
10551055
).save_and_notify(prevcommitter=prevcommitter)
1056+
1057+
if poc.is_open:
1058+
in_progress_cf = CommitFest.get_in_progress()
1059+
if in_progress_cf is not None:
1060+
poc = patch.move(
1061+
poc.commitfest,
1062+
in_progress_cf,
1063+
request.user,
1064+
allow_move_to_in_progress=True,
1065+
)
1066+
10561067
poc.status = PatchOnCommitFest.STATUS_COMMITTED
10571068

10581069
status_mapping = {
@@ -1098,17 +1109,11 @@ def move(request, patchid):
10981109

10991110
patch = get_object_or_404(Patch, pk=patchid)
11001111
try:
1101-
patch.move(from_cf, to_cf)
1112+
patch.move(from_cf, to_cf, request.user)
11021113
except UserInputError as e:
11031114
messages.error(request, f"Failed to move patch: {e}")
11041115
return HttpResponseRedirect(f"/patch/{patchid}/")
11051116

1106-
PatchHistory(
1107-
patch=patch,
1108-
by=request.user,
1109-
what=f"Moved from CF {from_cf} to CF {to_cf}",
1110-
).save_and_notify()
1111-
11121117
return HttpResponseRedirect(f"/patch/{patchid}/")
11131118

11141119

0 commit comments

Comments
 (0)