Skip to content

Settings #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ Some extra tips:
* On Ubuntu, the `www-data` user's $HOME is `/var/www`, and by default it's owned by root.
That means you might have to do this before installing Redmine: `sudo mkdir /var/www/.ssh; sudo chown www-data:www-data /var/www/.ssh`

## Configuration

The plugin offers two configuration options:

* Local Repository Path (git_local_path) - Path, where repositories are created on the local system. This defaults to `REDMINE_PLUGINS_PATH/redmine_git_remote/repos`.
* Remote Repository Url Prefix - Default Prefix of the Remote Repository. The Default Prefix for Remote Repositories, defaults to an empty value. If this value is set, this prefix is shown in the Clone URL field of a repository by default, but can be overwritten by the user (eg. https://github.com/).

![](doc/settings.jpg)

The above configuration can be found at `Administration -> Plugins -> Redmine Git Remote -> Config`. Furthermore for initial values, the file `redmine_git_remote/conf/settings.yml` can be used.

## Usage

This plugin defines a new repository type, GitRemote, which allows you to associate
Expand All @@ -57,7 +68,7 @@ On submitting the repository creation form, the identifier and `url`
For example, if you enter `https://github.com/dergachev/vagrant-vbox-snapshot` as the Clone URL,
it will prefill the Identifier and filesystem path fields as follows:
* Identifier: `vagrant-vbox-snapshot`
* Path: `REDMINE_PLUGINS_PATH/redmine_git_remote/repos/github.com/dergachev/vagrant-vbox-snapshot`
* Path: `REDMINE_PLUGINS_PATH/redmine_git_remote/repos/github.com/dergachev/vagrant-vbox-snapshot` (Note: The Path can be configured using the above mentioned method, but can also be entered for each repository.)

Once the remote URL is validated, the plugin creates an [empty clone](http://stackoverflow.com/questions/895819/whats-the-most-straightforward-way-to-clone-an-empty-bare-git-repository) at the specified path.

Expand All @@ -83,6 +94,7 @@ cd /home/redmine/redmine && ./script/rails runner "Repository.fetch_changesets"
Notes:

* Tested on Redmine 2.6 and ruby 2.1
* Tested on Redmine 3.3.1
* Currently alpha state, use at your own risk. Given possible security risks of shelling out,
we recommend using this plugin only if all RedMine project admins are trusted users.
* This plugin doesn't clean-up (delete) cloned repos from the file system when the record
Expand Down
11 changes: 10 additions & 1 deletion app/models/repository/git_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ def initialize_clone

p = parse(attributes["extra_info"]["extra_clone_url"])
self.identifier = p[:identifier] if identifier.empty?
self.url = PATH_PREFIX + p[:path] if url.empty?

url_prefix = PATH_PREFIX
unless Setting.plugin_redmine_git_remote["git_local_path_default"].blank?
url_prefix = Setting.plugin_redmine_git_remote["git_local_path_default"]
if !url_prefix.end_with?("/") then
url_prefix = url_prefix + "/"
end
end

self.url = url_prefix + p[:path] if url.empty?

err = ensure_possibly_empty_clone_exists
errors.add :extra_clone_url, err if err
Expand Down
16 changes: 16 additions & 0 deletions app/views/settings/_redmine_git_remote.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p>
<label for="settings_git_local_path_default">Local Repository Path</label>
<input type="text" style="padding-left:2px;" size="60"
id="settings_git_local_path_default"
value="<%= settings['git_local_path_default'] %>"
name="settings[git_local_path_default]" >
<em class="info">Path, where repositories are created locally.</em>
</p>
<p>
<label for="settings_git_remote_url_prefix_default">Remote Repository Url Prefix</label>
<input type="text" style="padding-left:2px;" size="60"
id="settings_git_remote_url_prefix_default"
value="<%= settings['git_remote_url_prefix_default'] %>"
name="settings[git_remote_url_prefix_default]">
<em class="info">Default Prefix of the Remote Repository.</em>
</p>
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git_local_path: ''
git_remote_url_prefix: ''
Binary file added doc/settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
author 'Alex Dergachev'
url 'https://github.com/dergachev/redmine_git_remote'
description 'Automatically clone and fetch remote git repositories'
version '0.0.1'
version '0.0.2'

PLUGIN_ROOT = Pathname.new(__FILE__).join("..").realpath.to_s
options = YAML::load( File.open(File.join(PLUGIN_ROOT + '/config', 'settings.yml')))

settings :default => {'git_local_path_default' => options['git_local_path'],
'git_remote_url_prefix_default' => options['git_remote_url_prefix']},
:partial => 'settings/redmine_git_remote'
end
25 changes: 16 additions & 9 deletions lib/redmine_git_remote/repositories_helper_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ def self.included(base) # :nodoc:

module InstanceMethods
def git_remote_field_tags(form, repository)
content_tag('p', form.text_field(:url,
:size => 60, :required => false,
:disabled => !repository.safe_attribute?('url'),
:label => l(:field_path_to_repository)) +
content_tag('em', l(:text_git_remote_path_note), :class => 'info') +
form.text_field(:extra_clone_url, :size => 60, :required => true,
:disabled => !repository.safe_attribute?('url')) +
content_tag('em', l(:text_git_remote_url_note), :class => 'info')
)
local_path_tag = form.text_field(:url,
:size => 60, :required => false,
:disabled => !repository.safe_attribute?('url'),
:label => l(:field_path_to_repository))
local_path_note = content_tag('em', l(:text_git_remote_path_note), :class => 'info')

remote_url_prefix = Setting.plugin_redmine_git_remote["git_remote_url_prefix_default"].presence || ''

remote_url_tag = form.text_field(:extra_clone_url, :size => 60, :required => true,
:value => remote_url_prefix,
:disabled => !repository.safe_attribute?('url'))
remote_url_note = content_tag('em', l(:text_git_remote_url_note), :class => 'info')

git_remote_tag = content_tag('p', local_path_tag + local_path_note + remote_url_tag + remote_url_note)

git_remote_tag
end
end
end
Expand Down