Place short return before big block, improve logging

This commit is contained in:
Mikhail f. Shiryaev 2023-03-21 11:29:16 +01:00
parent 91e1de2d59
commit b9dca4e0df
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4

View File

@ -100,27 +100,33 @@ class Reviews:
if review.state == "APPROVED"
}
if approved:
if not approved:
logging.info(
"The PR #%s is not approved by any of %s team member",
self.pr.number,
TEAM_NAME,
)
return False
logging.info(
"The following users from %s team approved the PR: %s",
TEAM_NAME,
", ".join(user.login for user in approved.keys()),
)
# The only reliable place to get the 100% accurate last_modified
# info is when the commit was pushed to GitHub. The info is
# available as a header 'last-modified' of /{org}/{repo}/commits/{sha}.
# Unfortunately, it's formatted as 'Wed, 04 Jan 2023 11:05:13 GMT'
commit = self.pr.head.repo.get_commit(self.pr.head.sha)
if commit.stats.last_modified is None:
logging.warning(
"Unable to get info about the commit %s", self.pr.head.sha
)
logging.warning("Unable to get info about the commit %s", self.pr.head.sha)
return False
last_changed = datetime.strptime(
commit.stats.last_modified, "%a, %d %b %Y %H:%M:%S GMT"
)
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):
@ -130,26 +136,17 @@ class Reviews:
"\n".join(pformat(review) for review in self.reviews.values()),
)
else:
logging.info(
"The PR is approved at %s",
approved_at.isoformat(),
)
logging.info("The PR is approved at %s", approved_at.isoformat())
if approved_at < last_changed:
logging.info(
"There are changes after approve at %s",
"There are changes done at %s after approval at %s",
last_changed.isoformat(),
approved_at.isoformat(),
)
return False
return True
logging.info(
"The PR #%s is not approved by any of %s team member",
self.pr.number,
TEAM_NAME,
)
return False
def get_workflows_for_head(repo: Repository, head_sha: str) -> List[WorkflowRun]:
# The monkey-patch until the PR is merged: