|
5 | 5 |
|
6 | 6 | import argparse |
7 | 7 | import configparser |
| 8 | +import email |
8 | 9 | import os |
9 | 10 | import re |
10 | 11 | import subprocess |
|
13 | 14 | import textwrap |
14 | 15 | from pathlib import Path |
15 | 16 | from typing import Dict, List, Optional, Tuple |
| 17 | +from urllib.parse import urlparse |
16 | 18 | import requests |
17 | 19 |
|
18 | 20 |
|
@@ -99,6 +101,36 @@ def get_patchwork_patch(self, patch_id: int) -> Dict: |
99 | 101 | return response.json() |
100 | 102 |
|
101 | 103 |
|
| 104 | +def fetch_original_subject(session: requests.Session, |
| 105 | + archive_url: str) -> Optional[str]: |
| 106 | + """Fetch the original Subject from the email archive. |
| 107 | +
|
| 108 | + Patchwork mangles subjects (strips PATCH prefix, reformats tags), |
| 109 | + so we fetch the raw email from the archive to get the real Subject. |
| 110 | + """ |
| 111 | + if not archive_url: |
| 112 | + return None |
| 113 | + |
| 114 | + # lore.kernel.org serves raw email when /raw is appended |
| 115 | + parsed = urlparse(archive_url) |
| 116 | + if parsed.hostname == 'lore.kernel.org': |
| 117 | + raw_url = archive_url.rstrip('/') + '/raw' |
| 118 | + else: |
| 119 | + raw_url = archive_url |
| 120 | + |
| 121 | + try: |
| 122 | + response = session.get(raw_url, timeout=30) |
| 123 | + response.raise_for_status() |
| 124 | + except requests.exceptions.RequestException: |
| 125 | + return None |
| 126 | + |
| 127 | + msg = email.message_from_string(response.text) |
| 128 | + subject = msg.get('Subject') |
| 129 | + if subject: |
| 130 | + return subject |
| 131 | + return None |
| 132 | + |
| 133 | + |
102 | 134 | def extract_commit_subject(review_text: str) -> str: |
103 | 135 | """Extract the commit subject from review text""" |
104 | 136 | # Look for "commit <hash>\nAuthor: ...\n\n <subject>" |
@@ -613,6 +645,12 @@ def main(): |
613 | 645 | patch_info = patch_info_list[i] |
614 | 646 | message_id = patch_info.get('msgid', '') |
615 | 647 |
|
| 648 | + # Fetch original subject from archive to avoid Patchwork mangling |
| 649 | + archive_url = patch_info.get('list_archive_url') |
| 650 | + original_subject = fetch_original_subject(client.session, archive_url) |
| 651 | + if original_subject: |
| 652 | + patch_info['name'] = original_subject |
| 653 | + |
616 | 654 | # Skip empty reviews (None or empty string) |
617 | 655 | if review_text is None or review_text.strip() == '': |
618 | 656 | if args.verbose: |
|
0 commit comments