|
12 | 12 | from __future__ import annotations |
13 | 13 |
|
14 | 14 | import logging |
| 15 | +import subprocess |
15 | 16 | from dataclasses import dataclass |
16 | 17 |
|
17 | 18 | from repo_sync.stack.branches import check_idempotency |
@@ -94,9 +95,17 @@ def enumerate_unsynced_commits( |
94 | 95 | # Filter out sync-originated commits. |
95 | 96 | result = [] |
96 | 97 | for sha in all_commits: |
97 | | - if is_sync_originated(source_git, source_gh, sha): |
98 | | - logger.info("Skipping sync-originated commit %s.", sha[:12]) |
99 | | - continue |
| 98 | + try: |
| 99 | + if is_sync_originated(source_git, source_gh, sha): |
| 100 | + logger.info("Skipping sync-originated commit %s.", sha[:12]) |
| 101 | + continue |
| 102 | + except subprocess.CalledProcessError: |
| 103 | + logger.error( |
| 104 | + "GitHub API failure during loop detection for commit %s. " |
| 105 | + "Aborting sync to avoid creating an infinite loop.", |
| 106 | + sha[:12], |
| 107 | + ) |
| 108 | + raise |
100 | 109 | result.append(sha) |
101 | 110 |
|
102 | 111 | return result |
@@ -146,7 +155,15 @@ def build_public_to_private_description( |
146 | 155 | direct pushes. |
147 | 156 | """ |
148 | 157 | source_repo_name = source_repo.split("/")[-1] |
149 | | - source_pr = source_gh.get_pr_for_commit(source_sha) |
| 158 | + try: |
| 159 | + source_pr = source_gh.get_pr_for_commit(source_sha) |
| 160 | + except subprocess.CalledProcessError: |
| 161 | + logger.warning( |
| 162 | + "GitHub API error looking up PR for commit %s; " |
| 163 | + "falling back to commit-based description.", |
| 164 | + source_sha[:12], |
| 165 | + ) |
| 166 | + source_pr = None |
150 | 167 |
|
151 | 168 | if source_pr is not None: |
152 | 169 | return public_to_private_from_pr( |
@@ -180,7 +197,15 @@ def determine_sync_reviewer( |
180 | 197 | Tries the merger of the source PR first, then the commit author (via |
181 | 198 | GitHub API), then the fallback team. |
182 | 199 | """ |
183 | | - source_pr = source_gh.get_pr_for_commit(source_sha) |
| 200 | + try: |
| 201 | + source_pr = source_gh.get_pr_for_commit(source_sha) |
| 202 | + except subprocess.CalledProcessError: |
| 203 | + logger.warning( |
| 204 | + "GitHub API error looking up PR for commit %s; " |
| 205 | + "falling back to commit author or team for reviewer.", |
| 206 | + source_sha[:12], |
| 207 | + ) |
| 208 | + source_pr = None |
184 | 209 | pr_number = source_pr.number if source_pr else None |
185 | 210 |
|
186 | 211 | # For direct pushes (no source PR), look up the commit author via the API. |
|
0 commit comments