require_relative 'git_info'
require 'uri'

# Contains the various snippets of text generated for the mail
class EmailFormatter
  def initialize(special, target_branch_is_master)
    @special = special
    @target_branch_is_master = target_branch_is_master
  end

  attr_reader :special, :target_branch_is_master

  def to
    Settings.email_to
  end

  def subject
    "Deploy request #{special ? '[SPECIAL]' : '[no special]'} for "\
      "\"#{GitInfo.branch_name}\""
  end

  def body
    body_raw = <<BODY
# Branch
#{GitInfo.branch_name}
#{!target_branch_is_master ? "\n# Target branch\n" : ''}
#{special ? "\n# Deploy instructions\n1. \n" : ''}
# Commits
#{GitInfo.commit_log}

# Shortstat
#{GitInfo.shortstat}

# Referenced issues
#{GitInfo.issue_urls}
BODY

    return body_raw if OS.mac?

    URI.escape(body_raw)
  end
end

require_relative 'git_info'
require 'uri'

# Contains the various snippets of text generated for the mail
class EmailFormatter
  def initialize(special, target_branch_is_master)
    @special = special
    @target_branch_is_master = target_branch_is_master
  end

  attr_reader :special, :target_branch_is_master

  def to
    Settings.email_to
  end

  def subject
    "Deploy request #{special ? '[SPECIAL]' : '[no special]'} for "\
      "\"#{GitInfo.branch_name}\""
  end

  def body
    body_raw = <<BODY
# Branch
#{GitInfo.branch_name}
#{conditional_body_text}
# Commits
#{GitInfo.commit_log}

# Shortstat
#{GitInfo.shortstat}

# Referenced issues
#{GitInfo.issue_urls}
BODY

    return body_raw if OS.mac?

    URI.escape(body_raw)
  end

  def conditional_body_text
    text = ''
    text << "\n# Target branch\n\n" unless target_branch_is_master
    text << "\n# Deploy instructions\n1. \n" if special
    text
  end
end

Fix formatting of conditional email body text
Fix formatting of conditional email body text

If the user sets the target branch to master and considers the deploy
request a non-special one, then this would result in two empty lines
after the line with the name of the current branch.

If none of the two trigger, then there should only be one blank line
after the branch name.
