Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 53 additions & 2 deletions lib/issuer/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,13 @@ def formatted_output(site, repo)
if site_params[:body] && !site_params[:body].strip.empty?
body_field = field_map[:body] || 'body'
output << "#{body_field}:"
# Indent body content
# Indent body content with proper line wrapping
body_lines = site_params[:body].strip.split("\n")
body_lines.each do |line|
output << " #{line}"
wrapped_lines = wrap_line_with_indentation(line, 12)
wrapped_lines.each do |wrapped_line|
output << wrapped_line
end
end
output << "" # Empty line after body
end
Expand Down Expand Up @@ -385,6 +388,54 @@ def formatted_output(site, repo)

private

# Wrap a line with proper indentation, handling long lines that exceed terminal width
#
# @param line [String] The line to wrap
# @param indent_size [Integer] Number of spaces for indentation
# @return [Array<String>] Array of wrapped lines with proper indentation
#
# @example
# wrap_line_with_indentation("This is a very long line that needs wrapping", 4)
# # => [" This is a very long line that needs", " wrapping"]
def wrap_line_with_indentation(line, indent_size)
# Get terminal width, default to 80 if not available
terminal_width = ENV['COLUMNS']&.to_i || 80

# Calculate available width for content (terminal width - indentation)
available_width = terminal_width - indent_size

# If line fits within available width, just return it with indentation
if line.length <= available_width
return [' ' * indent_size + line]
end

# Split long line into chunks that fit
wrapped_lines = []
remaining_text = line

while remaining_text.length > available_width
# Find the last space before the available width limit
break_point = remaining_text.rindex(' ', available_width)

# If no space found, break at the available width (hard wrap)
break_point = available_width if break_point.nil?

# Extract the chunk and add it with proper indentation
chunk = remaining_text[0...break_point]
wrapped_lines << (' ' * indent_size + chunk)

# Remove the processed chunk from remaining text
remaining_text = remaining_text[break_point..].lstrip
end

# Add the final chunk if any text remains
if !remaining_text.empty?
wrapped_lines << (' ' * indent_size + remaining_text)
end

wrapped_lines
end

# Determine if stub logic should be applied to this issue
#
# Checks issue-level stub property first, then falls back to defaults.
Expand Down
36 changes: 36 additions & 0 deletions specs/tests/rspec/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,42 @@

expect(output).not_to include('repo:')
end

it 'properly handles long lines in body by wrapping with maintained indentation' do
long_line = 'This is a very long line that should wrap properly when displayed in the terminal to avoid the issue where wrapped lines go all the way to the left margin instead of maintaining proper indentation for readability.'
issue_data = { 'summ' => 'Test Issue', 'body' => long_line }
issue = described_class.new(issue_data)

output = issue.formatted_output(github_site, 'test/repo')

# Check that body is present
expect(output).to include('body:')

# Check that long lines are wrapped with proper indentation
body_lines = output.split("\n").select { |line| line.start_with?(' ') }
expect(body_lines.length).to be > 1 # Should have multiple wrapped lines

# All body content lines should start with the proper indentation
body_lines.each do |line|
expect(line).to start_with(' ') # 12 spaces indentation
end
end

it 'handles multi-line body content with proper indentation' do
multi_line_body = "First line of the body.\nSecond line which is also quite long and should maintain proper indentation when displayed.\nThird line."
issue_data = { 'summ' => 'Test Issue', 'body' => multi_line_body }
issue = described_class.new(issue_data)

output = issue.formatted_output(github_site, 'test/repo')

# Should have proper indentation for all lines
body_lines = output.split("\n").select { |line| line.start_with?(' ') }
expect(body_lines.length).to be >= 3 # At least 3 lines (may be more if wrapping occurs)

# Check that original line breaks are preserved
expect(output).to include(' First line of the body.')
expect(output).to include(' Third line.')
end
end

describe '.from_array' do
Expand Down