Skip to content

Commit

Permalink
fix: Treat internal URLs starting with __root_url__ as valid ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay-Lysenko committed Feb 28, 2024
1 parent c6ac238 commit 7cff14a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions git_hooks/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ def validate_internal_urls(internal_urls: list[str], headers: list[str], tags: l
headers = [x.lstrip('# ').rstrip(')') for x in headers]
for internal_url in internal_urls:
split_url = internal_url.split('/')
if split_url[0] != '__home_url__':
if split_url[0] == '__root_url__':
conditions = [
split_url[2] == 'notes' and split_url[3] in headers,
split_url[2] == 'tags' and split_url[3] in tags
]
elif split_url[0] == '__home_url__':
conditions = [
split_url[1] == 'notes' and split_url[2] in headers,
split_url[1] == 'tags' and split_url[2] in tags
]
else:
raise ValueError(
f"URLs must start with either 'http' or '__home_url__', but '{internal_url}' found"
"URLs must start with 'http', '__root_url__', or '__home_url__', "
f"but '{internal_url}' found"
)
conditions = [
split_url[1] == 'notes' and split_url[2] in headers,
split_url[1] == 'tags' and split_url[2] in tags
]
if not any(conditions):
raise ValueError(f"URL '{internal_url}' points to non-existent page")

Expand Down

0 comments on commit 7cff14a

Please sign in to comment.