From aeb786823a6992f6bda22c113a8bace1da744e9a Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Fri, 6 Aug 2021 22:23:45 +0200 Subject: [PATCH] Fix cherry-pick aborting --- miss_islington/tasks.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/miss_islington/tasks.py b/miss_islington/tasks.py index 05035b74..7d07361e 100644 --- a/miss_islington/tasks.py +++ b/miss_islington/tasks.py @@ -99,13 +99,7 @@ async def backport_task_asyncio( """, ) await util.assign_pr_to_core_dev(gh, issue_number, merged_by) - cp = cherry_picker.CherryPicker( - "origin", - commit_hash, - [branch], - config=CHERRY_PICKER_CONFIG, - prefix_commit=False, - ) + cp = _get_cherry_picker(commit_hash, branch) try: cp.backport() except cherry_picker.BranchCheckoutException: @@ -120,6 +114,12 @@ async def backport_task_asyncio( """, ) await util.assign_pr_to_core_dev(gh, issue_number, merged_by) + # We need to set the state to BACKPORT_PAUSED so that CherryPicker allows us to + # abort it, switch back to the default branch, and clean up the backport branch + # + # Ideally, we would be able to do it in a less-hacky way but that will require some changes + # in the upstream, so for now this is probably the best we can do here. + cp.initial_state = cherry_picker.WORKFLOW_STATES.BACKPORT_PAUSED cp.abort_cherry_pick() except cherry_picker.CherryPickException: await util.comment_on_pr( @@ -133,9 +133,21 @@ async def backport_task_asyncio( """, ) await util.assign_pr_to_core_dev(gh, issue_number, merged_by) + # we need to get a new CherryPicker here to get an up-to-date (PAUSED) state + cp = _get_cherry_picker(commit_hash, branch) cp.abort_cherry_pick() +def _get_cherry_picker(commit_hash, branch): + cp = cherry_picker.CherryPicker( + "origin", + commit_hash, + [branch], + config=CHERRY_PICKER_CONFIG, + prefix_commit=False, + ) + + class InitRepoStep(bootsteps.StartStopStep): def start(self, c): print("Initialize the repository.")