Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Indent issue body when working with multi-issue file #24

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions repobee_feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import re
import sys
import argparse
from textwrap import indent
from typing import Iterable, Tuple, List, Mapping

import repobee_plug as plug

PLUGIN_NAME = "feedback"

BEGIN_ISSUE_PATTERN = r"#ISSUE#(.*?)#(.*)"
INDENTATION_STR = " "
TRUNC_SIGN = "[...]"


def callback(args: argparse.Namespace, api: plug.PlatformAPI) -> None:
Expand Down Expand Up @@ -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 "",
marceloFA marked this conversation as resolved.
Show resolved Hide resolved
)
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"
)


Expand Down
20 changes: 20 additions & 0 deletions tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,23 @@ 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\nworld\n"
indented_body = feedback._indent_issue_body(body, 10)
assert feedback.TRUNC_SIGN in indented_body
marceloFA marked this conversation as resolved.
Show resolved Hide resolved

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, 20)
assert not feedback.TRUNC_SIGN in indented_body
marceloFA marked this conversation as resolved.
Show resolved Hide resolved