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.git/commitdiff_plain/8d823de6cf55f74d223dac4d5c11abcdcf197790?hp=5ffbe263839acf003494225f41a3f3c95af797b7 Zmiany w Redmine: * rozróżnianie po projektach, a nie trackerze; * skanowanie tylko repozytorium wybranego projektu; * skanowanie zmian, a nie working directory; --- diff --git a/redmine/redmine_publications/app/controllers/publications_controller.rb b/redmine/redmine_publications/app/controllers/publications_controller.rb index ebf735b9..fd623b99 100644 --- a/redmine/redmine_publications/app/controllers/publications_controller.rb +++ b/redmine/redmine_publications/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/redmine/redmine_publications/app/views/publications/refresh.erb b/redmine/redmine_publications/app/views/publications/refresh.erb index 1968a926..311ed33e 100644 --- a/redmine/redmine_publications/app/views/publications/refresh.erb +++ b/redmine/redmine_publications/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/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb b/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb index 8ab2a7b7..255460e9 100644 --- a/redmine/redmine_publications/app/views/settings/_publications_settings.html.erb +++ b/redmine/redmine_publications/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/redmine/redmine_publications/init.rb b/redmine/redmine_publications/init.rb index 4298f606..01afeab6 100644 --- a/redmine/redmine_publications/init.rb +++ b/redmine/redmine_publications/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/redmine/redmine_publications/lib/issue_publication_hook.rb b/redmine/redmine_publications/lib/issue_publication_hook.rb index 6d2101cf..788a72f4 100644 --- a/redmine/redmine_publications/lib/issue_publication_hook.rb +++ b/redmine/redmine_publications/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/redmine/redmine_publications/lib/redmine_publications/change_patch.rb b/redmine/redmine_publications/lib/redmine_publications/change_patch.rb index 41ea9596..b8e5c4b6 100644 --- a/redmine/redmine_publications/lib/redmine_publications/change_patch.rb +++ b/redmine/redmine_publications/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