From 4e2b6c56b043fecb1bef97dd0e8690432ec6c99a Mon Sep 17 00:00:00 2001 From: Sainjargal Ishdorj <67509383+frxdude@users.noreply.github.com> Date: Wed, 15 Oct 2025 10:06:45 +0800 Subject: [PATCH 1/2] Add doctest to get_files_url for pull request URL example Added comprehensive doctest to the get_files_url() function including: - Example usage with tempfile and environment variables - Expected output format - Documentation of potential exceptions (KeyError and FileNotFoundError) --- scripts/validate_solutions.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/validate_solutions.py b/scripts/validate_solutions.py index f426153b5683..133899f6e8a7 100755 --- a/scripts/validate_solutions.py +++ b/scripts/validate_solutions.py @@ -49,9 +49,26 @@ def all_solution_file_paths() -> list[pathlib.Path]: def get_files_url() -> str: - """Return the pull request number which triggered this action.""" - with open(os.environ["GITHUB_EVENT_PATH"]) as file: - event = json.load(file) + """ + Return the pull request files URL from the GitHub event file. + + Example: + >>> import os, json, tempfile + >>> data = {"pull_request": {"url": "https://github.com/example/repo/pull/42"}} + >>> with tempfile.NamedTemporaryFile("w", delete=False) as f: + ... json.dump(data, f) + ... os.environ["GITHUB_EVENT_PATH"] = f.name + >>> get_files_url() + 'https://github.com/example/repo/pull/42/files' + >>> os.unlink(f.name) + + Raises: + KeyError: if 'pull_request' or 'url' keys are missing in the event file. + FileNotFoundError: if GITHUB_EVENT_PATH is missing. + """ + import os, json + with open(os.environ["GITHUB_EVENT_PATH"]) as f: + event = json.load(f) return event["pull_request"]["url"] + "/files" From 577e2276e01d8ccd22ac7b7053730bd4e36b5516 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 Oct 2025 02:08:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/validate_solutions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/validate_solutions.py b/scripts/validate_solutions.py index 133899f6e8a7..00acf8966b84 100755 --- a/scripts/validate_solutions.py +++ b/scripts/validate_solutions.py @@ -67,6 +67,7 @@ def get_files_url() -> str: FileNotFoundError: if GITHUB_EVENT_PATH is missing. """ import os, json + with open(os.environ["GITHUB_EVENT_PATH"]) as f: event = json.load(f) return event["pull_request"]["url"] + "/files"