diff --git a/README.md b/README.md index 587701a..a1d6702 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ Example of output for [fail.md](tests/test_md_files/fail.md) ```bash File: tests/test_md_files/fail.md:3 • Link: https://github.com/AlexanderDokuchaev/FAILED • Error: 404: Not Found File: tests/test_md_files/fail.md:4 • Link: https://not_exist_github.githubcom/ • Error: 500: Internal Server Error -File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path does not exists in repository -File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path does not exists in repository -File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Not found fragment -File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path does not exists in repository +File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path not found +File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path not found +File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Fragment not found +File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path not found ❌ Found 6 dead links 🙀 ``` diff --git a/md_dead_link_check/link_checker.py b/md_dead_link_check/link_checker.py index d1cc168..61e0a67 100644 --- a/md_dead_link_check/link_checker.py +++ b/md_dead_link_check/link_checker.py @@ -17,6 +17,11 @@ TIMEOUT_RESPONSE_CODE = 408 +MSG_TIMEOUT = "408: Timeout" +MSG_PATH_NOT_FOUND = "Path not found" +MSG_PATH_NOT_ADDED = "Path not added to repository" +MSG_FRAGMENT_NOT_FOUND = "Fragment not found" + @dataclass class StatusInfo: @@ -65,8 +70,8 @@ async def process_link(link: str, session: ClientSession, config: Config) -> Lin return LinkStatus(link, str(e)) except asyncio.TimeoutError: if TIMEOUT_RESPONSE_CODE in config.catch_response_codes: - return LinkStatus(link, err_msg="408: Timeout") - return LinkStatus(link, warn_msg="408: Timeout") + return LinkStatus(link, err_msg=MSG_TIMEOUT) + return LinkStatus(link, warn_msg=MSG_TIMEOUT) return LinkStatus(link) @@ -121,7 +126,7 @@ def check_path_links( if not split_result.path: if fragment not in md_file_info.fragments: - ret.append(StatusInfo(md_link, "Not found header")) + ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND)) continue else: try: @@ -133,25 +138,25 @@ def check_path_links( abs_path = (md_abs_path.parent / split_result.path).resolve() rel_path = abs_path.relative_to(root_dir) except ValueError: - ret.append(StatusInfo(md_link, "Path is not within git repository")) + ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND)) continue if abs_path.as_posix() != abs_path.resolve().as_posix(): - ret.append(StatusInfo(md_link, "Path is not within git repository")) + ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND)) continue if rel_path.as_posix() in md_data: # Markdowns in repository if fragment and fragment not in md_data[rel_path.as_posix()].fragments: - ret.append(StatusInfo(md_link, "Not found fragment")) + ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND)) continue else: # Not markdown file if not any(f.as_posix().startswith(rel_path.as_posix()) for f in files_in_repo): if rel_path.exists(): - ret.append(StatusInfo(md_link, "File does not added to repository")) + ret.append(StatusInfo(md_link, MSG_PATH_NOT_ADDED)) else: - ret.append(StatusInfo(md_link, "Path does not exists in repository")) + ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND)) continue ret.append(StatusInfo(md_link)) diff --git a/tests/test_link_cheker.py b/tests/test_link_cheker.py index d3bc57b..a52eda0 100644 --- a/tests/test_link_cheker.py +++ b/tests/test_link_cheker.py @@ -56,11 +56,11 @@ def test_fails(): ), StatusInfo( link_info=LinkInfo(link="/test/fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=8), - err_msg="Path does not exists in repository", + err_msg="Path not found", ), StatusInfo( link_info=LinkInfo(link="fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=9), - err_msg="Path does not exists in repository", + err_msg="Path not found", ), StatusInfo( link_info=LinkInfo( @@ -68,7 +68,7 @@ def test_fails(): location=Path("tests/test_md_files/fail.md"), line_num=13, ), - err_msg="Not found fragment", + err_msg="Fragment not found", warn_msg=None, ), StatusInfo( @@ -77,7 +77,7 @@ def test_fails(): location=Path("tests/test_md_files/fail.md"), line_num=15, ), - err_msg="Path does not exists in repository", + err_msg="Path not found", warn_msg=None, ), ] @@ -128,7 +128,7 @@ def test_exclude_links(exclude_links): location=Path("tests/test_md_files/fail.md"), line_num=13, ), - err_msg="Not found fragment", + err_msg="Fragment not found", warn_msg=None, ), StatusInfo( @@ -137,7 +137,7 @@ def test_exclude_links(exclude_links): location=Path("tests/test_md_files/fail.md"), line_num=15, ), - err_msg="Path does not exists in repository", + err_msg="Path not found", warn_msg=None, ), ]