This repository was archived by the owner on Oct 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.py
More file actions
51 lines (44 loc) · 1.84 KB
/
github.py
File metadata and controls
51 lines (44 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations
import subprocess
from contextlib import contextmanager
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from job import Job
from branch import Branch
@dataclass
class PR:
number: int
title: str
state: str
author: str
is_draft: bool
head: str
base: str
@contextmanager
def handle_gh_backoff(job: Job, branch: Branch, branch_name: str | None = None):
job_name = type(job).__name__
try:
yield
except subprocess.CalledProcessError as e:
# move this to a method to call more often
if 'No commits between' in e.stderr:
if branch_name is None:
raise ValueError("Got a no commits error, but no branch name was provided")
print (f"No commits were found between branches (master..{branch_name}).. deleting the branch")
try:
branch.delete_remote_branch(branch_name)
except subprocess.CalledProcessError as e:
if branch_name in branch.list_remote_branches():
print(f"Failed to delete branch {branch_name}.. but it still exists.. raising")
raise
else:
print(f"Failed to delete branch {branch_name}.. but its already raised.. ignoring")
elif '502' in e.stderr and 'bug' in e.stderr:
print (f"Unexpected 502 (GH bug). Though it doesn't appear to be a rate-limit: {job_name}")
elif 'the merge commit cannot be cleanly created' in e.stderr:
print (f"GH claims it can't make the merge commit.. likely delay in previous merge: {job_name}")
elif 'API rate limit exceeded' in e.stderr:
job.request_backoff(f"GH API rate limit exceeded: {job_name}", 60)
else:
job.request_backoff(f"Unkown error: {e}", 5)