|
25 | 25 | import re |
26 | 26 | import cfdoc_qa as qa |
27 | 27 |
|
| 28 | +JIRA_BASE_URL = "https://northerntech.atlassian.net/browse/" |
| 29 | +# Pattern to match Jira ticket references (ENT-1234, CFE-4567, etc.) |
| 30 | +# (?<!/) skips tickets in URLs (/) |
| 31 | +# (?<!\[) and (?!\]) skips inside link text ([]) |
| 32 | +JIRA_TICKET_PATTERN = re.compile(r"(?<!/)(?<!\[)(ENT|CFE)-(\d+)\b(?!\])") |
| 33 | + |
28 | 34 |
|
29 | 35 | def run(config): |
30 | 36 | markdown_files = config["markdown_files"] |
@@ -115,6 +121,13 @@ def headerToAnchor(header): |
115 | 121 | return anchor |
116 | 122 |
|
117 | 123 |
|
| 124 | +def convertJiraTicketsToLinks(line): |
| 125 | + """Convert Jira ticket references (ENT-1234, CFE-4567) to markdown links.""" |
| 126 | + return JIRA_TICKET_PATTERN.sub( |
| 127 | + lambda m: "[%s](%s%s)" % (m[0], JIRA_BASE_URL, m[0]), line |
| 128 | + ) |
| 129 | + |
| 130 | + |
118 | 131 | def parseMarkdownForAnchors(file_name, config): |
119 | 132 | in_file = open(file_name, "r") |
120 | 133 | lines = in_file.readlines() |
@@ -305,6 +318,14 @@ def applyLinkMap(file_name, config): |
305 | 318 | else: |
306 | 319 | break |
307 | 320 | new_line += markdown_line |
| 321 | + |
| 322 | + # Convert Jira ticket references to links (only outside code blocks) |
| 323 | + if not in_pre: |
| 324 | + original_line = new_line |
| 325 | + new_line = convertJiraTicketsToLinks(new_line) |
| 326 | + if new_line != original_line: |
| 327 | + write_changes = True |
| 328 | + |
308 | 329 | new_lines.append(new_line) |
309 | 330 | previous_empty = markdown_line.lstrip() == "" |
310 | 331 |
|
|
0 commit comments