Project

General

Profile

Patch #31987 » changesets.rake.patch

Kuniharu AKAHANE, 2019-08-31 07:19

View differences:

lib/tasks/changesets.rake
1
namespace :redmine do
2
  namespace :changesets do
3
    desc 'Sync all revisions in repositories related with all active project.'
4
    task :reload => :environment do
5
      Project.active.has_module(:repository).find_each do |project|
6
        project.repositories.find_each do |repository|
7
          detail = [
8
            "PJ-ID #{repository.project_id}",
9
            "Identifier #{repository.identifier}",
10
            "URL #{repository.url}",
11
          ].join(", ")
12
          changesets = repository.changesets
13
          puts("Sync revisions: #{changesets.count}: #{detail}")
14
          latest_changeset = changesets.first
15
          changeset = latest_changeset
16
          while changeset
17
            revisions = repository.scm.revisions(nil,
18
                                                changeset.identifier,
19
                                                changeset.identifier)
20
            revisions.each do |revision|
21
              changeset.committer =
22
                Changeset.to_utf8(revision.author,
23
                                  repository.repo_log_encoding)
24
              changeset.comments =
25
                Changeset.normalize_comments(revision.message,
26
                                            repository.repo_log_encoding)
27
              changeset.user =
28
                repository.find_committer_user(changeset.committer)
29
              next unless changeset.changed?
30
              changeset.scan_for_issues
31
              if changeset.save
32
                puts("Sync revision: #{changeset.identifier}, #{detail}")
33
              else
34
                puts("Failed to sync revision: " +
35
                    "#{changeset.identifier}, #{detail}: " +
36
                    "#{changeset.errors}")
37
              end
38
            end
39
            changeset = changeset.previous
40
          end
41
        end
42
      end
43
    end
44
  end
45
end
(1-1/3)