# frozen_string_literal: true

module Issues
  class BuildFromVulnerabilityService < Issues::BuildService
    def execute
      vulnerability = params[:vulnerability]

      params.merge!(
        title: _("Investigate vulnerability: %{title}") % { title: vulnerability.title },
        description: render_description(vulnerability),
        confidential: true
      )

      super
    end

    private

    def render_description(vulnerability)
      ApplicationController.render(
        template: 'vulnerabilities/issue_description.md.erb',
        locals: { vulnerability: vulnerability.present }
      )
    end
  end
end
