Skip to content
Open
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
24 changes: 21 additions & 3 deletions scripts/validate_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,27 @@


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

Check failure on line 69 in scripts/validate_solutions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

scripts/validate_solutions.py:69:5: I001 Import block is un-sorted or un-formatted

Check failure on line 69 in scripts/validate_solutions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E401)

scripts/validate_solutions.py:69:5: E401 Multiple imports on one line

with open(os.environ["GITHUB_EVENT_PATH"]) as f:
event = json.load(f)
return event["pull_request"]["url"] + "/files"


Expand Down
Loading