diff --git a/list-branch-pr b/list-branch-pr index 6a5c6c5d..00ebb6aa 100755 --- a/list-branch-pr +++ b/list-branch-pr @@ -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. @@ -180,15 +180,22 @@ 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): @@ -196,6 +203,7 @@ class RepoConfig: 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), ) @@ -203,7 +211,8 @@ class RepoConfig: 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 @@ -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. @@ -368,6 +377,7 @@ query statuses( number title isDraft + createdAt authorAssociation author { login @@ -394,7 +404,7 @@ query statuses( fragment commitInfo on Commit { oid - pushedDate + committedDate status { contexts { context