Skip to content

Commit 4a4e152

Browse files
committed
Clear leftover cherry-picker state to prevent invalidrepoexception
1 parent 8bd2474 commit 4a4e152

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

miss_islington/tasks.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import logging
23
import os
34
import ssl
45
import subprocess
@@ -15,6 +16,7 @@
1516

1617
from . import util
1718

19+
logger = logging.getLogger(__name__)
1820

1921
app = celery.Celery("backport_cpython")
2022

@@ -116,16 +118,39 @@ async def backport_task_asyncio(
116118
# Ensure that we don't have any changes lying around
117119
subprocess.check_output(['git', 'reset', '--hard'])
118120
subprocess.check_output(['git', 'clean', '-fxd'])
119-
120-
cp = cherry_picker.CherryPicker(
121-
"origin",
122-
commit_hash,
123-
[branch],
124-
config=CHERRY_PICKER_CONFIG,
125-
prefix_commit=False,
121+
# Clear any leftover cherry-picker state from a previously interrupted
122+
# run; otherwise CherryPicker() init raises InvalidRepoException and
123+
# every subsequent backport on this worker silently fails.
124+
subprocess.run(
125+
['git', 'config', '--local', '--remove-section', 'cherry-picker'],
126+
stderr=subprocess.DEVNULL,
127+
check=False,
126128
)
129+
127130
try:
131+
cp = cherry_picker.CherryPicker(
132+
"origin",
133+
commit_hash,
134+
[branch],
135+
config=CHERRY_PICKER_CONFIG,
136+
prefix_commit=False,
137+
)
128138
cp.backport()
139+
except cherry_picker.InvalidRepoException as ire:
140+
await util.comment_on_pr(
141+
gh,
142+
issue_number,
143+
f"""\
144+
Sorry {util.get_participants(created_by, merged_by)}, I had trouble backporting to `{branch}`.
145+
Please retry by removing and re-adding the "needs backport to {branch}" label.
146+
Alternatively, you can backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on the command line.
147+
```
148+
cherry_picker {commit_hash} {branch}
149+
```
150+
""",
151+
)
152+
await util.assign_pr_to_core_dev(gh, issue_number, merged_by)
153+
logger.exception("InvalidRepoException while backporting to %s", branch)
129154
except cherry_picker.BranchCheckoutException as bce:
130155
await util.comment_on_pr(
131156
gh,

0 commit comments

Comments
 (0)