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/18 05:02:04 UTC

[lucene-jira-archive] branch improve-cross-link created (now 7c2e494e)

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

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


      at 7c2e494e selectively create cross-link issue

This branch includes the following new commits:

     new 7c2e494e selectively create cross-link issue

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: selectively create cross-link issue

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

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

commit 7c2e494e4437496281568a8d2338a1a89b0f1c5d
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Mon Jul 18 14:01:56 2022 +0900

    selectively create cross-link issue
---
 migration/src/jira_util.py          | 45 +++++++++++++----
 migration/src/update_issue_links.py | 96 -------------------------------------
 2 files changed, 37 insertions(+), 104 deletions(-)

diff --git a/migration/src/jira_util.py b/migration/src/jira_util.py
index f5cae1f2..850b440e 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -234,12 +234,41 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: d
 def embed_gh_issue_link(text: str, issue_id_map: dict[str, str]) -> str:
     """Embed GitHub issue number
     """
-    jira_keys = [m[1:] for m in re.findall(REGEX_JIRA_KEY, text)]
-    if jira_keys:
-        jira_keys = set(jira_keys)
-        for key in jira_keys:
-            gh_number = issue_id_map.get(key)
-            if gh_number:
-                new_key = f"{key} (#{gh_number})"
-                text = text.replace(key, new_key)
+    def repl_simple(m: re.Match):
+        res = m.group(0)
+        gh_number = issue_id_map.get(m.group(2))
+        if gh_number:
+            res = f"{m.group(1)}#{gh_number}{m.group(3)}"
+            # print(res)
+        return res
+    
+    def repl_paren(m: re.Match):
+        res = m.group(0)
+        gh_number = issue_id_map.get(m.group(2))
+        if gh_number:
+            res = f"{m.group(1)}#{gh_number}{m.group(3)}"
+            # print(res)
+        return res
+
+    def repl_bracket(m: re.Match):
+        res = m.group(0)
+        gh_number = issue_id_map.get(m.group(2))
+        if gh_number:
+            res = f"#{gh_number}"
+            # print(res)
+        return res
+    
+    def repl_md_link(m: re.Match):
+        res = m.group(0)
+        gh_number = issue_id_map.get(m.group(1))
+        if gh_number:
+            res = f"{m.group(0)} (#{gh_number})"
+            print(res)
+        return res
+
+    text = re.sub(r"(\s)(LUCENE-\d+)([\s,\?\!\.])", repl_simple, text)
+    text = re.sub(r"(\()(LUCENE-\d+)(\))", repl_paren, text)
+    text = re.sub(r"(\[)(LUCENE-\d+)(\])(?!\()", repl_bracket, text)
+    text = re.sub(r"\[(LUCENE-\d+)\]\(https?[^\)]+LUCENE-\d+\)", repl_md_link, text)
+
     return text
diff --git a/migration/src/update_issue_links.py b/migration/src/update_issue_links.py
deleted file mode 100644
index 3309f7dc..00000000
--- a/migration/src/update_issue_links.py
+++ /dev/null
@@ -1,96 +0,0 @@
-#
-# Deprecated.
-#
-# Update GitHub issues/comments to map Jira key to GitHub issue number
-# Usage:
-#   python src/update_issue_links.py --issues <issue number list>
-#   python src/update_issue_links.py
-#
-
-import argparse
-from pathlib import Path
-import sys
-import os
-
-from common import LOG_DIRNAME, MAPPINGS_DATA_DIRNAME, ISSUE_MAPPING_FILENAME, MaxRetryLimitExceedException, logging_setup, read_issue_id_map, retry_upto
-from github_issues_util import *
-from jira_util import embed_gh_issue_link
-
-
-log_dir = Path(__file__).resolve().parent.parent.joinpath(LOG_DIRNAME)
-logger = logging_setup(log_dir, "update_issue_links")
-
-
-@retry_upto(3, 1.0, logger)
-def update_issue_link_in_issue_body(issue_number: int, issue_id_map: dict[str, str], token: str, repo: str):
-    body = get_issue_body(token, repo, issue_number, logger)
-    if body:
-        updated_body = embed_gh_issue_link(body, issue_id_map)
-        if updated_body == body:
-            logger.debug(f"Issue {issue_number} does not contain any cross-issue links; nothing to do.")
-            return
-        if update_issue_body(token, repo, issue_number, updated_body, logger):
-            logger.debug(f"Issue {issue_number} was successfully updated.")
-            
-
-
-@retry_upto(3, 1.0, logger)
-def update_issue_link_in_comments(issue_number: int, issue_id_map: dict[str, str], token: str, repo: str):
-    comments = get_issue_comments(token, repo, issue_number, logger)
-    if not comments:
-        return
-    logger.debug(f"# comments in issue {issue_number} = {len(comments)}")
-    for comment in comments:
-        id = comment.id
-        body = comment.body
-        updated_body = embed_gh_issue_link(body, issue_id_map)
-        if updated_body == body:
-            logger.debug(f"Comment {id} does not contain any cross-issue links; nothing to do.")
-            continue
-        if update_comment_body(token, repo, id, updated_body, logger):
-            logger.debug(f"Comment {id} was successfully updated.")
-
-
-if __name__ == "__main__":
-    github_token = os.getenv("GITHUB_PAT")
-    if not github_token:
-        print("Please set your GitHub token to GITHUB_PAT environment variable.")
-        sys.exit(1)
-    github_repo = os.getenv("GITHUB_REPO")
-    if not github_repo:
-        print("Please set GitHub repo location to GITHUB_REPO environment varialbe.")
-        sys.exit(1)
-
-    check_authentication(github_token)
-
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--issues', type=int, required=False, nargs='*', help='Jira issue number list to be downloaded')
-    args = parser.parse_args()
-    
-    mapping_data_dir = Path(__file__).resolve().parent.parent.joinpath(MAPPINGS_DATA_DIRNAME)
-    issue_mapping_file = mapping_data_dir.joinpath(ISSUE_MAPPING_FILENAME)
-    if not issue_mapping_file.exists():
-        logger.error(f"Jira-GitHub issue id mapping file not found. {issue_mapping_file}")
-        sys.exit(1)
-    issue_id_map = read_issue_id_map(issue_mapping_file)
-    
-    issues = []
-    if args.issues:
-        issues = args.issues
-    else:
-        issues = list(issue_id_map.values())
-    
-    logger.info(f"Updating GitHub issues")
-    for num in issues:
-        try:
-            update_issue_link_in_issue_body(num, issue_id_map, github_token, github_repo)
-        except MaxRetryLimitExceedException:
-            logger.error(f"Failed to update issue body. Skipped issue {num}")
-            continue
-        try:
-            update_issue_link_in_comments(num, issue_id_map, github_token, github_repo)
-        except MaxRetryLimitExceedException:
-            logger.error(f"Failed to update issue comments. Skipped issue {num}")
-            continue
-
-    logger.info("Done.")
\ No newline at end of file