From: Łukasz Rekucki Date: Tue, 29 Sep 2009 20:35:35 +0000 (+0200) Subject: Zmiany w Redmine: X-Git-Url: https://git.mdrn.pl/redakcja_redmine.git/commitdiff_plain/2c8ba66d0a0c06107a2772e4fd19a5d94b28736d?ds=sidebyside;hp=e41ebde0b4ec4203e00e3ba906a3eadcd5edd10e Zmiany w Redmine: * rozróżnianie po projektach, a nie trackerze; * skanowanie tylko repozytorium wybranego projektu; * skanowanie zmian, a nie working directory; --- 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