fix bug in print test stats

Apparently GIT_DEFAULT_BRACH can be empty, it looks like `github.event.repository.default_branch` is not populated for schedule-triggered workflows
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74349
Approved by: https://github.com/seemethere, https://github.com/janeyx99
This commit is contained in:
Michael Suo 2022-03-16 23:01:53 +00:00 committed by PyTorch MergeBot
parent b604314aa6
commit e1d2d3f480

View file

@ -107,9 +107,14 @@ def plural(n: int) -> str:
def get_base_commit(sha1: str) -> str:
default_branch = f"origin/{os.environ.get('GIT_DEFAULT_BRANCH', 'master')}"
default_branch = os.environ.get('GIT_DEFAULT_BRANCH')
# capture None and "" cases
if not default_branch:
default_branch = "master"
default_remote = f"origin/{default_branch}"
return subprocess.check_output(
["git", "merge-base", sha1, default_branch],
["git", "merge-base", sha1, default_remote],
encoding="ascii",
).strip()