Skip to content

Commit

Permalink
Print file names with external links (#44)
Browse files Browse the repository at this point in the history
Files names were printed with internal links but not with external links
which made it harder to decide which files to update when the same link
existed in multiple files. This commit prints file name with external
links also just like with internal links.

Signed-off-by: Gaurav Aggarwal <[email protected]>
  • Loading branch information
aggarg authored Jun 17, 2022
1 parent 830a32f commit b52c91b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions link-verifier/verify-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from termcolor import cprint
from multiprocessing import Pool
import traceback
from collections import defaultdict

MARKDOWN_SEARCH_TERM = r'\.md$'
# Regex to find a URL
Expand Down Expand Up @@ -314,6 +315,7 @@ def main():
broken_links = []
md_file_list = []
link_set = set()
link_to_files = defaultdict(set)
exclude_dirs = [dir.lower() for dir in args.exclude_dirs] if args.exclude_dirs else []

if args.user_agent != None:
Expand Down Expand Up @@ -353,6 +355,7 @@ def main():
urls = re.findall(URL_SEARCH_TERM, text)
for url in urls:
link_set.add(url[0])
link_to_files[url[0]].add(f_path)

# If allowlist file is passed, add those links to link_cache so that link check on those URLs can be bypassed.
if args.allowlist is not None:
Expand Down Expand Up @@ -393,10 +396,12 @@ def main():
is_broken, status_code = test_url(link)
if is_broken:
broken_links.append(link)
cprint(f'{status_code}\t{link}', 'red')
print("FILES:", link_to_files[link])
cprint(f'\t{status_code}\t{link}', 'red')
else:
if args.verbose:
cprint(f'{status_code}\t{link}', 'green')
print("FILES:", link_to_files[link])
cprint(f'\t{status_code}\t{link}', 'green')

# Return code > 0 to return error.
num_broken = len(broken_links)
Expand Down

0 comments on commit b52c91b

Please sign in to comment.