aboutsummaryrefslogtreecommitdiffstats
path: root/import_issues.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-06-02 21:56:46 +0200
committerBryan Gardiner <bog@khumba.net>2024-07-19 20:30:21 -0700
commit08aa8dc51b39d14c1bfbed244e42f91d95b85fbb (patch)
treeb740c1007c84767789db5610c2756de5fedd38a9 /import_issues.py
parentd75a1d7341e07a0bf4e1ba5fbf11b751c8f96bbf (diff)
downloadlazygl2srht-08aa8dc51b39d14c1bfbed244e42f91d95b85fbb.tar.gz
refactor: split open_ticket() into two subfunctions per modes.
Diffstat (limited to 'import_issues.py')
-rwxr-xr-ximport_issues.py138
1 files changed, 117 insertions, 21 deletions
diff --git a/import_issues.py b/import_issues.py
index eee6ce6..6086f9b 100755
--- a/import_issues.py
+++ b/import_issues.py
@@ -127,13 +127,13 @@ import json
import logging
import os
import re
-import subprocess
import smtplib
+import subprocess
import sys
import time
+from datetime import datetime, timezone
from email.message import EmailMessage
from email.utils import format_datetime, make_msgid
-from datetime import datetime, timezone
from pathlib import Path
from typing import Dict, List, Optional
@@ -267,7 +267,7 @@ def do_mail(
def run_hut(cmds, tracker, msg, args=None, delay=None):
log.debug(
- f"run_hut: cmds = {cmds}, tracker = {tracker}, args = {args}\n\nmsg:\n{msg}"
+ "cmds = %s, tracker = %s, args = %s\n\nmsg:\n%s", cmds, tracker, args, msg
)
if args is None:
args = []
@@ -294,8 +294,55 @@ def run_hut(cmds, tracker, msg, args=None, delay=None):
return res
-def open_ticket(
- *,
+def open_ticket_by_hut(
+ delay: float,
+ tracker: str,
+ frm: str,
+ title: str,
+ body: str,
+ created_by: Optional[str],
+ created_at: str,
+ closed_at: Optional[str],
+ is_closed: bool,
+ is_confidential: bool,
+ labels: List[Dict[str, Any]],
+ milestone_name: Optional[str],
+ gitlab_ticket_url: str,
+) -> str:
+
+ lines = []
+ pheaders = []
+
+ pheaders.append(f"Migrated from: {gitlab_ticket_url}")
+
+ if created_by:
+ pheaders.append(f"Created by: {created_by}")
+ pheaders.append(f"Created at: {created_at}")
+
+ if closed_at is not None:
+ pheaders.append(f"Closed at: {closed_at}")
+ elif is_closed:
+ pheaders.append("State: closed")
+
+ if milestone_name:
+ pheaders.append(f"Milestone: {milestone_name}")
+
+ if is_confidential:
+ pheaders.append("Confidential: true")
+
+ lines.append(" \\\n".join(pheaders))
+ lines.append("")
+ lines.append(body)
+
+ msg = title
+ if len(lines):
+ msg += "\n" + "\n".join(lines)
+ out = run_hut(["ticket", "create"], tracker, msg, delay=delay)
+
+ return out
+
+
+def open_ticket_by_email(
smtp,
delay: float,
mode: str,
@@ -311,9 +358,7 @@ def open_ticket(
label_names: List[str],
milestone_name: Optional[str],
gitlab_ticket_url: str,
-) -> int:
- global issue_count
-
+):
lines = []
pheaders = []
@@ -341,21 +386,71 @@ def open_ticket(
lines.append("")
lines.append(body)
- if mode in ["send", "print"]:
- do_mail(
- smtp=smtp,
- delay=delay,
- mode=mode,
- frm=frm,
- to=f"{tracker}@todo.sr.ht",
- subject=title,
- body="\n".join(lines),
+ do_mail(
+ smtp=smtp,
+ delay=delay,
+ mode=mode,
+ frm=frm,
+ to=f"{tracker}@todo.sr.ht",
+ subject=title,
+ body="\n".join(lines),
+ )
+
+
+def open_ticket(
+ *,
+ smtp,
+ delay: float,
+ mode: str,
+ tracker: str,
+ frm: str,
+ title: str,
+ body: str,
+ created_by: Optional[str],
+ created_at: str,
+ closed_at: Optional[str],
+ is_closed: bool,
+ is_confidential: bool,
+ labels: List[Dict[str, Any]],
+ milestone_name: Optional[str],
+ gitlab_ticket_url: str,
+) -> int:
+ global issue_count
+
+ if mode in ("send", "print"):
+ open_ticket_by_email(
+ smtp,
+ delay,
+ mode,
+ tracker,
+ frm,
+ title,
+ body,
+ created_by,
+ created_at,
+ closed_at,
+ is_closed,
+ is_confidential,
+ labels,
+ milestone_name,
+ gitlab_ticket_url,
)
elif mode == "hut":
- msg = title
- if len(lines):
- msg += "\n" + "\n".join(lines)
- run_hut(["ticket", "create"], tracker, msg, delay=delay)
+ open_ticket_by_hut(
+ delay,
+ tracker,
+ frm,
+ title,
+ body,
+ created_by,
+ created_at,
+ closed_at,
+ is_closed,
+ is_confidential,
+ labels,
+ milestone_name,
+ gitlab_ticket_url,
+ )
issue_count += 1
return issue_count
@@ -448,6 +543,7 @@ def send_comment(
mode=mode,
frm=frm,
to=f"{tracker}/{issue_id}@todo.sr.ht",
+ body=body,
)
elif mode == "hut":
run_hut(["ticket", "comment"], tracker, body, [str(issue_id)], delay=delay)