Skip to content

Commit 563257b

Browse files
committed
[feat] Add --truncation-length option and default to showing whole issue body, fix #6
1 parent f43c7e1 commit 563257b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

repobee_feedback/feedback.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525

2626
def callback(args: argparse.Namespace, api: plug.API) -> None:
27-
repo_names = plug.generate_repo_names(
28-
args.students, args.master_repo_names
29-
)
27+
repo_names = plug.generate_repo_names(args.students, args.master_repo_names)
3028
if "multi_issues_file" in args and args.multi_issues_file is not None:
3129
issues_file = pathlib.Path(args.multi_issues_file).resolve()
3230
issues = _parse_multi_issues_file(issues_file)
@@ -35,7 +33,9 @@ def callback(args: argparse.Namespace, api: plug.API) -> None:
3533
issues = _collect_issues(repo_names, issues_dir)
3634
_raise_on_missing_issue_file(issues, repo_names)
3735
for repo_name, issue in issues:
38-
open_issue = args.batch_mode or _ask_for_open(issue, repo_name)
36+
open_issue = args.batch_mode or _ask_for_open(
37+
issue, repo_name, args.truncation_length
38+
)
3939
if open_issue:
4040
api.open_issue(issue.title, issue.body, [repo_name])
4141
else:
@@ -51,6 +51,18 @@ def create_extension_command(self):
5151
help="Run without any yes/no promts.",
5252
action="store_true",
5353
)
54+
parser.add_argument(
55+
"--tl",
56+
"--truncation-length",
57+
help=(
58+
"In interactive mode, truncates the body of an issue at this "
59+
"many characters. If not specified, issue bodies are shown in "
60+
"full."
61+
),
62+
dest="truncation_length",
63+
type=int,
64+
default=sys.maxsize,
65+
)
5466
issues_grp = parser.add_mutually_exclusive_group(required=True)
5567
issues_grp.add_argument(
5668
"--id",
@@ -99,8 +111,7 @@ def create_extension_command(self):
99111
)
100112

101113

102-
def _ask_for_open(issue: plug.Issue, repo_name: str) -> bool:
103-
trunc_len = 50
114+
def _ask_for_open(issue: plug.Issue, repo_name: str, trunc_len: int) -> bool:
104115
LOGGER.info(
105116
'Processing issue "{}" for {}: {}{}'.format(
106117
issue.title,
@@ -110,9 +121,7 @@ def _ask_for_open(issue: plug.Issue, repo_name: str) -> bool:
110121
)
111122
)
112123
return (
113-
input(
114-
'Open issue "{}" in repo {}? (y/n) '.format(issue.title, repo_name)
115-
)
124+
input('Open issue "{}" in repo {}? (y/n) '.format(issue.title, repo_name))
116125
== "y"
117126
)
118127

@@ -145,15 +154,11 @@ def _read_issue(issue_path: pathlib.Path) -> plug.Issue:
145154
def _parse_multi_issues_file(
146155
issues_file: pathlib.Path
147156
) -> Iterable[Tuple[str, plug.Issue]]:
148-
with open(
149-
str(issues_file), mode="r", encoding=sys.getdefaultencoding()
150-
) as file:
157+
with open(str(issues_file), mode="r", encoding=sys.getdefaultencoding()) as file:
151158
lines = list(file.readlines())
152159

153160
if not lines or not re.match(BEGIN_ISSUE_PATTERN, lines[0], re.IGNORECASE):
154-
raise plug.PlugError(
155-
"first line of multi issues file not #ISSUE# line"
156-
)
161+
raise plug.PlugError("first line of multi issues file not #ISSUE# line")
157162

158163
issue_blocks = _extract_issue_blocks(lines)
159164
return list(_extract_issues(issue_blocks, lines))

tests/test_feedback.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def parsed_args_issues_dir(tmp_path):
6060
batch_mode=True,
6161
issues_dir=str(tmp_path),
6262
multi_issues_file=None,
63+
truncation_length=50,
6364
)
6465

6566

@@ -72,6 +73,7 @@ def parsed_args_multi_issues_file(with_multi_issues_file):
7273
batch_mode=True,
7374
issues_dir=None,
7475
multi_issues_file=str(issues_file),
76+
truncation_length=50,
7577
)
7678

7779

0 commit comments

Comments
 (0)