20110504-IncludeReposInScheduledFetch.patch

IncludeReposInScheduledFetch Path File - Built against revision r5642 - Christina Louise Warne, 2011-05-05 03:36

Download (6.2 KB)

View differences:

app/controllers/repositories_controller.rb (working copy)
42 42
    end
43 43
    if request.post? && @repository
44 44
      @repository.attributes = params[:repository]
45
      @repository.include_in_scheduled_fetch = !params[:include_in_scheduled_fetch].nil?
45 46
      @repository.save
46 47
    end
47 48
    render(:update) do |page|
app/models/repository.rb (working copy)
211 211
    encoding.blank? ? 'UTF-8' : encoding
212 212
  end
213 213

  
214
  # Fetches new changesets for all repositories of active projects
215
  # Can be called periodically by an external script
216
  # eg. ruby script/runner "Repository.fetch_changesets"
217
  def self.fetch_changesets
214
  # Fetches new changsets for all repositories of active projects
215
  # When fetch_all is true, all repositories will be processed, but when it is false,
216
  # only those with the 'include_in_scheduled_fetch' flag set will be retrieved
217
  def self.do_fetch_changesets(fetch_all)
218 218
    Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
219 219
      if project.repository
220 220
        begin
221
          project.repository.fetch_changesets
222
        rescue Redmine::Scm::Adapters::CommandFailed => e
223
          logger.error "scm: error during fetching changesets: #{e.message}"
221
          if (project.repository.include_in_scheduled_fetch? or fetch_all)
222
            begin
223
              project.repository.fetch_changesets
224
            rescue Redmine::Scm::Adapters::CommandFailed => e
225
              logger.error "scm: error during fetch of changesets: #{e.message}"
226
            end
227
          end
224 228
        end
225 229
      end
226 230
    end
227 231
  end
228 232

  
233
  # Fetches new changesets for all repositories of active projects
234
  # Can be called periodically by an external script
235
  # eg. ruby script/runner "Repository.fetch_changesets"
236
  def self.fetch_changesets
237
    self.do_fetch_changesets(true)
238
  end
239

  
240
  # Fetches new changesets for all repositories of active projects which have the 'include_in_scheduled_fetch' flag set
241
  # Should be called periodically by an external script
242
  # eg. ruby script/runner "Repository.scheduled_fetch_changesets"
243
  def self.scheduled_fetch_changesets
244
    self.do_fetch_changesets(false)
245
  end
246

  
229 247
  # scan changeset comments to find related and fixed issues for all repositories
230 248
  def self.scan_changesets_for_issue_ids
231 249
    find(:all).each(&:scan_changesets_for_issue_ids)
app/views/projects/settings/_repository.rhtml (working copy)
6 6
<%= error_messages_for 'repository' %>
7 7

  
8 8
<div class="box tabular">
9
<p><%= label_tag('include_in_scheduled_fetch', l(:label_include_in_scheduled_fetch)) %><%= check_box_tag 'include_in_scheduled_fetch', 1, @repository && @repository.include_in_scheduled_fetch? %></p>
9 10
<p>
10 11
<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %>
11 12
<% if @repository %>
config/locales/en-GB.yml (working copy)
804 804
  label_project_copy_notifications: Send email notifications during the project copy
805 805
  label_principal_search: "Search for user or group:"
806 806
  label_user_search: "Search for user:"
807
  label_include_in_scheduled_fetch: "Include in scheduled fetch"
807 808
  
808 809
  button_login: Login
809 810
  button_submit: Submit
config/locales/en.yml (working copy)
819 819
  label_issues_visibility_all: All issues
820 820
  label_issues_visibility_public: All non private issues
821 821
  label_issues_visibility_own: Issues created by or assigned to the user
822
  label_include_in_scheduled_fetch: "Include in scheduled fetch"
822 823
  
823 824
  button_login: Login
824 825
  button_submit: Submit
db/migrate/20110504001300_add_include_repos_in_scheduled_fetch_flag.rb (revision 0)
1
class AddIncludeReposInScheduledFetchFlag < ActiveRecord::Migration
2
  def self.up
3
    add_column :repositories, :include_in_scheduled_fetch, :boolean, :default => false, :null => false
4
  end
5

  
6
  def self.down
7
    drop_column :repositories, :include_in_scheduled_fetch
8
  end
9
end
lib/tasks/scheduled_fetch_changesets.rake (revision 0)
1
# redMine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
desc 'Scheduled fetch changesets from the repositories'
19

  
20
namespace :redmine do
21
  task :scheduled_fetch_changesets => :environment do
22
    Repository.scheduled_fetch_changesets
23
  end
24
end