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/09 12:36:38 UTC

[lucene-jira-archive] branch remap-mentions created (now e8c2a881)

This is an automated email from the ASF dual-hosted git repository.

tomoko pushed a change to branch remap-mentions
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git


      at e8c2a881 remap jira name to github account if it is available

This branch includes the following new commits:

     new e8c2a881 remap jira name to github account if it is available

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[lucene-jira-archive] 01/01: remap jira name to github account if it is available

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomoko pushed a commit to branch remap-mentions
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git

commit e8c2a881410a63fb91f1c61ee2a632e781bcd3da
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Sat Jul 9 21:36:29 2022 +0900

    remap jira name to github account if it is available
---
 migration/src/jira2github_import.py |  4 ++--
 migration/src/jira_util.py          | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/migration/src/jira2github_import.py b/migration/src/jira2github_import.py
index 4399f601..c460182a 100644
--- a/migration/src/jira2github_import.py
+++ b/migration/src/jira2github_import.py
@@ -85,7 +85,7 @@ def convert_issue(num: int, dump_dir: Path, output_dir: Path, account_map: dict[
         # 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 @@ Pull Requests:
         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 32378994..3cc916d3 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -184,11 +184,11 @@ JIRA_EMOJI_TO_UNICODE = {
 
 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 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}) -> str:
     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)