diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-06-02 21:56:44 +0200 |
---|---|---|
committer | Bryan Gardiner <bog@khumba.net> | 2024-07-19 20:30:20 -0700 |
commit | 2d0ad6a9012c823eac72a9c92e5b082a18190eeb (patch) | |
tree | 15af2f5957cc96b1879f931d78fcb98aa2703314 /import_issues.py | |
parent | 7835e04a3e878d282fa7274aec8cd992f89b7dab (diff) | |
download | lazygl2srht-2d0ad6a9012c823eac72a9c92e5b082a18190eeb.tar.gz |
feat: have smaller delay between calls to hut than SMTP ones.
Diffstat (limited to 'import_issues.py')
-rwxr-xr-x | import_issues.py | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/import_issues.py b/import_issues.py index fca08a8..1b7c538 100755 --- a/import_issues.py +++ b/import_issues.py @@ -263,16 +263,32 @@ def do_mail( raise RuntimeError(f"Unknown mode: {mode!r}") -def run_hut(cmds, tracker, msg, args=None): +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}" + ) if args is None: args = [] - res = subprocess.run( - ["hut", "todo"] + cmds + ["-t", tracker] + args, - encoding="utf-8", - input=msg, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) + if msg is None: + res = subprocess.run( + ["hut", "todo"] + cmds + ["-t", tracker] + args, + check=True, + encoding="utf-8", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + else: + res = subprocess.run( + ["hut", "todo"] + cmds + ["-t", tracker, "--stdin"] + args, + check=True, + encoding="utf-8", + input=msg, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + time.sleep(delay) + return res @@ -337,7 +353,7 @@ def open_ticket( msg = title if len(lines): msg += "\n" + "\n".join(lines) - run_hut(["ticket", "create", "--stdin"], tracker, msg) + run_hut(["ticket", "create"], tracker, msg, delay=delay) issue_count += 1 return issue_count @@ -366,7 +382,7 @@ def file_missing_ticket( ) elif mode == "hut": msg = f"Missing issue\n\nIssue {issue_id} is not known." - run_hut(["ticket", "create"], tracker, msg, ["--stdin"]) + run_hut(["ticket", "create"], tracker, msg, delay=delay) issue_count += 1 @@ -434,7 +450,7 @@ def send_comment( to=f"{tracker}/{issue_id}@todo.sr.ht", ) elif mode == "hut": - run_hut(["ticket", "comment"], tracker, None, ["--stdin", issue_id]) + run_hut(["ticket", "comment"], tracker, body, [str(issue_id)], delay=delay) def close_ticket( @@ -474,11 +490,14 @@ def close_ticket( ["ticket", "update-status"], tracker, None, - ["--resolution", "fixed", "--status", "closed", issue_id], + [str(issue_id), "--resolution", "fixed", "--status", "resolved"], + delay=delay, ) -def ensure_label(tracker: str, name: str, bg_color: str, fg_color: str = "#FFFFFF"): +def ensure_label( + tracker: str, name: str, bg_color: str, fg_color: str = "#FFFFFF", delay=None +): labels = get_labels(tracker.split("/", 1)[1]) if not ([x for x in labels if x["name"] == name]): run_hut( @@ -486,6 +505,7 @@ def ensure_label(tracker: str, name: str, bg_color: str, fg_color: str = "#FFFFF tracker, None, ["--background", bg_color, "--foreground", fg_color, name], + delay=delay, ) @@ -794,7 +814,7 @@ def main(): parser.add_argument( "--delay", - default=5, + default=None, help="Decimal number of seconds to wait between accessing the server.", ) @@ -903,9 +923,18 @@ def main(): srht_tracker = args["srht_tracker"] tracker = f"~{srht_owner}/{srht_tracker}" - if mode == "print": + delay = args["delay"] + if delay is None: + if mode == "hut": + delay = 0.5 + else: + delay = 5 + else: + delay = float(delay) + + if mode != "send": smtp = None - elif mode == "send": + else: smtp_ssl = args["smtp_ssl"] smtp_starttls = args["smtp_starttls"] smtp_host = args["smtp_host"] or os.environ.get("SMTP_HOST", "localhost") @@ -936,7 +965,7 @@ def main(): run( smtp=smtp, - delay=float(args["delay"]), + delay=delay, mode=mode, tracker=tracker, frm=frm, |