Skip to content

Commit 1ab6977

Browse files
authored
ci: use pagination to retrieve complete list of changed files [backport #6818 to 1.18] (#6829)
Backport of #6818 to 1.18 We make sure to fetch all the pages from the call to the pull request GitHub REST API so that we can get the full list of changed files, instead of just the first 30 entries. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that.
1 parent 7bca241 commit 1ab6977

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

scripts/needs_testrun.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from argparse import ArgumentParser
44
import fnmatch
55
from functools import cache
6+
from itertools import count
67
import json
78
import logging
89
import os
@@ -72,13 +73,18 @@ def get_changed_files(pr_number: int, sha: t.Optional[str] = None) -> t.Set[str]
7273
"""
7374
rest_check_failed = False
7475
if sha is None:
76+
files = set()
7577
try:
76-
url = f"https://api.github.com/repos/datadog/dd-trace-py/pulls/{pr_number}/files"
77-
headers = {"Accept": "application/vnd.github+json"}
78-
return {_["filename"] for _ in json.load(urlopen(Request(url, headers=headers)))}
78+
for page in count(1):
79+
url = f"https://api.github.com/repos/datadog/dd-trace-py/pulls/{pr_number}/files?page={page}"
80+
headers = {"Accept": "application/vnd.github+json"}
81+
result = {_["filename"] for _ in json.load(urlopen(Request(url, headers=headers)))}
82+
if not result:
83+
return files
84+
files |= result
7985
except Exception:
8086
rest_check_failed = True
81-
LOGGER.warning("Failed to get changed files from GitHub API")
87+
LOGGER.warning("Failed to get changed files from GitHub API", exc_info=True)
8288

8389
if sha is not None or rest_check_failed:
8490
diff_base = sha or get_merge_base(pr_number)
@@ -175,7 +181,9 @@ def main() -> bool:
175181

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

181189
args = argp.parse_args()

0 commit comments

Comments
 (0)