Make repository clone path configurable via settings.

Signed-off-by: flozzone <flozzone@gmail.com>
This commit is contained in:
flozzone 2020-05-08 18:22:21 +02:00
parent f384527b15
commit 25180d0909
4 changed files with 20 additions and 4 deletions

View File

@ -6,9 +6,6 @@ require_dependency 'redmine_git_remote/poor_mans_capture3'
class Repository::GitRemote < Repository::Git class Repository::GitRemote < Repository::Git
PLUGIN_ROOT = Pathname.new(__FILE__).join("../../../..").realpath.to_s
PATH_PREFIX = PLUGIN_ROOT + "/repos/"
before_validation :initialize_clone before_validation :initialize_clone
safe_attributes 'extra_info', :if => lambda {|repository, _user| repository.new_record?} safe_attributes 'extra_info', :if => lambda {|repository, _user| repository.new_record?}
@ -81,7 +78,11 @@ class Repository::GitRemote < Repository::Git
p = parse(attributes["extra_info"]["extra_clone_url"]) p = parse(attributes["extra_info"]["extra_clone_url"])
self.identifier = p[:identifier] if identifier.empty? self.identifier = p[:identifier] if identifier.empty?
self.url = PATH_PREFIX + p[:path] if url.empty?
base_path = Setting.plugin_redmine_git_remote['git_remote_repo_clone_path']
base_path = base_path + "/" unless base_path.end_with?("/")
self.url = base_path + p[:path] if url.empty?
err = ensure_possibly_empty_clone_exists err = ensure_possibly_empty_clone_exists
errors.add :extra_clone_url, err if err errors.add :extra_clone_url, err if err

View File

@ -0,0 +1,7 @@
<h3><%= t('config.title') %></h3>
<p>
<label><%= t('config.repo_clone_path') %></label>
<%= text_field_tag 'settings[git_remote_repo_clone_path]', @settings['git_remote_repo_clone_path'], :size => '60' %>
<%= t('config.clone_path_hint') %>
</p>

View File

@ -2,3 +2,7 @@ en:
field_extra_clone_url: Clone URL field_extra_clone_url: Clone URL
text_git_remote_url_note: The URL to clone from. text_git_remote_url_note: The URL to clone from.
text_git_remote_path_note: The absolute filesystem path to clone to. Leave blank to auto-populate from URL. text_git_remote_path_note: The absolute filesystem path to clone to. Leave blank to auto-populate from URL.
config:
title: Git Remote Settings
repo_clone_path: Repository clone path
clone_path_hint: Path where repository is cloned. Relative to plugin directory.

View File

@ -9,4 +9,8 @@ Redmine::Plugin.register :redmine_git_remote do
url 'https://github.com/dergachev/redmine_git_remote' url 'https://github.com/dergachev/redmine_git_remote'
description 'Automatically clone and fetch remote git repositories' description 'Automatically clone and fetch remote git repositories'
version '0.0.1' version '0.0.1'
settings :default => {
'git_remote_repo_clone_path' => Pathname.new(__FILE__).join("../").realpath.to_s + "/repos",
}, :partial => 'settings/git_remote_settings'
end end