[ez] Add try catch for deleting old branches (#119696)

I think some chars in branch names affect the api calls, so just assume they're protected
Pull Request resolved: https://github.com/pytorch/pytorch/pull/119696
Approved by: https://github.com/huydhn
This commit is contained in:
Catherine Lee 2024-02-12 21:08:59 +00:00 committed by PyTorch MergeBot
parent 7eecbf8a30
commit ad217d4266

View file

@ -95,11 +95,15 @@ query ($owner: String!, $repo: String!, $cursor: String) {
def is_protected(branch: str) -> bool:
ESTIMATED_TOKENS[0] += 1
res = gh_fetch_json_dict(
f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/branches/{branch}"
)
return bool(res["protected"])
try:
ESTIMATED_TOKENS[0] += 1
res = gh_fetch_json_dict(
f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/branches/{branch}"
)
return bool(res["protected"])
except Exception as e:
print(f"[{branch}] Failed to fetch branch protections: {e}")
return True
def convert_gh_timestamp(date: str) -> float: