aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsobiemir <sobiemir@aculo.pl>2019-01-07 23:09:21 +0100
committersobiemir <sobiemir@aculo.pl>2019-01-07 23:09:21 +0100
commit2c2ccf0f35db39e78e98b52160ae2196599d3242 (patch)
treef3eee6d0dde4bad301cbbc2f6bee39c2bfd65222
parenta62923c90a386cd46363f991e7deb63f0f90c5d9 (diff)
downloadredmine-revision-redirect-2c2ccf0f35db39e78e98b52160ae2196599d3242.tar.gz
redmine-revision-redirect-2c2ccf0f35db39e78e98b52160ae2196599d3242.zip
Add implementation of redirects in commit history for issues
-rw-r--r--app/views/issues/_changesets.html.erb41
-rw-r--r--init.rb1
-rw-r--r--lib/revision_issues_patch.rb20
-rw-r--r--lib/revision_repositories_patch.rb4
4 files changed, 64 insertions, 2 deletions
diff --git a/app/views/issues/_changesets.html.erb b/app/views/issues/_changesets.html.erb
new file mode 100644
index 0000000..6f78c7b
--- /dev/null
+++ b/app/views/issues/_changesets.html.erb
@@ -0,0 +1,41 @@
+<% changesets.each do |changeset| %>
+ <div class="changeset">
+ <p>
+ <%=
+ redirect = @redirects[changeset.repository_id]
+ if redirect == nil || redirect.revision_redirect == false then
+ link_to_revision(changeset, changeset.repository,
+ :text => "#{l(:label_revision)} #{changeset.format_identifier}")
+ else
+ url = redirect.revision_link.
+ gsub("\%REV\%", changeset.revision).
+ gsub("\%ID\%", changeset.project.identifier)
+ link_to("#{l(:label_revision)} #{changeset.format_identifier}", url)
+ end
+ %>
+
+ <% if changeset.filechanges.any? && User.current.allowed_to?(:browse_repository, changeset.project) %>
+ (<%=
+ if redirect == nil || redirect.diff_redirect == false then
+ link_to(l(:label_diff),
+ :controller => 'repositories',
+ :action => 'diff',
+ :id => changeset.project,
+ :repository_id => changeset.repository.identifier_param,
+ :path => "",
+ :rev => changeset.identifier)
+ else
+ url = redirect.diff_link.
+ gsub("\%DIFF\%", changeset.identifier).
+ gsub("\%ID\%", changeset.project.identifier)
+ link_to(l(:label_diff), url)
+ end
+ %>)
+ <% end %>
+ <br />
+ <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
+ <div class="wiki changeset-comments">
+ <%= format_changeset_comments changeset %>
+ </div>
+ </div>
+<% end %>
diff --git a/init.rb b/init.rb
index a7659cb..f48e00e 100644
--- a/init.rb
+++ b/init.rb
@@ -11,4 +11,5 @@ end
Rails.configuration.to_prepare do
RepositoriesController.send(:include, RevisionRepositoriesPatch)
+ IssuesController.send(:include, RevisionIssuesPatch)
end
diff --git a/lib/revision_issues_patch.rb b/lib/revision_issues_patch.rb
new file mode 100644
index 0000000..7a80697
--- /dev/null
+++ b/lib/revision_issues_patch.rb
@@ -0,0 +1,20 @@
+require_dependency 'issues_controller'
+
+module RevisionIssuesPatch
+ def self.included(base)
+ base.send(:include, RevisionIssuesInstanceMethods)
+
+ base.class_eval do
+ unloadable
+ before_action :get_revision_redirects, :only => [:show]
+ end
+ end
+end
+
+module RevisionIssuesInstanceMethods
+ def get_revision_redirects
+ @redirects = Hash.new do |hash, key|
+ hash[key] = RevisionRedirect.where(repository_id: key).first
+ end
+ end
+end
diff --git a/lib/revision_repositories_patch.rb b/lib/revision_repositories_patch.rb
index 7b0ee85..1edf62e 100644
--- a/lib/revision_repositories_patch.rb
+++ b/lib/revision_repositories_patch.rb
@@ -2,7 +2,7 @@ require_dependency 'repositories_controller'
module RevisionRepositoriesPatch
def self.included(base)
- base.send(:include, InstanceMethods)
+ base.send(:include, RevisionRepositoriesInstanceMethods)
base.class_eval do
unloadable
@@ -11,7 +11,7 @@ module RevisionRepositoriesPatch
end
end
-module InstanceMethods
+module RevisionRepositoriesInstanceMethods
def destroy_revision_redirects
redirect = RevisionRedirect.where(repository_id: params[:id]).first
redirect.destroy if request.delete?