Skip to content

Commit

Permalink
Use committedDate instead of deprecated pushedDate
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoWilken committed Nov 29, 2023
1 parent d0a5ab1 commit 679ff71
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions list-branch-pr
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class RepoConfig:
)
)

def process_single_pr(self, pull_number, last_commit,
def process_single_pr(self, pull_number, last_commit, pr_created,
is_draft=False, is_trusted=False):
"""Decide whether to queue this PR (or branch) for testing.
Expand All @@ -180,30 +180,39 @@ class RepoConfig:
("succeeded" if success else "failed")
else:
state = "skip"
updated_time = last_commit["pushedDate"]
print(f"pr: {pull_number:6d}@{commit_hash:.7s}: upd={updated_time} "

# The PR has been waiting for checks either since it was created or
# since its latest commit was pushed. commit["pushedDate"] was
# unfortunately deprecated and removed by GitHub, so committedDate
# will have to do. Eliminate a common source for errors by falling
# back to the PR creation time, in case the commit was created well
# before the PR.
waiting_since = max(pr_created, last_commit["committedDate"])
print(f"pr: {pull_number:6d}@{commit_hash:.7s}: wait={waiting_since} "
f"revd={reviewed:d} trust={is_trusted:d} tested={tested:d} "
f"success={success:d} => state={state}", file=sys.stderr)
return None if state == "skip" else (state, {
"number": pull_number,
"sha": commit_hash,
"build_config": self.build_config,
"updated_at": updated_time,
"waiting_since": waiting_since,
})

def process_pulls(self, session, repo_info, show_base_branch=False):
"""Return pull requests we can process, with relevant attributes."""
for pull in repo_info["pullRequests"]["nodes"]:
item = self.process_single_pr(
pull["number"], pull["commits"]["nodes"][0]["commit"],
pull["createdAt"],
is_draft=pull["isDraft"] or pull["title"].startswith("[WIP]"),
is_trusted=self.trust_pr(session, pull),
)
if item is not None:
yield item

if show_base_branch:
item = self.process_single_pr(self.branch_ref, repo_info["object"])
item = self.process_single_pr(self.branch_ref, repo_info["object"],
pull["createdAt"])
if item is not None:
yield item

Expand Down Expand Up @@ -255,14 +264,14 @@ def main(args):
# Sort by PR number so that older PRs are built first. Don't use
# .sort() here as it modifies the list in-place, and that list might
# also be used elsewhere.
# pr["updated_at"] can apparently be None sometimes, which breaks
# pr["waiting_since"] can apparently be None sometimes, which breaks
# sorting, so default to the empty string if so.
for pull in sorted(prs, key=lambda pr: pr["updated_at"] or ""):
updated_at = pull["updated_at"]
last_push = datetime.fromisoformat(updated_at) \
if updated_at else datetime.now(timezone.utc)
for pull in sorted(prs, key=lambda pr: pr["waiting_since"] or ""):
commit_timestr = pull["waiting_since"]
commit_time = datetime.fromisoformat(commit_timestr) \
if commit_timestr else datetime.now(timezone.utc)
print(group, pull["number"], pull["sha"], pull["build_config"],
int(last_push.timestamp()), sep="\t")
int(commit_time.timestamp()), sep="\t")

if grouped["untested"]:
# If there are untested PRs waiting, build all of them first.
Expand Down Expand Up @@ -368,6 +377,7 @@ query statuses(
number
title
isDraft
createdAt
authorAssociation
author {
login
Expand All @@ -394,7 +404,7 @@ query statuses(
fragment commitInfo on Commit {
oid
pushedDate
committedDate
status {
contexts {
context
Expand Down

0 comments on commit 679ff71

Please sign in to comment.