Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit f158f05

Browse files
committed
feature: git: github api: Enable ignoring errors for a repo
Signed-off-by: John Andersen <[email protected]>
1 parent e91b7d2 commit f158f05

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

feature/git/dffml_feature_git/github_api.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
2+
import sys
23
import json
4+
import time
35
import asyncio
46
import logging
57

@@ -172,15 +174,33 @@ def make_github_operations(
172174
for repo_url in repo_urls:
173175
try:
174176
# Fork the repository
177+
print("\n\n\n\nUPDATING FOR", repo_url, "\n\n\n", file=sys.stderr)
175178
org, repo_name = repo_url.split("/")[-2:]
176179
repo = g.get_repo(f"{org}/{repo_name}")
177180
fork = user.create_fork(repo)
178181

182+
# Create a new branch from the default branch
183+
fork_not_ready_error = None
184+
for i in range(0, 5):
185+
try:
186+
fork_default_branch = fork.get_branch(fork.default_branch)
187+
fork_not_ready_error = None
188+
break
189+
except github.GithubException as error:
190+
fork_not_ready_error = error
191+
time.sleep(2)
192+
if fork_not_ready_error is not None:
193+
try:
194+
raise Exception(
195+
"Fork not yet ready"
196+
) from fork_not_ready_error
197+
except Exception as error:
198+
logger.error(error)
199+
continue
200+
179201
commit_message = make_commit_message(repo, fork)
180202
pull_request_body = make_pull_request_body(repo, fork)
181203

182-
# Create a new branch from the default branch
183-
fork_default_branch = fork.get_branch(fork.default_branch)
184204
try:
185205
fork.create_git_ref(
186206
ref="refs/heads/" + new_branch_name,
@@ -241,17 +261,27 @@ def make_github_operations(
241261
snoop.pp(fork)
242262
base = base_repo.default_branch
243263
head = f"{user.login}:{fork.name}:{new_branch_name}"
244-
base_repo.create_pull(
264+
pr = base_repo.create_pull(
245265
title=commit_message,
246266
body=pull_request_body,
247267
head=head,
248268
base=base,
249269
)
250270

251-
except GithubException as error:
252-
raise Exception(
253-
f"Unable to complete operations for {repo_url} due to {error}"
254-
) from error
271+
print(
272+
"\n\n\n\nUPDATED SUCCESSFULLY",
273+
pr.html_url,
274+
"\n\n\n",
275+
file=sys.stderr,
276+
)
277+
278+
except Exception as error:
279+
try:
280+
raise Exception(
281+
f"Unable to complete operations for {repo_url} due to {error}"
282+
) from error
283+
except Exception as error:
284+
logger.error(error)
255285

256286

257287
import pathlib

0 commit comments

Comments
 (0)