aboutsummaryrefslogtreecommitdiffstats
path: root/import_issues.py
diff options
context:
space:
mode:
Diffstat (limited to 'import_issues.py')
-rwxr-xr-ximport_issues.py57
1 files changed, 44 insertions, 13 deletions
diff --git a/import_issues.py b/import_issues.py
index c9ffffd..42b0a1f 100755
--- a/import_issues.py
+++ b/import_issues.py
@@ -136,6 +136,7 @@ from email.message import EmailMessage
from email.utils import format_datetime, make_msgid
from pathlib import Path
from typing import Any, Optional
+from urllib.parse import urlparse
logging.basicConfig(
format="%(levelname)s:%(funcName)s:%(message)s",
@@ -369,6 +370,9 @@ def open_ticket_by_email(
lines.append("")
lines.append(body)
+ body_split = split_long_str("\n".join(lines))
+
+ # First create the ticket
do_mail(
smtp=smtp,
delay=delay,
@@ -376,9 +380,24 @@ def open_ticket_by_email(
frm=frm,
to=f"{tracker}@todo.sr.ht",
subject=title,
- body="\n".join(lines),
+ body=body_split[0],
)
+ # then add remaining parts of the description as comments
+ if len(body_split) > 1:
+ url_split = urlparse(gitlab_ticket_url)
+ issue_id = int(os.path.basename(url_split.path))
+
+ for part in body_split[1:]:
+ do_mail(
+ smtp=smtp,
+ delay=delay,
+ mode=mode,
+ frm=frm,
+ to=f"{tracker}/{issue_id}@todo.sr.ht",
+ body=part,
+ )
+
def open_ticket_by_hut(
delay: float,
@@ -423,7 +442,9 @@ def open_ticket_by_hut(
msg = title
if len(lines):
msg += "\n" + "\n".join(lines)
- out = run_hut(["ticket", "create"], tracker, msg, delay=delay)
+ msg_split = split_long_str(msg)
+
+ out = run_hut(["ticket", "create"], tracker, msg_split[0], delay=delay)
out.issue_id = int(out.stderr.strip()[len("Created new ticket #") :])
for label in sorted(labels, key=lambda x: x["label"]["title"]):
@@ -451,6 +472,13 @@ def open_ticket_by_hut(
delay=delay,
)
+ # then add remaining parts of the description as comments
+ if len(msg_split) > 1:
+ for part in msg_split[1:]:
+ run_hut(
+ ["ticket", "comment"], tracker, part, [str(out.issue_id)], delay=delay
+ )
+
return out
@@ -593,17 +621,20 @@ def send_comment(
body = "\n".join(lines)
- if mode in ["send", "print"]:
- do_mail(
- smtp=smtp,
- delay=delay,
- 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)
+ body_split = split_long_str(body)
+
+ for part in body_split:
+ if mode in ["send", "print"]:
+ do_mail(
+ smtp=smtp,
+ delay=delay,
+ mode=mode,
+ frm=frm,
+ to=f"{tracker}/{issue_id}@todo.sr.ht",
+ body=part,
+ )
+ elif mode == "hut":
+ run_hut(["ticket", "comment"], tracker, part, [str(issue_id)], delay=delay)
def close_ticket(