feat: normalize URLs without scheme to https://

- Add normalize_url() helper function in commands.py
- Automatically prefix URLs without scheme (e.g. github.com → https://github.com)
- Applies to both -link flag and auto-detected URLs
- Add 5 new tests for URL normalization
- Fix existing tests to handle 5-value return from parse_args()

Examples:
  /add Fix bug github.com/user/repo
  → stored as: https://github.com/user/repo
This commit is contained in:
shokollm
2026-04-09 10:10:06 +00:00
parent 4885be0752
commit 2158f71fd0
2 changed files with 46 additions and 15 deletions

View File

@@ -81,6 +81,15 @@ def parse_args(
return True
return False
def normalize_url(url: str) -> str:
"""Normalize URL by adding https:// prefix if missing."""
if not url:
return url
if url.startswith("http://") or url.startswith("https://"):
return url
# Add https:// for URLs without scheme
return f"https://{url}"
def is_time(s: str) -> bool:
if not s or ":" not in s:
return False
@@ -106,7 +115,7 @@ def parse_args(
if arg == "-link":
if i + 1 < len(args) and not args[i + 1].startswith("-"):
link = args[i + 1]
link = normalize_url(args[i + 1])
i += 2
else:
clear_link = True
@@ -129,7 +138,7 @@ def parse_args(
clear_date = True
i += 1
elif not link and is_url(arg):
link = arg
link = normalize_url(arg)
i += 1
elif due_date_ts is None:
due_date_ts = parse_date_with_tz(arg)