Skip to content

Commit

Permalink
fix: Turn failed external link checks into warnings
Browse files Browse the repository at this point in the history
The Github Runners may be firewalled or blacklisted, so only trigger warnings for those links.
  • Loading branch information
FHeilmann authored Jan 22, 2024
1 parent 08494d3 commit 54af3e1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions voron_toolkit/tools/markdown_link_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ def _check_link(self: Self, link: str, markdown_file_relative: str) -> ExtendedR
response = requests.head(link, timeout=5)
response.raise_for_status()
except HTTPError as e:
logger.error("Link '{}' is invalid: {}, {}", link, e.response.status_code, e.response.reason)
self.result_items[ExtendedResultEnum.FAILURE].append(ItemResult(item=markdown_file_relative, extra_info=[f"Link '{link}' is invalid: {e}"]))
return ExtendedResultEnum.FAILURE
logger.warning("Link '{}' is invalid: {}, {}. Please verify it manually", link, e.response.status_code, e.response.reason)
self.result_items[ExtendedResultEnum.WARNING].append(ItemResult(item=markdown_file_relative, extra_info=[f"Link '{link}' returned {e}"]))
return ExtendedResultEnum.WARNING
self.result_items[ExtendedResultEnum.SUCCESS].append(ItemResult(item=markdown_file_relative, extra_info=[f"Link '{link}' is valid!"]))
return ExtendedResultEnum.SUCCESS

# The link is a relative path, check if the file exists
if Path(markdown_file_folder_absolute, link).exists():
self.result_items[ExtendedResultEnum.SUCCESS].append(ItemResult(item=markdown_file_relative, extra_info=[f"Relative link '{link}' is valid!"]))
return ExtendedResultEnum.SUCCESS

self.result_items[ExtendedResultEnum.FAILURE].append(ItemResult(item=markdown_file_relative, extra_info=[f"Relative link '{link}' is invalid!"]))
logger.error("Relative link '{}' is invalid!", Path(markdown_file_folder_absolute, link))
return ExtendedResultEnum.FAILURE
if not Path(markdown_file_folder_absolute, link).exists():
self.result_items[ExtendedResultEnum.FAILURE].append(ItemResult(item=markdown_file_relative, extra_info=[f"Relative link '{link}' is invalid!"]))
logger.error("Relative link '{}' is invalid!", Path(markdown_file_folder_absolute, link))
return ExtendedResultEnum.FAILURE
self.result_items[ExtendedResultEnum.SUCCESS].append(ItemResult(item=markdown_file_relative, extra_info=[f"Relative link '{link}' is valid!"]))
return ExtendedResultEnum.SUCCESS

def _check_markdown(self: Self, markdown_file: Path) -> ExtendedResultEnum:
markdown_content: str = markdown_file.read_text()
Expand Down

0 comments on commit 54af3e1

Please sign in to comment.