Skip to content

Commit

Permalink
Merge pull request #157 from con/gh-150b
Browse files Browse the repository at this point in the history
Revert PR #151
  • Loading branch information
yarikoptic committed Nov 2, 2022
2 parents b78f1d8 + a4aeee2 commit a073f29
Showing 1 changed file with 7 additions and 42 deletions.
49 changes: 7 additions & 42 deletions src/tinuous/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from github import Github
from github.GitRelease import GitRelease
from github.GitReleaseAsset import GitReleaseAsset
from github.GithubException import RateLimitExceededException, UnknownObjectException
from github.GithubException import RateLimitExceededException
from github.Repository import Repository
from github.Workflow import Workflow
from github.WorkflowRun import WorkflowRun
from pydantic import BaseModel, Field
import requests
from urllib3.exceptions import ResponseError
from urllib3.util.retry import Retry

from .base import (
Expand All @@ -35,12 +34,6 @@
sanitize_pathname,
)

RETRY_STATUSES = [500, 502, 503, 504]

RETRY_RESPONSE_ERRORS = {
ResponseError.SPECIFIC_ERROR.format(status_code=c): c for c in RETRY_STATUSES
}


def retry_ratelimit(func: Callable) -> Callable:
@wraps(func)
Expand Down Expand Up @@ -73,7 +66,7 @@ def client(self) -> Github:
retry=Retry(
total=12,
backoff_factor=1.25,
status_forcelist=RETRY_STATUSES,
status_forcelist=[500, 502, 503, 504],
),
)

Expand Down Expand Up @@ -105,39 +98,11 @@ def get_workflows(self) -> List[Workflow]:
@retry_ratelimit
def get_runs(self, wf: Workflow, since: datetime) -> List[WorkflowRun]:
runs: List[WorkflowRun] = []
try:
for r in wf.get_runs():
if ensure_aware(r.created_at) <= since:
break
runs.append(r)
return runs
except requests.exceptions.RetryError as e:
reason = e.args[0].reason
if (
isinstance(reason, ResponseError)
and reason.args[0] in RETRY_RESPONSE_ERRORS
and ensure_aware(wf.updated_at) <= since
and not (wf.path and self.has_file(wf.path))
):
log.warning(
"Request for runs for workflow %s (%s) returned %d, and"
" workflow was deleted before starting timestamp; skipping",
wf.path,
wf.name,
RETRY_RESPONSE_ERRORS[reason.args[0]],
)
return []
else:
raise

@retry_ratelimit
def has_file(self, path: str) -> bool:
try:
self.ghrepo.get_contents(path)
except UnknownObjectException:
return False
else:
return True
for r in wf.get_runs():
if ensure_aware(r.created_at) <= since:
break
runs.append(r)
return runs

def get_build_assets(
self, event_types: List[EventType], logs: bool, artifacts: bool
Expand Down

0 comments on commit a073f29

Please sign in to comment.