remap jira name to github account if it is available (#25)
diff --git a/migration/src/jira2github_import.py b/migration/src/jira2github_import.py
index 4399f60..c460182 100644
--- a/migration/src/jira2github_import.py
+++ b/migration/src/jira2github_import.py
@@ -85,7 +85,7 @@
# make pull requests list
pull_requests_list = [f"- {x}\n" for x in pull_requests]
- body = f"""{convert_text(description, att_replace_map)}
+ body = f"""{convert_text(description, att_replace_map, account_map)}
---
### Jira information
@@ -117,7 +117,7 @@
comments_data = []
for (comment_author_name, comment_author_dispname, comment_body, comment_created, comment_updated) in comments:
data = {
- "body": f"""{convert_text(comment_body, att_replace_map)}
+ "body": f"""{convert_text(comment_body, att_replace_map, account_map)}
Author: {comment_author(comment_author_name, comment_author_dispname)}
Created: {comment_created}
diff --git a/migration/src/jira_util.py b/migration/src/jira_util.py
index 3237899..3cc916d 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -184,11 +184,11 @@
REGEX_CRLF = re.compile(r"\r\n")
REGEX_JIRA_KEY = re.compile(r"[^/]LUCENE-\d+")
-REGEX_MENTION = re.compile(r"@\w+")
+REGEX_MENTION = re.compile(r"((?<=^)@\w+|(?<=[\s\(\"'])@\w+)(?=[\s\)\"'\?!,\.$])") # this regex may capture only "@" + "<username>" mentions
REGEX_LINK = re.compile(r"\[([^\]]+)\]\(([^\)]+)\)")
-def convert_text(text: str, att_replace_map: dict[str, str] = {}) -> str:
+def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: dict[str, str] = {}) -> str:
"""Convert Jira markup to Markdown
"""
def repl_att(m: re.Match):
@@ -220,8 +220,10 @@
if mentions:
mentions = set(mentions)
for m in mentions:
- with_backtick = f"`{m}`"
- text = text.replace(m, with_backtick)
+ jira_id = m[1:]
+ gh_m = account_map.get(jira_id)
+ # replace Jira name with GitHub account if it is available, othewise show Jira name with `` to avoid unintentional mentions
+ text = text.replace(m, f"`@{jira_id}`" if not gh_m else f"@{gh_m}")
text = re.sub(REGEX_LINK, repl_att, text)