From 0f35ecd942082274d33a908fe30c935b6963ecf2 Mon Sep 17 00:00:00 2001 From: Alex Dergachev Date: Thu, 27 Nov 2014 21:07:35 +0000 Subject: [PATCH] Renamed GitFetch to GitRemove --- README.md | 16 +++++++++++++--- .../repository/{git_fetch.rb => git_remote.rb} | 14 ++++---------- config/locales/en.yml | 4 ++-- init.rb | 11 +++++------ .../repositories_helper_patch.rb | 6 +++--- 5 files changed, 27 insertions(+), 24 deletions(-) rename app/models/repository/{git_fetch.rb => git_remote.rb} (93%) diff --git a/README.md b/README.md index a43c406..3948dbf 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,18 @@ cd REDMINE_ROOT/plugins git clone https://github.com/dergachev/redmine_git_remote ``` +Then enable the new GitRemote SMC type in [http://redmine-root/settings?tab=repositories](http://redmine-root/settings?tab=repositories) + +![](https://dl.dropbox.com/u/29440342/screenshots/AYKNZDTB-2014.11.27-15-59-06.png) + Be sure to install the appropriate SSH keys to `~/.ssh/id_rsa` (for your redmine user). I recommend creating a dedicated deployment user on github/gitlab for this purpose. ## Usage -This plugin defines a new repository type, GitFetch, which allows you to associate +This plugin defines a new repository type, GitRemote, which allows you to associate a remote repository with your Redmine project. First create a new repository of type -GitFetch, enter the clone URL. The identifier and path will be auto-generated, but can be overriden. +GitRemote, enter the clone URL. The identifier and path will be auto-generated, but can be overriden. ![](https://dl.dropbox.com/u/29440342/screenshots/ATIAQXHG-2014.11.27-15-03-51.png) @@ -42,7 +46,13 @@ automatically" setting at and relying on the following cron job as per [Redmine Wiki Instructions](http://www.redmine.org/projects/redmine/wiki/RedmineRepositories): ``` -cd /home/redmine/redmine && ./script/rails runner \"Repository.fetch_changesets\" -e production >> log/cron_rake.log 2>&1 +*/5 * * * * cd /home/redmine/redmine && ./script/rails runner \"Repository.fetch_changesets\" -e production >> log/cron_rake.log 2>&1 +``` + +To trigger fetch manually, run this: + +``` +cd /home/redmine/redmine && ./script/rails runner "Repository.fetch_changesets" -e production ``` Note GitRemote doesn't delete the cloned repos when the associated record is deleted from Redmine. diff --git a/app/models/repository/git_fetch.rb b/app/models/repository/git_remote.rb similarity index 93% rename from app/models/repository/git_fetch.rb rename to app/models/repository/git_remote.rb index 652fd17..98307fd 100644 --- a/app/models/repository/git_fetch.rb +++ b/app/models/repository/git_remote.rb @@ -2,7 +2,7 @@ require 'redmine/scm/adapters/git_adapter' require 'pathname' require 'fileutils' -class Repository::GitFetch < Repository::Git +class Repository::GitRemote < Repository::Git PLUGIN_ROOT = Pathname.new(__FILE__).join("../../../..").realpath.to_s PATH_PREFIX = PLUGIN_ROOT + "/repos/" @@ -62,7 +62,7 @@ class Repository::GitFetch < Repository::Git end def clone_empty - Repository::GitFetch.add_known_host(clone_host) + Repository::GitRemote.add_known_host(clone_host) unless system "git ls-remote -h #{clone_url}" return "#{clone_url} is not a valid remote." @@ -86,7 +86,7 @@ class Repository::GitFetch < Repository::Git unloadable def self.scm_name - 'GitFetch' + 'GitRemote' end def parse(url) @@ -107,7 +107,7 @@ class Repository::GitFetch < Repository::Git def fetch puts "Fetching repo #{clone_path}" - Repository::GitFetch.add_known_host(clone_host) + Repository::GitRemote.add_known_host(clone_host) err = clone_empty Rails.logger.warn err if err @@ -118,12 +118,6 @@ class Repository::GitFetch < Repository::Git end end - def self.fetch_all - Repository::GitFetch.all.each do |x| - x.fetch - end - end - # Checks if host is in ~/.ssh/known_hosts, adds it if not present def self.add_known_host(host) # if not found... diff --git a/config/locales/en.yml b/config/locales/en.yml index a500cd9..27c8435 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,4 @@ en: field_extra_clone_url: Clone URL - text_git_fetch_repository_note: The URL to clone from. - text_git_fetch_repository_path_note: The absolute filesystem path to clone to. Leave blank to auto-populate from URL. + 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. diff --git a/init.rb b/init.rb index d8811f7..3a941df 100644 --- a/init.rb +++ b/init.rb @@ -3,17 +3,16 @@ require 'redmine' # TODO: why isn't this autoloaded? # NB: at this point, $PATH only contains {PLUGINS}/lib and app/models, app/controllers # but not {PLUGINS}/app/models. Maybe those get added later? -require File.dirname(__FILE__) + '/app/models/repository/git_fetch' +require File.dirname(__FILE__) + '/app/models/repository/git_remote' require_dependency "repository_fetch/repositories_helper_patch" -Redmine::Scm::Base.add "GitFetch" +Redmine::Scm::Base.add "GitRemote" -Redmine::Plugin.register :redmine_repository_fetch do +Redmine::Plugin.register :redmine_git_remote do name 'Repository Fetch' author 'Alex Dergachev' - url 'https://github.com/dergachev/redmine_repository_fetch' - description 'Automatically clone and fetch referenced repositories' + url 'https://github.com/dergachev/redmine_git_remote' + description 'Automatically clone and fetch remote git repositories' version '0.0.1' end - diff --git a/lib/repository_fetch/repositories_helper_patch.rb b/lib/repository_fetch/repositories_helper_patch.rb index b604874..7915c57 100644 --- a/lib/repository_fetch/repositories_helper_patch.rb +++ b/lib/repository_fetch/repositories_helper_patch.rb @@ -5,17 +5,17 @@ module RepositoryFetch end module InstanceMethods - def git_fetch_field_tags(form, repository) + def git_remote_field_tags(form, repository) #TODO: change URL label to "Path" content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => !repository.safe_attribute?('url'), :required => false) + content_tag('em', - l(:text_git_fetch_repository_path_note), + 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_fetch_repository_note), + l(:text_git_remote_url_note), :class => 'info') ) end