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/11 15:33:32 UTC

[lucene-jira-archive] 01/04: add a script to list all jira user names

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

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

commit 46ebd285efb3e4bda6c8af3e5b65838b35d10377
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Sun Jul 10 23:36:08 2022 +0900

    add a script to list all jira user names
---
 migration/src/common.py          |  3 +++
 migration/src/list_jira_users.py | 49 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/migration/src/common.py b/migration/src/common.py
index e4d4727e..8e924feb 100644
--- a/migration/src/common.py
+++ b/migration/src/common.py
@@ -7,6 +7,7 @@ import os
 import tempfile
 
 LOG_DIRNAME = "log"
+WORK_DIRNAME = "work"
 
 JIRA_DUMP_DIRNAME = "jira-dump"
 JIRA_ATTACHMENTS_DIRPATH = os.getenv("ATTACHMENTS_DL_DIR")
@@ -14,6 +15,8 @@ GITHUB_IMPORT_DATA_DIRNAME = "github-import-data"
 GITHUB_REMAPPED_DATA_DIRNAME = "github-remapped-data"
 MAPPINGS_DATA_DIRNAME = "mappings-data"
 
+JIRA_USERS_FILENAME = "jira-users.csv"
+
 ISSUE_MAPPING_FILENAME = "issue-map.csv"
 ACCOUNT_MAPPING_FILENAME = "account-map.csv"
 
diff --git a/migration/src/list_jira_users.py b/migration/src/list_jira_users.py
new file mode 100644
index 00000000..15826a6a
--- /dev/null
+++ b/migration/src/list_jira_users.py
@@ -0,0 +1,49 @@
+from pathlib import Path
+import json
+from collections import defaultdict
+
+from common import JIRA_DUMP_DIRNAME, WORK_DIRNAME, JIRA_USERS_FILENAME
+from jira_util import *
+
+
+def extract_authors(jira_dump_file: Path) -> set[tuple[str, str]]:
+    assert jira_dump_file.exists()
+    authors = set([])
+    with open(jira_dump_file) as fp:
+        o = json.load(fp)
+        reporter = extract_reporter(o)
+        authors.add(reporter)
+        assignee = extract_assignee(o)
+        authors.add(assignee)
+        comment_authors = set(__extract_comment_authors(o))
+        authors |= comment_authors
+    return authors
+
+
+def __extract_comment_authors(o: dict) -> tuple[str, str]:
+    comments = extract_comments(o)
+    return [(c[0], c[1]) for c in comments]
+
+
+if __name__ == "__main__":
+    dump_dir = Path(__file__).resolve().parent.parent.joinpath(JIRA_DUMP_DIRNAME)
+    work_dir = Path(__file__).resolve().parent.parent.joinpath(WORK_DIRNAME)
+    if not work_dir.exists():
+        work_dir.mkdir()
+    assert work_dir.exists()
+    jira_user_file = work_dir.joinpath(JIRA_USERS_FILENAME)
+
+    counts = defaultdict(int)
+    for child in dump_dir.iterdir():
+        if child.is_file() and child.name.endswith(".json"):
+            authors = extract_authors(child)
+            for author in authors:
+                counts[author] += 1
+    counts = sorted(counts.items(), key=lambda x: x[1], reverse=True)
+
+    with open(jira_user_file, "w") as fp:
+        fp.write("JiraName,DispName\n")
+        for a, _ in counts:
+            if len(a[0]) == 0:
+                continue
+            fp.write(f"{a[0]},{a[1]}\n")
\ No newline at end of file