Skip to content

Commit

Permalink
Backport #56778 to 23.9: Fix pygithub
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-clickhouse committed Nov 21, 2023
1 parent f2d9b8d commit 5aa3472
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 9 additions & 6 deletions tests/ci/cherry_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,19 @@ def ping_cherry_pick_assignees(self, dry_run: bool) -> None:
"Checking if cherry-pick PR #%s needs to be pinged",
self.cherrypick_pr.number,
)
since_updated = datetime.now() - self.cherrypick_pr.updated_at
# The `updated_at` is Optional[datetime]
cherrypick_updated_ts = (
self.cherrypick_pr.updated_at or datetime.now()
).timestamp()
since_updated = int(datetime.now().timestamp() - cherrypick_updated_ts)
since_updated_str = (
f"{since_updated.days}d{since_updated.seconds // 3600}"
f"h{since_updated.seconds // 60 % 60}m{since_updated.seconds % 60}s"
f"{since_updated // 86400}d{since_updated // 3600}"
f"h{since_updated // 60 % 60}m{since_updated % 60}s"
)
if since_updated < timedelta(days=1):
if since_updated < 86400:
logging.info(
"The cherry-pick PR was updated at %s %s ago, "
"The cherry-pick PR was updated %s ago, "
"waiting for the next running",
self.cherrypick_pr.updated_at.isoformat(),
since_updated_str,
)
return
Expand Down
6 changes: 3 additions & 3 deletions tests/ci/github_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_release_pulls(self, repo_name: str) -> PullRequests:
label="release",
)

def sleep_on_rate_limit(self):
def sleep_on_rate_limit(self) -> None:
for limit, data in self.get_rate_limit().raw_data.items():
if data["remaining"] == 0:
sleep_time = data["reset"] - int(datetime.now().timestamp()) + 1
Expand Down Expand Up @@ -199,13 +199,13 @@ def _is_cache_updated(
# We don't want the cache_updated being always old,
# for example in cases when the user is not updated for ages
cache_updated = max(
datetime.fromtimestamp(cache_file.stat().st_mtime), cached_obj.updated_at
cache_file.stat().st_mtime, cached_obj.updated_at.timestamp()
)
if obj_updated_at is None:
# When we don't know about the object is updated or not,
# we update it once per hour
obj_updated_at = datetime.now() - timedelta(hours=1)
if obj_updated_at <= cache_updated:
if obj_updated_at.timestamp() <= cache_updated:
return True, cached_obj
return False, cached_obj

Expand Down
8 changes: 4 additions & 4 deletions tests/ci/merge_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def is_approved(self, team: List[NamedUser]) -> bool:
logging.info("The PR is changed at %s", last_changed.isoformat())

approved_at = max(review.submitted_at for review in approved.values())
if approved_at == datetime.fromtimestamp(0):
if approved_at.timestamp() == 0:
logging.info(
"Unable to get `datetime.fromtimestamp(0)`, "
"here's debug info about reviews: %s",
Expand All @@ -138,7 +138,7 @@ def is_approved(self, team: List[NamedUser]) -> bool:
else:
logging.info("The PR is approved at %s", approved_at.isoformat())

if approved_at < last_changed:
if approved_at.timestamp() < last_changed.timestamp():
logging.info(
"There are changes done at %s after approval at %s",
last_changed.isoformat(),
Expand Down Expand Up @@ -230,8 +230,8 @@ def main():
# An ugly and not nice fix to patch the wrong organization URL,
# see https://github.com/PyGithub/PyGithub/issues/2395#issuecomment-1378629710
# pylint: disable=protected-access
repo.organization._url.value = repo.organization.url.replace( # type: ignore
"/users/", "/orgs/", 1
repo.organization._url = repo._makeStringAttribute(
repo.organization.url.replace("/users/", "/orgs/", 1)
)
# pylint: enable=protected-access
pr = repo.get_pull(args.pr)
Expand Down

0 comments on commit 5aa3472

Please sign in to comment.