From 63d983afcffe6820ea43877e1500b51e93691970 Mon Sep 17 00:00:00 2001 From: David Lord Date: Sat, 11 Jan 2025 16:21:57 -0800 Subject: [PATCH] rewrap body message --- src/modify_repos/models.py | 10 +++++++--- src/modify_repos/wrap.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/modify_repos/wrap.py diff --git a/src/modify_repos/models.py b/src/modify_repos/models.py index a66d193..628582d 100644 --- a/src/modify_repos/models.py +++ b/src/modify_repos/models.py @@ -1,6 +1,7 @@ from __future__ import annotations import dataclasses +import typing as t from contextlib import chdir from functools import cached_property from inspect import isclass @@ -11,6 +12,7 @@ import click from modify_repos.cmd import echo_cmd from modify_repos.cmd import run_cmd +from modify_repos.wrap import wrap @dataclasses.dataclass @@ -91,10 +93,12 @@ class Script: branch: str title: str body: str - target: str = "main" - branch: str - def __init__(self, orgs: list[str], push: bool) -> None: + def __init_subclass__(cls, **kwargs: t.Any) -> None: + super().__init_subclass__(**kwargs) + cls.body = wrap(cls.body, width=72) + + def __init__(self, push: bool) -> None: self.clones_dir: Path = Path("clones") self.push = push diff --git a/src/modify_repos/wrap.py b/src/modify_repos/wrap.py new file mode 100644 index 0000000..bc10ad5 --- /dev/null +++ b/src/modify_repos/wrap.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +import textwrap +from inspect import cleandoc + + +def wrap(text: str, width: int = 80) -> str: + """Wrap a multi-line, multi-paragraph string.""" + return "\n\n".join( + textwrap.fill(p, width=width, tabsize=4, break_long_words=False) + for p in cleandoc(text).split("\n\n") + )