From 2c8ba66d0a0c06107a2772e4fd19a5d94b28736d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Tue, 29 Sep 2009 22:35:35 +0200 Subject: [PATCH] =?utf8?q?Zmiany=20w=20Redmine:=20*=20rozr=C3=B3=C5=BCnian?= =?utf8?q?ie=20po=20projektach,=20a=20nie=20trackerze;=20*=20skanowanie=20?= =?utf8?q?tylko=20repozytorium=20wybranego=20projektu;=20*=20skanowanie=20?= =?utf8?q?zmian,=20a=20nie=20working=20directory;?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/controllers/publications_controller.rb | 43 +++++++++---------- app/views/publications/refresh.erb | 6 +-- .../settings/_publications_settings.html.erb | 7 ++- init.rb | 2 +- lib/issue_publication_hook.rb | 2 +- lib/redmine_publications/change_patch.rb | 10 +++-- 6 files changed, 32 insertions(+), 38 deletions(-) diff --git a/app/controllers/publications_controller.rb b/app/controllers/publications_controller.rb index ebf735b..fd623b9 100644 --- a/app/controllers/publications_controller.rb +++ b/app/controllers/publications_controller.rb @@ -13,34 +13,31 @@ class PublicationsController < ApplicationController end def refresh - @match_status = [] - regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern]) Publication.delete_all() - repos = Repository.all - if repos - repos.each do |repo| - repo_status = [] - if repo.entries - repo.entries.each do |entry| - match = entry.path.match(regexp) - if match - Publication.find_or_create_by_name(:name => match[1], - :source_file => entry.path, :repository_id => repo.id) - repo_status += [{:path => entry.path, :match => match[1], :matched => true}] - else - repo_status += [{:path => entry.path, :match =>nil, :matched => false}] - end - end - @match_status += [{:repo => repo, :status => repo_status}] + + repo = Repository.find(:first, :conditions => ['project_id = ?', Setting.plugin_redmine_publications[:project]] ) + + Rails.logger.info('[INFO] Importing changes from ' << repo.url) + Rails.logger.info('[INFO] Change list: ' << repo.changes.find(:all).inspect ) + + @repo_status = [] + repo.changes.find(:all).each do |change| + Rails.logger.info('[INFO] Importing change ' << change.path) + match = change.path.match(regexp) + if match + Publication.find_or_create_by_name(:name => match[1], + :source_file => change.path, :repository_id => repo.id) + @repo_status += [{:path => change.path, :match => match[1], :matched => true}] + else + @repo_status += [{:path => change.path, :match => nil, :matched => false}] end - end + end - respond_to do |format| + respond_to do |format| format.html - format.xml { render :xml => @match_status} - format.json { render :json => @match_status } - end + format.xml { render :xml => @repo_status} + format.json { render :json => @repo_status } end end diff --git a/app/views/publications/refresh.erb b/app/views/publications/refresh.erb index 1968a92..311ed33 100644 --- a/app/views/publications/refresh.erb +++ b/app/views/publications/refresh.erb @@ -1,9 +1,6 @@ -<% @match_status.each do |repo_status| %> -

Repozytorium: <%= repo_status[:repo].url %>

- -<% repo_status[:status].each do |status| %> +<% @repo_status.each do |status| %> @@ -11,4 +8,3 @@ <% end %>
Ścieżka zasobuRozpoznanoID zasobu
<%= status[:path] %> <%= (status[:matched] && 'Tak') || 'Nie' %>
-<% end %> diff --git a/app/views/settings/_publications_settings.html.erb b/app/views/settings/_publications_settings.html.erb index 8ab2a7b..255460e 100644 --- a/app/views/settings/_publications_settings.html.erb +++ b/app/views/settings/_publications_settings.html.erb @@ -1,9 +1,8 @@ -<% @tracker = Tracker.find(@settings[:tracker] || 1) %> - +<% @project = Project.find(:first, :conditions => ["id = ?", @settings[:project]]) %>

- - <%= collection_select(:tracker, :id, Tracker.all, :id, :name, {}, {:name => "settings[tracker]"}) %> + + <%= collection_select(:project, :id, Project.all, :id, :name, {}, {:name => "settings[project]"}) %>

diff --git a/init.rb b/init.rb index 4298f60..01afeab 100644 --- a/init.rb +++ b/init.rb @@ -28,7 +28,7 @@ Redmine::Plugin.register :redmine_publications do # permission :view_issues_for_publication, :publications => :issues settings :partial => 'settings/publications_settings', - :default => { :tracker => '1', :pattern => '.*/[a-z_].xml', :editorurl => 'http://localhost/:pubid'} + :default => { :project => '0', :pattern => '[^\$].xml', :editorurl => 'http://localhost/:pubid'} menu :application_menu, :publications, { :controller => 'publications', :action => 'index' }, :caption => 'Publikacje' diff --git a/lib/issue_publication_hook.rb b/lib/issue_publication_hook.rb index 6d2101c..788a72f 100644 --- a/lib/issue_publication_hook.rb +++ b/lib/issue_publication_hook.rb @@ -21,7 +21,7 @@ class IssuesPublicationHook < Redmine::Hook::ViewListener end def is_pticket?(context) - context[:issue].tracker_id == Setting.plugin_redmine_publications[:tracker].to_i + context[:issue].project_id == Setting.plugin_redmine_publications[:project].to_i end public diff --git a/lib/redmine_publications/change_patch.rb b/lib/redmine_publications/change_patch.rb index 41ea959..b8e5c4b 100644 --- a/lib/redmine_publications/change_patch.rb +++ b/lib/redmine_publications/change_patch.rb @@ -21,12 +21,14 @@ module RedminePublications module InstanceMethods def update_publication - if self.action == 'A' + if (self.action == 'A') and (self.changeset.repository.project_id == Setting.plugin_redmine_publications[:project].to_i) regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern]) match = self.path.match(regexp) - Rails.logger.info('[INFO] Adding publication: "' << match[1]) - Publication.find_or_create_by_name(:name => match[1], - :source_file => self.path, :repository_id => self.changeset.repository.id ) + if match + Rails.logger.info('[INFO] Adding publication: "' << match[1]) + Publication.find_or_create_by_name(:name => match[1], + :source_file => self.path, :repository_id => self.changeset.repository.id ) + end end end -- 2.20.1