diff options
-rwxr-xr-x | import_issues.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/import_issues.py b/import_issues.py index a9a289d..c1dbc21 100755 --- a/import_issues.py +++ b/import_issues.py @@ -128,6 +128,7 @@ import json import os import re import smtplib +import sys import time from email.message import EmailMessage from email.utils import format_datetime, make_msgid @@ -141,6 +142,7 @@ ID_RE = re.compile(r"^[0-9]+$") logging.basicConfig( format="%(levelname)s:%(funcName)s:%(message)s", level=logging.DEBUG, + stream=sys.stdout, ) log = logging.getLogger() @@ -181,20 +183,30 @@ def do_mail( ): global email_count email_count += 1 - log.info(f"---- #{email_count}") + + if mode == "print": + verb = "Printing" + elif mode == "send": + verb = "Sending" + else: + raise ValueError(f"Unhandled mode {mode!r}.") + + log.info(f"{verb} email #{email_count}.") date = format_datetime(datetime.now(timezone.utc)) msg_id = make_msgid() + indent = " " if mode == "print": - print(f"From: {frm}") - print(f"To: {to}") - print(f"Date: {date}") + print(f"{indent}From: {frm}") + print(f"{indent}To: {to}") + print(f"{indent}Date: {date}") if subject: - print(f"Subject: {subject}") - print(f"Message-ID: {msg_id}") + print(f"{indent}Subject: {subject}") + print(f"{indent}Message-ID: {msg_id}") + print() + print(indent + re.sub("\n", f"\n{indent}", body)) print() - print(body) elif mode == "send": msg = EmailMessage() @@ -499,7 +511,7 @@ def run( for issue_json in issue_jsons: issue_json["notes"].sort(key=lambda x: x["created_at"]) - log.info("-------- CREATING TICKETS") + log.info("Creating tickets.") issue_id_map: Dict[int, int] = {} @@ -570,7 +582,7 @@ def run( issue_id_map[gitlab_issue_id] = srht_issue_id - log.info("-------- CREATING COMMENTS") + log.info("Creating comments.") for issue_json in issue_jsons: for note_json in issue_json["notes"]: @@ -626,7 +638,7 @@ def run( is_confidential=(note_json["confidential"] is True), ) - log.info("-------- CLOSING CLOSED ISSUES") + log.info("Closing closed issues.") for issue_json in issue_jsons: if issue_json["state"] == "closed": |