diff --git a/repobee_feedback/feedback.py b/repobee_feedback/feedback.py index 6014698..f4ceb59 100644 --- a/repobee_feedback/feedback.py +++ b/repobee_feedback/feedback.py @@ -11,6 +11,7 @@ import re import sys import argparse +from textwrap import indent from typing import Iterable, Tuple, List, Mapping import repobee_plug as plug @@ -18,6 +19,8 @@ PLUGIN_NAME = "feedback" BEGIN_ISSUE_PATTERN = r"#ISSUE#(.*?)#(.*)" +INDENTATION_STR = " " +TRUNC_SIGN = "[...]" def callback(args: argparse.Namespace, api: plug.PlatformAPI) -> None: @@ -108,20 +111,20 @@ def command(self, api: plug.PlatformAPI): callback(self.args, api) +def _indent_issue_body(body: str, trunc_len: int): + indented_body = indent(body[:trunc_len], INDENTATION_STR) + body_end = TRUNC_SIGN if len(body) > trunc_len else "" + return indented_body + body_end + + def _ask_for_open(issue: plug.Issue, repo_name: str, trunc_len: int) -> bool: - plug.echo( - 'Processing issue "{}" for {}: {}{}'.format( - issue.title, - repo_name, - issue.body[:trunc_len], - "[...]" if len(issue.body) > trunc_len else "", - ) + indented_body = _indent_issue_body(issue.body, trunc_len) + issue_description = ( + f'\nProcessing issue "{issue.title}" for {repo_name}:\n{indented_body}' ) + plug.echo(issue_description) return ( - input( - 'Open issue "{}" in repo {}? (y/n) '.format(issue.title, repo_name) - ) - == "y" + input(f'Open issue "{issue.title}" in repo {repo_name}? (y/n) ') == "y" ) diff --git a/tests/test_feedback.py b/tests/test_feedback.py index 790e602..67667d4 100644 --- a/tests/test_feedback.py +++ b/tests/test_feedback.py @@ -223,3 +223,26 @@ def test_skips_unexpected_issues_in_multi_issues_file( feedback.callback(args=args, api=api_mock) api_mock.create_issue.assert_has_calls(expected_calls, any_order=True) + + +class TestIndentIssueBody: + """Tests for the method that addds indentation to the issue body""" + + def test_issue_indented_and_truncated( + self, + ): + """Test that a long issue body get truncated to a certain length""" + body = "Hello world\nfrom python\n" + indented_body = feedback._indent_issue_body( + body, trunc_len=len(body) // 2 + ) + assert indented_body.startswith(f"{feedback.INDENTATION_STR}Hello") + assert indented_body.endswith(feedback.TRUNC_SIGN) + + def test_issue_indented_and_not_truncated( + self, + ): + """Test that a short issue body does not get truncated""" + body = "This is an issue\n" + indented_body = feedback._indent_issue_body(body, 2 * len(body)) + assert indented_body == f"{feedback.INDENTATION_STR}{body}"