]> source.dussan.org Git - redmine.git/commitdiff
Export a version as changelog text (#36679).
authorGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 04:20:25 +0000 (04:20 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 04:20:25 +0000 (04:20 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: https://svn.redmine.org/redmine/trunk@22179 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/versions_controller.rb
app/helpers/versions_helper.rb
app/views/versions/show.html.erb
lib/redmine/export/text/versions_text_helper.rb [new file with mode: 0644]
test/functional/versions_controller_test.rb

index d2beef25344ea4b9c89fa93d2a58665d2aae69ff..cdec397a8ea0c83198a30c1658eb42c0af399b09 100644 (file)
@@ -27,6 +27,7 @@ class VersionsController < ApplicationController
 
   accept_api_auth :index, :show, :create, :update, :destroy
 
+  include VersionsHelper
   helper :custom_fields
   helper :projects
 
@@ -73,6 +74,9 @@ class VersionsController < ApplicationController
           to_a
       end
       format.api
+      format.text do
+        send_data(version_to_text(@version), type: 'text/plain', filename: "#{@version.name}.txt")
+      end
     end
   end
 
index d613f6d2aa52ea88c7597fc389fab1d0eb53f6f0..54f553d48da7afc28eeeee0fedfd6e77fcb5d40b 100644 (file)
@@ -18,6 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 module VersionsHelper
+  include Redmine::Export::Text::VersionsTextHelper
 
   def version_anchor(version)
     if @project == version.project
index 0527eae9cc35020269929518548d9e3cdc56a427..e1757107586a4cfd4381efa59a6849854efe0eec 100644 (file)
 <% end %>
 </div>
 
+<% other_formats_links do |f| %>
+  <%= f.link_to_with_query_parameters 'TXT' %>
+<% end %>
+
 <%= call_hook :view_versions_show_bottom, :version => @version %>
 
 <% html_title @version.name %>
diff --git a/lib/redmine/export/text/versions_text_helper.rb b/lib/redmine/export/text/versions_text_helper.rb
new file mode 100644 (file)
index 0000000..a460c4c
--- /dev/null
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2023  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+module Redmine
+  module Export
+    module Text
+      module VersionsTextHelper
+        def version_to_text(version)
+          [
+            "# #{version.name}",
+            format_date(version.effective_date),
+            version.description,
+            version.fixed_issues.visible.map do |issue|
+              "* #{issue.tracker.name} ##{issue.id}: #{issue.subject}\n"
+            end.join
+          ].compact.join("\n\n")
+        end
+      end
+    end
+  end
+end
index b997a04a4ca88da2b92e053db6c1ed3848961607..5b72f4c481371918bdf8d8d4da8495cd20877685 100644 (file)
@@ -20,6 +20,7 @@
 require_relative '../test_helper'
 
 class VersionsControllerTest < Redmine::ControllerTest
+  include Redmine::I18n
   fixtures :projects, :enabled_modules,
            :trackers, :projects_trackers,
            :versions, :issue_statuses, :issue_categories, :enumerations,
@@ -220,6 +221,18 @@ class VersionsControllerTest < Redmine::ControllerTest
     assert_select 'a.icon.icon-add', :text => 'New issue'
   end
 
+  def test_show_with_text_format
+    version = Version.find(2)
+    get :show, params: {id: version.id, format: :text}
+    assert_response :success
+    assert_equal 'text/plain', response.media_type
+
+    result = response.body.split("\n\n")
+    assert_equal "# #{version.name}", result[0]
+    assert_equal format_date(version.effective_date), result[1]
+    assert_equal version.description, result[2]
+  end
+
   def test_new
     @request.session[:user_id] = 2
     get :new, :params => {:project_id => '1'}