You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2022/07/31 03:14:39 UTC
[lucene-jira-archive] 01/01: escape github style issue links
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a commit to branch escape-github-style-issue-link-in-jira
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git
commit 107a49d331473f0da17c8cc79d19a4e294ee93aa
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Sun Jul 31 12:14:29 2022 +0900
escape github style issue links
---
migration/src/jira_util.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/migration/src/jira_util.py b/migration/src/jira_util.py
index c25c8ea1..5f3f9ce6 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -231,6 +231,7 @@ REGEX_JIRA_KEY = re.compile(r"[^/]LUCENE-\d+")
REGEX_MENTION_ATMARK = re.compile(r"(^@[\w\.]+)|((?<=[\s\(\"'])@[\w\.]+)(?=[\s\)\"'\?!,\.$])") # this regex may capture only "@" + "<username>" mentions
REGEX_MENION_TILDE = re.compile(r"(^\[~[\w\.]+\])|((?<=[\s\(\"'])\[~[\w\.]+\])(?=[\s\)\"'\?!,\.$])") # this regex may capture only "[~" + "<username>" + "]" mentions
REGEX_LINK = re.compile(r"\[([^\]]+)\]\(([^\)]+)\)")
+REGEX_GITHUB_ISSUE_LINK = re.compile(r"(\s)(#\d+)(\s)")
def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: dict[str, str] = {}, jira_users: dict[str, str] = {}) -> str:
@@ -243,6 +244,11 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: d
res = f"[{m.group(1)}]({repl})"
return res
+ def escape_gh_issue_link(m: re.Match):
+ # escape #NN by backticks to prevent creating an unintentional issue link
+ res = f"{m.group(1)}`{m.group(2)}`{m.group(3)}"
+ return res
+
text = re.sub(REGEX_CRLF, "\n", text) # jira2markup does not support carriage return (?)
# convert Jira special emojis into corresponding or similar Unicode characters
@@ -284,8 +290,12 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: d
mention = lambda: f"@{gh_m}" if gh_m else disp_name if disp_name else f"`~{jira_id}`"
text = text.replace(m, mention())
+ # convert links to attachments
text = re.sub(REGEX_LINK, repl_att, text)
+ # escape github style cross-issue link (#NN)
+ text = re.sub(REGEX_GITHUB_ISSUE_LINK, escape_gh_issue_link, text)
+
return text