|
1 | 1 | import asyncio |
| 2 | +import logging |
2 | 3 | import os |
3 | 4 | import ssl |
4 | 5 | import subprocess |
|
15 | 16 |
|
16 | 17 | from . import util |
17 | 18 |
|
| 19 | +logger = logging.getLogger(__name__) |
18 | 20 |
|
19 | 21 | app = celery.Celery("backport_cpython") |
20 | 22 |
|
@@ -116,16 +118,39 @@ async def backport_task_asyncio( |
116 | 118 | # Ensure that we don't have any changes lying around |
117 | 119 | subprocess.check_output(['git', 'reset', '--hard']) |
118 | 120 | 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, |
126 | 128 | ) |
| 129 | + |
127 | 130 | try: |
| 131 | + cp = cherry_picker.CherryPicker( |
| 132 | + "origin", |
| 133 | + commit_hash, |
| 134 | + [branch], |
| 135 | + config=CHERRY_PICKER_CONFIG, |
| 136 | + prefix_commit=False, |
| 137 | + ) |
128 | 138 | 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) |
129 | 154 | except cherry_picker.BranchCheckoutException as bce: |
130 | 155 | await util.comment_on_pr( |
131 | 156 | gh, |
|
0 commit comments