Project

General

Profile

Patch #31987 » changesets.rake.patch

Go MAEDA, 2021-03-28 16:56

View differences:

lib/tasks/changesets.rake
1
# Redmine - project management software
2
# Copyright (C) 2006-2021  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
namespace :redmine do
19
  namespace :changesets do
20
    desc 'Fetch changesets from the repositories'
21
    task :fetch => :environment do
22
      Repository.fetch_changesets
23
    end
24

  
25
    desc 'Sync all revisions in repositories related with all active project.'
26
    task :reload => :environment do
27
      Project.active.has_module(:repository).find_each do |project|
28
        project.repositories.find_each do |repository|
29
          detail = [
30
            "PJ-ID #{repository.project_id}",
31
            "Identifier #{repository.identifier}",
32
            "URL #{repository.url}",
33
          ].join(", ")
34
          changesets = repository.changesets
35
          puts("Sync revisions: #{changesets.count}: #{detail}")
36
          latest_changeset = changesets.first
37
          changeset = latest_changeset
38
          while changeset
39
            revisions = repository.scm.revisions(nil,
40
                                                 changeset.identifier,
41
                                                 changeset.identifier)
42
            revisions.each do |revision|
43
              changeset.committer =
44
                Changeset.to_utf8(revision.author,
45
                                  repository.repo_log_encoding)
46
              changeset.comments =
47
                Changeset.normalize_comments(revision.message,
48
                                             repository.repo_log_encoding)
49
              changeset.user =
50
                repository.find_committer_user(changeset.committer)
51
              next unless changeset.changed?
52

  
53
              changeset.issues = []
54
              changeset.scan_for_issues
55
              if changeset.save
56
                puts("Sync revision: #{changeset.identifier}, #{detail}")
57
              else
58
                puts("Failed to sync revision: " +
59
                    "#{changeset.identifier}, #{detail}: " +
60
                    changeset.errors.to_s)
61
              end
62
            end
63
            changeset = changeset.previous
64
          end
65
        end
66
      end
67
    end
68
  end
69
end
lib/tasks/redmine.rake
49 49

  
50 50
  desc 'Fetch changesets from the repositories'
51 51
  task :fetch_changesets => :environment do
52
    Repository.fetch_changesets
52
    warn 'redmine:fetch_changesets is deprecated. Use redmine:changesets:fetch instead.'
53
    Rake::Task["redmine:changesets:fetch"].invoke
53 54
  end
54 55

  
55 56
  desc 'Migrates and copies plugins assets.'
(3-3/3)