Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci suitespec): default to diffing against base branch if exactly 30 changed files returned #6649

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions scripts/needs_testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ def get_changed_files(pr_number: int, sha: t.Optional[str] = None) -> t.Set[str]
try:
url = f"https://api.github.com/repos/datadog/dd-trace-py/pulls/{pr_number}/files"
headers = {"Accept": "application/vnd.github+json"}
return {_["filename"] for _ in json.load(urlopen(Request(url, headers=headers)))}
result = {_["filename"] for _ in json.load(urlopen(Request(url, headers=headers)))}
if len(result) != 30: # 30 files is an unreliable return because it's the maximum
return result
except Exception as exc:
LOGGER.warning("Failed to get changed files from GitHub API")
LOGGER.warning(exc)

if sha is not None:
diff_base = sha or get_merge_base(pr_number)
LOGGER.info("Checking changed files against commit %s", diff_base)
return set(check_output(["git", "diff", "--name-only", "HEAD", diff_base]).decode("utf-8").strip().splitlines())
diff_base = sha or get_merge_base(pr_number)
LOGGER.info("Checking changed files against commit %s", diff_base)
return set(check_output(["git", "diff", "--name-only", "HEAD", diff_base]).decode("utf-8").strip().splitlines())


@cache
Expand Down Expand Up @@ -174,7 +175,9 @@ def main() -> bool:

argp.add_argument("suite", help="The suite to use", type=str)
argp.add_argument("--pr", help="The PR number", type=int, default=_get_pr_number())
argp.add_argument("--sha", help="Commit hash to use as diff base (defaults to PR merge root)", type=lambda v: v or None)
argp.add_argument(
"--sha", help="Commit hash to use as diff base (defaults to PR merge root)", type=lambda v: v or None
)
argp.add_argument("--verbose", "-v", action="store_true", help="Verbose output")

args = argp.parse_args()
Expand Down
Loading