The referenced Trac ticket must have has_patch=1. Uses initial_data (the dict returned by fetch_trac_ticket()) on the first check, then polls via fetch_trac_ticket() every poll_interval seconds for up to poll_timeout seconds. Set poll_timeout=0 for a single check with no retries. Pa
(ticket_id, initial_data, poll_interval=1, poll_timeout=10)
| 272 | |
| 273 | |
| 274 | def check_trac_has_patch(ticket_id, initial_data, poll_interval=1, poll_timeout=10): |
| 275 | """The referenced Trac ticket must have has_patch=1. |
| 276 | |
| 277 | Uses initial_data (the dict returned by fetch_trac_ticket()) on the first |
| 278 | check, then polls via fetch_trac_ticket() every poll_interval seconds for |
| 279 | up to poll_timeout seconds. Set poll_timeout=0 for a single check with no |
| 280 | retries. Passing None for initial_data skips the check entirely. |
| 281 | """ |
| 282 | deadline = time.monotonic() + poll_timeout |
| 283 | elapsed = 0 |
| 284 | ticket_data = initial_data |
| 285 | |
| 286 | while True: |
| 287 | logger.info( |
| 288 | "Checking has_patch flag for ticket-%s (elapsed: %ss) ...", |
| 289 | ticket_id, |
| 290 | elapsed, |
| 291 | ) |
| 292 | if ticket_data is None: |
| 293 | return None # Non-fatal fetch error; skip. |
| 294 | if ticket_data is TICKET_NOT_FOUND: |
| 295 | # Ticket not found -- already reported by check_trac_status. |
| 296 | return None |
| 297 | has_patch = ticket_data.get("custom", {}).get("has_patch", "0").strip() |
| 298 | if has_patch == "1": |
| 299 | logger.info("ticket-%s has_patch flag is set.", ticket_id) |
| 300 | return None |
| 301 | remaining = deadline - time.monotonic() |
| 302 | if remaining <= 0: |
| 303 | break |
| 304 | logger.info( |
| 305 | " has_patch not yet set -- will retry in %ss.", |
| 306 | poll_interval, |
| 307 | ) |
| 308 | sleep_time = min(poll_interval, remaining) |
| 309 | time.sleep(sleep_time) |
| 310 | elapsed += int(sleep_time) |
| 311 | ticket_data = fetch_trac_ticket(ticket_id) |
| 312 | |
| 313 | logger.warning( |
| 314 | "ticket-%s has_patch flag was not set after %ss.", |
| 315 | ticket_id, |
| 316 | poll_timeout, |
| 317 | ) |
| 318 | return Message(*MISSING_HAS_PATCH_FLAG, ticket_id=ticket_id) |
| 319 | |
| 320 | |
| 321 | def check_pr_title_has_ticket(pr_title, ticket_id): |