aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsobiemir <sobiemir@aculo.pl>2019-01-08 00:43:40 +0100
committersobiemir <sobiemir@aculo.pl>2019-01-08 00:43:40 +0100
commit3567283acad210997dafd7657411af0b9384d3ef (patch)
tree520748d42ede069f958317158cce3331aa702cc3
parent570799ede176c2a6fc63ae9711c1540349db0ad7 (diff)
downloadredmine-revision-redirect-3567283acad210997dafd7657411af0b9384d3ef.tar.gz
redmine-revision-redirect-3567283acad210997dafd7657411af0b9384d3ef.zip
Add autofill of domain name and remove ID from links
-rw-r--r--app/controllers/revision_redirects_controller.rb11
-rw-r--r--app/views/issues/_changesets.html.erb8
-rw-r--r--app/views/projects/settings/_repositories.html.erb2
-rw-r--r--app/views/revision_redirects/edit.html.erb10
-rw-r--r--init.rb3
-rw-r--r--lib/revision_issues_patch.rb1
-rw-r--r--lib/revision_repositories_patch.rb2
7 files changed, 19 insertions, 18 deletions
diff --git a/app/controllers/revision_redirects_controller.rb b/app/controllers/revision_redirects_controller.rb
index 8f07cfa..1639d2f 100644
--- a/app/controllers/revision_redirects_controller.rb
+++ b/app/controllers/revision_redirects_controller.rb
@@ -5,6 +5,7 @@ class RevisionRedirectsController < ApplicationController
end
def update
+ # check if object exists
if @redirect == nil || @redirect.new_record? then
@redirect = RevisionRedirect.new(update_params)
@redirect.repository_id = params[:id]
@@ -28,10 +29,14 @@ class RevisionRedirectsController < ApplicationController
private
def find_repository_details
+ # find repository and redirect object
@repository = Repository.find(params[:id])
@redirect = RevisionRedirect.where(repository_id: params[:id]).first
@project = @repository.project
+ # get user domain to emulate git path (by default cgit path)
+ user_domain = request.domain
+
# if redirect cannot be found, create new with default values
if not @redirect then
@redirect = RevisionRedirect.new({
@@ -39,9 +44,9 @@ class RevisionRedirectsController < ApplicationController
diff_redirect: false,
repository_redirect: false,
repository_id: params[:id],
- revision_link: "https://git.example.com/#{@project.identifier}/commit/?id=\%REV\%",
- diff_link: "https://git.example.com/#{@project.identifier}/diff/?id=\%DIFF\%",
- repository_link: "https://git.example.com/#{@project.identifier}"
+ revision_link: "https://git.#{user_domain}/#{@project.identifier}/commit/?id=\%REV\%",
+ diff_link: "https://git.#{user_domain}/#{@project.identifier}/diff/?id=\%DIFF\%",
+ repository_link: "https://git.#{user_domain}/#{@project.identifier}"
})
end
rescue ActiveRecord::RecordNotFound
diff --git a/app/views/issues/_changesets.html.erb b/app/views/issues/_changesets.html.erb
index 6f78c7b..452f8a7 100644
--- a/app/views/issues/_changesets.html.erb
+++ b/app/views/issues/_changesets.html.erb
@@ -7,9 +7,7 @@
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)
+ url = redirect.revision_link.gsub("\%REV\%", changeset.revision)
link_to("#{l(:label_revision)} #{changeset.format_identifier}", url)
end
%>
@@ -25,9 +23,7 @@
:path => "",
:rev => changeset.identifier)
else
- url = redirect.diff_link.
- gsub("\%DIFF\%", changeset.identifier).
- gsub("\%ID\%", changeset.project.identifier)
+ url = redirect.diff_link.gsub("\%DIFF\%", changeset.identifier)
link_to(l(:label_diff), url)
end
%>)
diff --git a/app/views/projects/settings/_repositories.html.erb b/app/views/projects/settings/_repositories.html.erb
index 1fe194b..3cf65b9 100644
--- a/app/views/projects/settings/_repositories.html.erb
+++ b/app/views/projects/settings/_repositories.html.erb
@@ -41,5 +41,5 @@
</table>
</div>
<% else %>
-<p class="nodata"><%= l(:label_no_data) %></p>
+ <p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
diff --git a/app/views/revision_redirects/edit.html.erb b/app/views/revision_redirects/edit.html.erb
index 03ae466..ae56a6c 100644
--- a/app/views/revision_redirects/edit.html.erb
+++ b/app/views/revision_redirects/edit.html.erb
@@ -9,9 +9,8 @@
<p>
<%= f.text_field :revision_link, :label => 'Revision link', :size => 60 %>
<em class="info">
- You can use <code>%REV%</code> and <code>%ID%</code> in your link.<br />
- <code>%REV%</code> is current revision requested to get in diffstat.<br />
- <code>%ID%</code> is project identifier given when project was creating.
+ You can use <code>%REV%</code> in your link.<br />
+ <code>%REV%</code> is current revision requested to get in diffstat.
</em>
</p>
<p>
@@ -20,9 +19,8 @@
<p>
<%= f.text_field :diff_link, :label => 'Diffstat link', :size => 60 %>
<em class="info">
- You can use <code>%DIFF%</code> and <code>%ID%</code> in your link.<br />
+ You can use <code>%DIFF%</code> in your link.<br />
<code>%DIFF%</code> is current revision requested to get in diffstat.<br />
- <code>%ID%</code> is project identifier given when project was creating.
</em>
</p>
<p>
@@ -32,10 +30,8 @@
<%= f.text_field :repository_link, :label => 'Repository link', :size => 60 %>
</p>
</div>
-
<p>
<%= submit_tag(@redirect.new_record? ? l(:button_create) : l(:button_save)) %>
<%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %>
</p>
-
<% end %>
diff --git a/init.rb b/init.rb
index f48e00e..c444232 100644
--- a/init.rb
+++ b/init.rb
@@ -2,13 +2,14 @@ Redmine::Plugin.register :redmine_revision_redirect do
name 'Redmine Revision Redirect plugin'
author 'sobiemir'
description 'This plugin redirects all revisions to external service with git repository.'
- version '0.0.1'
+ version '0.1.0'
url 'https://git.aculo.pl/redmine-revision-redirect'
author_url 'https://aculo.pl'
permission :edit_revision_redirects, :revision_redirects => [:edit, :update]
end
+# add patches to controllers
Rails.configuration.to_prepare do
RepositoriesController.send(:include, RevisionRepositoriesPatch)
IssuesController.send(:include, RevisionIssuesPatch)
diff --git a/lib/revision_issues_patch.rb b/lib/revision_issues_patch.rb
index 7a80697..5efb604 100644
--- a/lib/revision_issues_patch.rb
+++ b/lib/revision_issues_patch.rb
@@ -13,6 +13,7 @@ end
module RevisionIssuesInstanceMethods
def get_revision_redirects
+ # this gets value and store it when it's requested by user
@redirects = Hash.new do |hash, key|
hash[key] = RevisionRedirect.where(repository_id: key).first
end
diff --git a/lib/revision_repositories_patch.rb b/lib/revision_repositories_patch.rb
index 2bce717..6555685 100644
--- a/lib/revision_repositories_patch.rb
+++ b/lib/revision_repositories_patch.rb
@@ -14,11 +14,13 @@ end
module RevisionRepositoriesInstanceMethods
def destroy_revision_redirects
+ # deletes object of revision redirects table when repository is deleted
redirect = RevisionRedirect.where(repository_id: params[:id]).first
redirect.destroy if request.delete?
end
def repository_instant_redirect
+ # redirect to repository when user selected this option after clicking on repository tab
redirect = RevisionRedirect.where(repository_id: @repository.id).first
if redirect != nil && redirect.repository_redirect == true then
redirect_to redirect.repository_link