Skip to content

Commit 3cacf06

Browse files
committed
fix: honor stored sourceUrl for mirror clone and permalinks (CM-1318)
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent d324ea1 commit 3cacf06

4 files changed

Lines changed: 9 additions & 12 deletions

File tree

services/apps/mailing_list_integration/src/crowdmail/services/mirror/mirror_service.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from crowdmail.services.parse.noteren import get_email_from_git, git_run_command
2121
from crowdmail.settings import LORE_MIRROR_DIR
2222

23-
LORE_BASE_URL = "https://lore.kernel.org/"
24-
2523
RETRYABLE_MIRROR_ERRORS = (NetworkError, RateLimitError, RemoteServerError)
2624

2725
retry_on_mirror_error = retry(
@@ -103,15 +101,14 @@ def list_mirror_dir(list_name: str, mirror_dir: str = LORE_MIRROR_DIR) -> str:
103101

104102

105103
@retry_on_mirror_error
106-
async def ensure_mirror(list_name: str, mirror_dir: str = LORE_MIRROR_DIR) -> str:
104+
async def ensure_mirror(list_name: str, source_url: str, mirror_dir: str = LORE_MIRROR_DIR) -> str:
107105
"""Clone the list mirror if it's absent, otherwise fetch new commits. Returns the list dir."""
108106
list_dir = list_mirror_dir(list_name, mirror_dir)
109107
if not os.path.isdir(list_dir):
110-
logger.info(f"Cloning lore list '{list_name}' into {list_dir}")
108+
clone_url = source_url.rstrip("/") + "/"
109+
logger.info(f"Cloning lore list '{list_name}' from {clone_url} into {list_dir}")
111110
os.makedirs(os.path.dirname(list_dir), exist_ok=True)
112-
await _run_shell_command(
113-
["public-inbox-clone", "-q", f"{LORE_BASE_URL}{list_name}/", list_dir]
114-
)
111+
await _run_shell_command(["public-inbox-clone", "-q", clone_url, list_dir])
115112
# public-inbox-clone drops a manifest scoped to clone time; remove it
116113
# and re-fetch from inside list_dir so the manifest is regenerated
117114
# correctly there (needed to detect new epoch shards, e.g. git/1.git,

services/apps/mailing_list_integration/src/crowdmail/services/parse/noteren.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def parse_email(
355355
"channel": channel,
356356
"title": subject,
357357
"body": json_body,
358-
"url": "https://lore.kernel.org/r/" + msgid,
358+
"url": source.rstrip("/") + "/r/" + msgid,
359359
"isContribution": True,
360360
"type": ActivityType.MESSAGE,
361361
"attributes": attributes,

services/apps/mailing_list_integration/src/crowdmail/worker/list_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def _process_single_list(self, mailing_list: MailingList):
8181
state = ListState.FAILED
8282

8383
try:
84-
list_dir = await ensure_mirror(mailing_list.name)
84+
list_dir = await ensure_mirror(mailing_list.name, mailing_list.source_url)
8585
heads = dict(mailing_list.last_processed_heads)
8686
activities_db = []
8787
activities_kafka = []

services/apps/mailing_list_integration/src/test/test_noteren.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,14 +852,14 @@ def test_parse_email_url_contains_message_id():
852852
b"body\n"
853853
)
854854
parsed = _parse_email(raw, "src", "chan", "c1", "b1")
855-
assert parsed["activityData"]["url"] == "https://lore.kernel.org/r/unique-id@example.com"
855+
assert parsed["activityData"]["url"] == "src/r/unique-id@example.com"
856856

857857

858858
def test_parse_email_url_with_no_message_id():
859-
"""When Message-ID is absent the url must end with a trailing slash and empty id."""
859+
"""When Message-ID is absent the url must end with a slash under the source's /r/ path."""
860860
raw = b"From: A <a@example.com>\nSubject: s\nDate: Mon, 1 Jan 2024 12:00:00 +0000\n\nbody\n"
861861
parsed = _parse_email(raw, "src", "chan", "c1", "b1")
862-
assert parsed["activityData"]["url"] == "https://lore.kernel.org/r/"
862+
assert parsed["activityData"]["url"] == "src/r/"
863863

864864

865865
def test_parse_email_result_structure():

0 commit comments

Comments
 (0)